summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* proxy: rename the options freeing functioncmn/proxy-options-freeCarlos Martín Nieto2017-10-073-4/+4
|
* curl: free the user-provided proxy credentialsCarlos Martín Nieto2017-09-271-0/+1
|
* curl: free the proxy optionsCarlos Martín Nieto2017-09-271-0/+2
|
* proxy: add a free function for the options's pointersCarlos Martín Nieto2017-09-272-0/+7
| | | | | | When we duplicate a user-provided options struct, we're stuck with freeing the url in it. In case we add stuff to the proxy struct, let's add a function in which to put the logic.
* diff: cleanup hash ctx in `git_diff_patchid`Patrick Steinhardt2017-09-151-0/+1
| | | | | | | | | | After initializing the hash context in `git_diff_patchid`, we never proceed to call `git_hash_ctx_cleanup` on it. While this doesn't really matter on most hash implementations, this causes a memory leak on Win32 due to CNG system requiring a `malloc` call. Fix the memory leak by always calling `git_hash_ctx_cleanup` before exiting.
* Merge pull request #4344 from slavikus/fix-dirty-buffer-in-git-push-update-tipsEdward Thomson2017-09-121-0/+3
|\ | | | | Clear the remote_ref_name buffer in git_push_update_tips()
| * Clear the remote_ref_name buffer in git_push_update_tips()Slava Karpenko2017-09-111-0/+3
| | | | | | | | | | | | If fetch_spec was a non-pattern, and it is not the first iteration of push_status vector, then git_refspec_transform would result in the new value appended via git_buf_puts to the previous iteration value. Forcibly clearing the buffer on each iteration to prevent this behavior.
* | features.h: allow building without CMake-generated feature headerPatrick Steinhardt2017-09-122-2/+8
|/ | | | | | | | | | | | | | | | | | | | | In commit a390a8464 (cmake: move defines into "features.h" header, 2017-07-01), we have introduced a new "features.h" header. This file is being generated by the CMake build system based on how the libgit2 build has been configured, replacing the preexisting method of simply setting the defines inside of the CMake build system. This was done to help splitting up the build instructions into multiple separate subdirectories. An overlooked shortcoming of this approach is that some projects making use of libgit2 build the library with custom build systems, without making use of CMake. For those users, the introduction of the "features.h" file makes their life harder as they would have to also generate this file. Fix this issue by guarding all inclusions of the generated header file by the `LIBGIT2_NO_FEATURES_H` define. Like this, other build systems can skip the feature header and simply define all used features by specifying `-D` flags for the compiler again.
* Merge pull request #4296 from pks-t/pks/pattern-based-gitignoreEdward Thomson2017-08-251-36/+50
|\ | | | | Fix negative ignore rules with patterns
| * ignore: honor case insensitivity for negative ignoresPatrick Steinhardt2017-08-251-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When computing negative ignores, we throw away any rule which does not undo a previous rule to optimize. But on case insensitive file systems, we need to keep in mind that a negative ignore can also undo a previous rule with different case, which we did not yet honor while determining whether a rule undoes a previous one. So in the following example, we fail to unignore the "/Case" directory: /case !/Case Make both paths checking whether a plain- or wildcard-based rule undo a previous rule aware of case-insensitivity. This fixes the described issue.
| * ignore: keep negative rules containing wildcardsPatrick Steinhardt2017-08-251-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ignore rules allow for reverting a previously ignored rule by prefixing it with an exclamation mark. As such, a negative rule can only override previously ignored files. While computing all ignore patterns, we try to use this fact to optimize away some negative rules which do not override any previous patterns, as they won't change the outcome anyway. In some cases, though, this optimization causes us to get the actual ignores wrong for some files. This may happen whenever the pattern contains a wildcard, as we are unable to reason about whether a pattern overrides a previous pattern in a sane way. This happens for example in the case where a gitignore file contains "*.c" and "!src/*.c", where we wouldn't un-ignore files inside of the "src/" subdirectory. In this case, the first solution coming to mind may be to just strip the "src/" prefix and simply compare the basenames. While that would work here, it would stop working as soon as the basename pattern itself is different, like for example with "*x.c" and "!src/*.c. As such, we settle for the easier fix of just not optimizing away rules that contain a wildcard.
| * ignore: return early to avoid useless indentationPatrick Steinhardt2017-08-251-26/+24
| |
| * ignore: fix indentation of comment blockPatrick Steinhardt2017-08-251-6/+6
| |
* | submodule: refuse lookup in bare repositoriesPatrick Steinhardt2017-08-251-0/+10
|/ | | | | | | | | | | | | | While it is technically possible to look up submodules inside of a bare repository by reading the submodule configuration of a specific commit, we do not offer this functionality right now. As such, calling both `git_submodule_lookup` and `git_submodule_foreach` should error out early when these functions encounter a bare repository. While `git_submodule_lookup` already does return an error due to not being able to parse the configuration, `git_submodule_foreach` simply returns success and never invokes the callback function. Fix the issue by having both functions check whether the repository is bare and returning an error in that case.
* cmake: fix output location of import libraries and DLLsPatrick Steinhardt2017-08-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | | As observed by Edward Thomson, the libgit2 DLL built by Windows will not end up in the top-level build directory but instead inside of the 'src/' subdirectory. While confusing at first because we are actually setting the LIBRARY_OUTPUT_DIRECTORY to the project's binary directory, the manual page of LIBRARY_OUTPUT_DIRECTORY clears this up: There are three kinds of target files that may be built: archive, library, and runtime. Executables are always treated as runtime targets. Static libraries are always treated as archive targets. Module libraries are always treated as library targets. For non-DLL platforms shared libraries are treated as library targets. For DLL platforms the DLL part of a shared library is treated as a runtime target and the corresponding import library is treated as an archive target. All Windows-based systems including Cygwin are DLL platforms. So in fact, DLLs and import libraries are not treated as libraries at all by CMake but instead as runtime and archive targets. To fix the issue, we can thus simply set the variables RUNTIME_OUTPUT_DIRECTORY and ARCHIVE_OUTPUT_DIRECTORY to the project's root binary directory.
* cmake: always include our own headers firstPatrick Steinhardt2017-08-161-3/+4
| | | | | | | | | | | | With c26ce7840 (Merge branch 'AndreyG/cmake/modernization', 2017-06-28), we have recently introduced a regression in the way we are searching for headers. We have made sure to always include our own headers first, but due to the changes in c26ce7840 this is no longer guaranteed. In fact, this already leads the compiler into picking "config.h" from the "deps/regex" dependency, if it is used. Fix the issue by declaring our internal include directories up front, before any of the other search directories is added.
* cmake: move library build instructions into subdirectoryPatrick Steinhardt2017-08-161-0/+397
| | | | | | | | | | To fix leaking build instructions into different targets and to make the build instructions easier to handle, create a new CMakeLists.txt file containing build instructions for the libgit2 target. By now, the split is rather easy to achieve. Due to the preparatory steps, we can now simply move over all related build instructions, only needing to remove the "src/" prefix from some files.
* cmake: move regcomp and futimens checks to "features.h"Patrick Steinhardt2017-08-162-2/+4
| | | | | | | | | | | | | In our CMakeLists.txt, we have to check multiple functions in order to determine if we have to use our own or whether we can use the platform-provided one. For two of these functions, namely `regcomp_l()` and `futimens`, the defined macro is actually used inside of the header file "src/unix/posix.h". As such, these macros are not only required by the library, but also by our test suite, which is makes use of internal headers. To prepare for the CMakeLists.txt split, move these two defines inside of the "features.h" header.
* cmake: move defines into "features.h" headerPatrick Steinhardt2017-08-163-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a future commit, we will split out the build instructions for our library directory and move them into a subdirectory. One of the benefits is fixing scoping issues, where e.g. defines do not leak to build targets where they do not belong to. But unfortunately, this does also pose the problem of how to propagate some defines which are required by both the library and the test suite. One way would be to create another variable keeping track of all added defines and declare it inside of the parent scope. While this is the most obvious and simplest way of going ahead, it is kind of unfortunate. The main reason to not use this is that these defines become implicit dependencies between the build targets. By simply observing a define inside of the CMakeLists.txt file, one cannot reason whether this define is only required by the current target or whether it is required by different targets, as well. Another approach would be to use an internal header file keeping track of all defines shared between targets. While configuring the library, we will set various variables and let CMake configure the file, adding or removing defines based on what has been configured. Like this, one can easily keep track of the current environment by simply inspecting the header file. Furthermore, these dependencies are becoming clear inside the CMakeLists.txt, as instead of simply adding a define, we now call e.g. `SET(GIT_THREADSAFE 1)`. Having this header file though requires us to make sure it is always included before any "#ifdef"-preprocessor checks are executed. As we have already refactored code to always include the "common.h" header file before any statement inside of a file, this becomes easy: just make sure "common.h" includes the new "features.h" header file first.
* Merge pull request #4288 from pks-t/pks/include-fixupsEdward Thomson2017-08-15237-253/+612
|\ | | | | Include fixups
| * Make sure to always include "common.h" firstPatrick Steinhardt2017-07-03235-143/+437
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
| * Add missing license headersPatrick Steinhardt2017-07-037-0/+49
| | | | | | | | | | Some implementation files were missing the license headers. This commit adds them.
| * Fix missing include for header filesPatrick Steinhardt2017-07-039-3/+19
| | | | | | | | | | | | | | | | | | | | | | | | Some of our header files are not included at all by any of their implementing counter-parts. Including them inside of these files leads to some compile errors mostly due to unknown types because of missing includes. But there's also one case where a declared function does not match the implementation's prototype. Fix all these errors by fixing up the prototype and adding missing includes. This is preparatory work for fixing up missing includes in the implementation files.
| * win32: fix circular include deps with w32_crtdbgPatrick Steinhardt2017-06-303-107/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The current order of declarations and includes between "common.h" and "w32_crtdbg_stacktrace.h" is rather complicated. Both header files make use of things defined in the other one and are thus circularly dependent on each other. This makes it currently impossible to compile the "w32_crtdbg_stacktrace.c" file when including "common.h" inside of "w32_crtdbg_stacktrace.h". We can disentangle the mess by moving declaration of the inline crtdbg functions into the "w32_crtdbg_stacktrace.h" file and adding additional includes inside of it, such that all required functions are available to it. This allows us to break the dependency cycle.
* | Merge pull request #4328 from libgit2/peff/hashcmp-is-memcmpEdward Thomson2017-08-141-8/+1
|\ \ | | | | | | oid: use memcmp in git_oid__hashcmp
| * | oid: use memcmp in git_oid__hashcmppeff/hashcmp-is-memcmpJeff King2017-08-091-8/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The open-coded version was inherited from git.git. But it turns out it was based on an older version of glibc, whose memcmp was not very optimized. Modern glibc does much better, and some compilers (like gcc 7) can even inline the memcmp into a series of multi-byte xors. Upstream is switching to using memcmp in git/git@0b006014c87f400bd9a86267ed30fd3e7b383884.
* | | Merge pull request #4327 from libgit2/peff/drop-sha1-entry-posEdward Thomson2017-08-143-224/+0
|\ \ \ | | | | | | | | sha1_lookup: drop sha1_entry_pos function
| * | | sha1_lookup: drop sha1_entry_pos functionpeff/drop-sha1-entry-posJeff King2017-08-093-224/+0
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was pulled over from git.git, and is an experiment in making binary-searching lists of sha1s faster. It was never compiled by default (nor was it used upstream by default without a special environment variable). Unfortunately, it is actually slower in practice, and upstream is planning to drop it in git/git@f1068efefe6dd3beaa89484db5e2db730b094e0b (which has some timing results). It's worth doing the same here for simplicity.
* | | 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.