summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* sha1_position: convert do-while to whilepeff/binary-search-do-whileJeff King2017-08-091-2/+2
| | | | | | | | | | | | If we enter the sha1_position() function with "lo == hi", we have no elements. But the do-while loop means that we'll enter the loop body once anyway, picking "mi" at that same value and comparing nonsense to our desired key. This is unlikely to match in practice, but we still shouldn't be looking at the memory in the first place. This bug is inherited from git.git; it was fixed there in e01580cfe01526ec2c4eb4899f776a82ade7e0e1.
* Merge pull request #4304 from pks-t/pks/patch-buffersEdward Thomson2017-07-311-2/+2
|\ | | | | patch_generate: represent buffers as void pointers
| * patch_generate: represent buffers as void pointersPatrick Steinhardt2017-07-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | Pointers to general data should usually be used as a void pointer such that it is possible to hand in variables of a different pointer type without the need to cast. This is the same when creating patches from buffers, where the buffers may contain arbitrary data. Instead of requiring the caller to care whether his buffer is e.g. `char *` or `unsigned char *`, we should instead just accept a `void *`. This is also consistent in how we tread other types like for example `git_blob`, which also just has a void pointer as its raw contents.
* | Merge branch '4233'Edward Thomson2017-07-311-8/+37
|\ \
| * | remote: add function to create detached remotesEric Myhre2017-05-051-7/+17
| | | | | | | | | | | | | | | | | | | | | | | | Right now it is only possible to create remotes from a repository. While this is probably the most common use-case, there are commands which make sense even without a repository, e.g. the equivalence of `git ls-remote`. Add a new function `git_remote_create_detached`, which simply accepts a URL.
| * | remote: reject various actions for detached remotesPatrick Steinhardt2017-05-051-0/+17
| | | | | | | | | | | | | | | | | | | | | There are only few actions which actually make sense for a detached remote, like e.g. `git_remote_ls`, `git_remote_prune`. For all the other actions, we have to report an error when the remote has no repository attached to it. This commit does so and implements some tests.
| * | remote: improve error message if no URL is setPatrick Steinhardt2017-05-051-1/+3
| | | | | | | | | | | | | | | | | | | | | The current error message when connecting to a remote when no URL is set is missing information on whether it is missing a fetch or push URL. Furthermore, it results in undefined behavior when using a remote without name. Fix both issues.
* | | Merge pull request #4314 from pks-t/pks/timsortEdward Thomson2017-07-261-1/+0
|\ \ \ | | | | | | | | tsort: remove idempotent conditional assignment
| * | | tsort: remove idempotent conditional assignmentPatrick Steinhardt2017-07-211-1/+0
| | | | | | | | | | | | | | | | | | | | The conditional `run < minrun` can never be true directly after assigning `run = minrun`. Remove it to avoid confusion.
* | | | Merge pull request #4311 from libgit2/ethomson/win32_remediateEdward Thomson2017-07-261-5/+8
|\ \ \ \ | |/ / / |/| | | win32: provide fast-path for retrying filesystem operations
| * | | win32: provide fast-path for retrying filesystem operationsethomson/win32_remediateEdward Thomson2017-07-261-11/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using the `do_with_retries` macro for retrying filesystem operations in the posix emulation layer, allow the remediation function to return `GIT_RETRY`, meaning that the error was believed to be remediated, and the operation should be retried immediately, without a sleep. This is a slightly more general solution to the problem fixed in #4312.
| * | | fixed win32 p_unlink retry sleep issueCarson Howard2017-07-261-1/+6
| | | | | | | | | | | | Fixed an issue where the retry logic on p_unlink sleeps before it tries setting a file to write mode causing unnecessary slowdown.
* | | | Merge pull request #4250 from pks-t/pks/config-file-iterationEdward Thomson2017-07-191-131/+154
|\ \ \ \ | | | | | | | | | | Configuration file fixes with includes
| * | | | config_file: refuse modifying included variablesPatrick Steinhardt2017-07-151-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Modifying variables pulled in by an included file currently succeeds, but it doesn't actually do what one would expect, as refreshing the configuration will cause the values to reappear. As we are currently not really able to support this use case, we will instead just return an error for deleting and setting variables which were included via an include.
| * | | | config_file: move reader into `config_read` onlyPatrick Steinhardt2017-07-151-45/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, we have multiple call sites which initialize a `reader` structure. As the structure is only actually used inside of `config_read`, we can instead just move the reader inside of the `config_read` function. Instead, we can just pass in the configuration file into `config_read`, which eases code readability.
| * | | | config_file: refresh all files if includes were modifiedPatrick Steinhardt2017-07-151-36/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, we only re-parse the top-level configuration file when it has changed itself. This can cause problems when an include is changed, as we were not updating all values correctly. Instead of conditionally reparsing only refreshed files, the logic becomes much clearer and easier to follow if we always re-parse the top-level configuration file when either the file itself or one of its included configuration files has changed on disk. This commit implements this logic. Note that this might impact performance in some cases, as we need to re-read all configuration files whenever any of the included files changed. It could increase performance to just re-parse include files which have actually changed, but this would compromise maintainability of the code without much gain. The only case where we will gain anything is when we actually use includes and when only these includes are updated, which will probably be quite an unusual scenario to actually be worthwhile to optimize.
| * | | | config_file: remove unused backend field from parse dataPatrick Steinhardt2017-07-151-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | The backend passed to `config_read` is never actually used anymore, so we can remove it from the function and the `parse_data` structure.
| * | | | config_file: pass reader directly to callbacksPatrick Steinhardt2017-07-151-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the callbacks passed to `config_parse` got the reader via a pointer to a pointer. This allowed the callbacks to update the callers `reader` variable when the array holding it has been reallocated. As the array is no longer present, we can simply the code by making the reader a simple pointer.
| * | | | config_file: refactor include handlingPatrick Steinhardt2017-07-151-98/+116
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current code for configuration files uses the `reader` structure to parse configuration files and store additional metadata like the file's path and checksum. These structures are stored within an array in the backend itself, which causes multiple problems. First, it does not make sense to keep around the file's contents with the backend itself. While this data is usually free'd before being added to the backend, this brings along somewhat intricate lifecycle problems. A better solution would be to store only the file paths as well as the checksum of the currently parsed content only. The second problem is that the `reader` structures are stored inside an array. When re-parsing configuration files due to changed contents, we may cause this array to be reallocated, requiring us to update pointers hold by callers. Furthermore, we do not keep track of includes which are already associated to a reader inside of this array. This causes us to add readers multiple times to the backend, e.g. in the scenario of refreshing configurations. This commit fixes these shortcomings. We introduce a split between the parsing data and the configuration file's metadata. The `reader` will now only hold the file's contents and the parser state and the new `config_file` structure holds the file's path and checksum. Furthermore, the new structure is a recursive structure in that it will also hold references to the files it directly includes. The diskfile is changed to only store the top-level configuration file. These changes allow us further refactorings and greatly simplify understanding the code.
* | | | Merge pull request #4272 from pks-t/pks/patch-idEdward Thomson2017-07-191-0/+144
|\ \ \ \ | |/ / / |/| | | Patch ID calculation
| * | | diff: implement function to calculate patch IDPatrick Steinhardt2017-06-261-0/+144
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The upstream git project provides the ability to calculate a so-called patch ID. Quoting from git-patch-id(1): A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a patch, with whitespace and line numbers ignored." Patch IDs can be used to identify two patches which are probably the same thing, e.g. when a patch has been cherry-picked to another branch. This commit implements a new function `git_diff_patchid`, which gets a patch and derives an OID from the diff. Note the different terminology here: a patch in libgit2 are the differences in a single file and a diff can contain multiple patches for different files. The implementation matches the upstream implementation and should derive the same OID for the same diff. In fact, some code has been directly derived from the upstream implementation. The upstream implementation has two different modes to calculate patch IDs, which is the stable and unstable mode. The old way of calculating the patch IDs was unstable in a sense that a different ordering the diffs was leading to different results. This oversight was fixed in git 1.9, but as git tries hard to never break existing workflows, the old and unstable way is still default. The newer and stable way does not care for ordering of the diff hunks, and in fact it is the mode that should probably be used today. So right now, we only implement the stable way of generating the patch ID.
* | | | signature: don't leave a dangling pointer to the strings on parse failurecmn/tag-bad-signatureCarlos Martín Nieto2017-07-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the signature is invalid but we detect that after allocating the strings, we free them. We however leave that pointer dangling in the structure the caller gave us, which can lead to double-free. Set these pointers to `NULL` after freeing their memory to avoid this.
* | | | git_reset_*: pass parameters as const pointersAndrey Davydov2017-06-301-5/+5
| |_|/ |/| |
* | | Convert port with htons() in p_getaddrinfo()Ian Douglas Scott2017-06-231-1/+1
|/ / | | | | | | `sin_port` should be in network byte order.
* | merge: fix potential free of uninitialized memoryPatrick Steinhardt2017-06-211-1/+1
| | | | | | | | | | | | | | | | | | | | The function `merge_diff_mark_similarity_exact` may error our early and, when it does so, free the `ours_deletes_by_oid` and `theirs_deletes_by_oid` variables. While the first one can never be uninitialized due to the first call actually assigning to it, the second variable can be freed without being initialized. Fix the issue by initializing both variables to `NULL`.
* | Merge pull request #4202 from mitesch/linear_exact_renameEdward Thomson2017-06-211-31/+152
|\ \ | | | | | | merge: perform exact rename detection in linear time
| * | merge: perform exact rename detection in linear timeMichael Tesch2017-05-171-31/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | The current exact rename detection has order n^2 complexity. We can do better by using a map to first aggregate deletes and using that to match deletes to adds. This results in a substantial performance improvement for merges with a large quantity of adds and deletes.
* | | repository: remove trailing whitespaceAriel Davis2017-06-191-2/+2
| | |
* | | repository: do not initialize templates if dir is an empty stringAriel Davis2017-06-191-1/+7
| | |
* | | Adding git_filter_init for initializing `git_filter` struct + unit test Mohseen Mukaddam2017-06-131-1/+7
| | |
* | | Merge pull request #4263 from libgit2/ethomson/config_for_inmemory_repoEdward Thomson2017-06-121-9/+6
|\ \ \ | | | | | | | | Allow creation of a configuration object in an in-memory repository
| * | | repository: don't fail to create config option in inmemory repoEdward Thomson2017-06-121-6/+3
| | | | | | | | | | | | | | | | | | | | When in an in-memory repository - without a configuration file - do not fail to create a configuration object.
| * | | repository_item_path: return ENOTFOUND when appropriateEdward Thomson2017-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Disambiguate error values: return `GIT_ENOTFOUND` when the item cannot exist in the repository (perhaps because the repository is inmemory or otherwise not backed by a filesystem), return `-1` when there is a hard failure.
| * | | repository_item_path: error messages lowercasedEdward Thomson2017-06-121-2/+2
| | | |
* | | | Merge pull request #4261 from RogerGee/fix_wait_while_ackEdward Thomson2017-06-121-1/+2
|\ \ \ \ | | | | | | | | | | smart_protocol: fix parsing of server ACK responses
| * | | | smart_protocol: fix parsing of server ACK responsesRoger Gee2017-06-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix ACK parsing in wait_while_ack() internal function. This patch handles the case where multi_ack_detailed mode sends 'ready' ACKs. The existing functionality would bail out too early, thus causing the processing of the ensuing packfile to fail if/when 'ready' ACKs were sent.
* | | | | odb_read_prefix: reset error in backends loopethomson/read_prefixEdward Thomson2017-06-121-1/+4
| |/ / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When looking for an object by prefix, we query all the backends so that we can ensure that there is no ambiguity. We need to reset the `error` value between backends; otherwise the first backend may find an object by prefix, but subsequent backends may not. If we do not reset the `error` value then it will remain at `GIT_ENOTFOUND` and `read_prefix_1` will fail, despite having actually found an object.
* | | | Merge pull request #4088 from chescock/packfile-name-using-complete-hashEdward Thomson2017-06-111-8/+4
|\ \ \ \ | | | | | | | | | | Ensure packfiles with different contents have different names
| * | | | indexer: name pack files after trailer hashChris Hescock2017-05-191-8/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream git.git has changed the way how packfiles are named. Previously, they were using a hash of the contained object's OIDs, which has then been changed to use the hash of the complete packfile instead. See 1190a1acf (pack-objects: name pack files after trailer hash, 2013-12-05) in the git.git repository for more information on this change. This commit changes our logic to match the behavior of core git.
* | | | | Merge pull request #4260 from libgit2/ethomson/forced_checkout_2Edward Thomson2017-06-112-4/+5
|\ \ \ \ \ | |_|/ / / |/| | | | Update to forced checkout and untracked files
| * | | | git_futils_rmdir: only allow `EBUSY` when askedethomson/forced_checkout_2Edward Thomson2017-06-101-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | Only ignore `EBUSY` from `rmdir` when the `GIT_RMDIR_SKIP_NONEMPTY` bit is set.
| * | | | checkout: cope with untracked files in directory deletionEdward Thomson2017-06-101-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When deleting a directory during checkout, do not simply delete the directory, since there may be untracked files. Instead, go into the iterator and examine each file. In the original code (the code with the faulty assumption), we look to see if there's an index entry beneath the directory that we want to remove. Eg, it looks to see if we have a workdir entry foo and an index entry foo/bar.txt. If this is not the case, then the working directory must have precious files in that directory. This part is okay. The part that's not okay is if there is an index entry foo/bar.txt. It just blows away the whole damned directory. That's not cool. Instead, by simply pushing the directory itself onto the stack and iterating each entry, we will deal with the files one by one - whether they're in the index (and can be force removed) or not (and are precious). The original code was a bad optimization, assuming that we didn't need to git_iterator_advance_into if there was any index entry in the folder. That's wrong - we could have optimized this iff all folder entries are in the index. Instead, we need to simply dig into the directory and analyze its entries.
* | | | | settings: rename `GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION`Patrick Steinhardt2017-06-088-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Initially, the setting has been solely used to enable the use of `fsync()` when creating objects. Since then, the use has been extended to also cover references and index files. As the option is not yet part of any release, we can still correct this by renaming the option to something more sensible, indicating not only correlation to objects. This commit renames the option to `GIT_OPT_ENABLE_FSYNC_GITDIR`. We also move the variable from the object to repository source code.
* | | | | Merge pull request #4255 from pks-t/pks/buffer-grow-errorsEdward Thomson2017-06-085-20/+21
|\ \ \ \ \ | | | | | | | | | | | | Buffer growing cleanups
| * | | | | buffer: use `git_buf_init` with lengthPatrick Steinhardt2017-06-082-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `git_buf_init` function has an optional length parameter, which will cause the buffer to be initialized and allocated in one step. This can be used instead of static initialization with `GIT_BUF_INIT` followed by a `git_buf_grow`. This patch does so for two functions where it is applicable.
| * | | | | buffer: return errors for `git_buf_init` and `git_buf_attach`Patrick Steinhardt2017-06-082-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Both the `git_buf_init` and `git_buf_attach` functions may call `git_buf_grow` in case they were given an allocation length as parameter. As such, it is possible for these functions to fail when we run out of memory. While it won't probably be used anytime soon, it does indeed make sense to also record this fact by returning an error code from both functions. As they belong to the internal API only, this change does not break our interface.
| * | | | | buffer: consistently use `ENSURE_SIZE` to grow buffers on-demandPatrick Steinhardt2017-06-081-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `ENSURE_SIZE` macro can be used to grow a buffer if its currently allocated size does not suffice a required target size. While most of the code already uses this macro, the `git_buf_join` and `git_buf_join3` functions do not yet use it. Due to the macro first checking whether we have to grow the buffer at all, this has the benefit of saving a function call when it is not needed. While this is nice to have, it will probably not matter at all performance-wise -- instead, this only serves for consistency across the code.
| * | | | | buffer: fix `ENSURE_SIZE` macro referencing wrong variablePatrick Steinhardt2017-06-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the `ENSURE_SIZE` macro gets a reference to both the buffer that is to be resized and a new size, we were not consistently referencing the passed buffer, but instead a variable `buf`, which is not passed in. Funnily enough, we never noticed because our buffers seem to always be named `buf` whenever the macro was being used. Fix the macro by always using the passed-in buffer. While at it, add braces around all mentions of passed-in variables as should be done with macros to avoid subtle errors. Found-by: Edward Thompson
| * | | | | buffer: rely on `GITERR_OOM` set by `git_buf_try_grow`Patrick Steinhardt2017-06-082-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function `git_buf_try_grow` consistently calls `giterr_set_oom` whenever growing the buffer fails due to insufficient memory being available. So in fact, we do not have to do this ourselves when a call to any buffer-growing function has failed due to an OOM situation. But we still do so in two functions, which this patch cleans up.
* | | | | | Merge pull request #4253 from pks-t/pks/cov-fixesEdward Thomson2017-06-085-15/+31
|\ \ \ \ \ \ | | | | | | | | | | | | | | Coverity fixes