summaryrefslogtreecommitdiff
path: root/src/diff.c
Commit message (Collapse)AuthorAgeFilesLines
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-2/+2
|
* diff: remove unused macros `DIFF_FLAG_*`Patrick Steinhardt2017-11-301-7/+0
| | | | | | | | | | In commit 9be638ecf (git_diff_generated: abstract generated diffs, 2016-04-19), the code for generated diffs was moved out of the generic "diff.c" and instead into its own module. During that conversion, it was forgotten to remove the macros `DIFF_FLAG_IS_SET`, `DIFF_FLAG_ISNT_SET` and `DIFF_FLAG_SET`, which are now only used in "diff_generated.c". Remove those macros now.
* 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 #4288 from pks-t/pks/include-fixupsEdward Thomson2017-08-151-2/+3
|\ | | | | Include fixups
| * Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | 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.
* patch_generate: move `git_diff_foreach` to diff.cPatrick Steinhardt2017-03-141-0/+35
| | | | | | Now that the `git_diff_foreach` function does not depend on internals of the `git_patch_generated` structure anymore, we can easily move it to the actual diff code.
* introduce `git_diff_from_buffer` to parse diffsEdward Thomson2016-05-261-2/+2
| | | | Parse diff files into a `git_diff` structure.
* git_diff_generated: abstract generated diffsEdward Thomson2016-05-261-1549/+30
|
* diff: include oid length in deltasEdward Thomson2016-05-261-0/+4
| | | | | | Now that `git_diff_delta` data can be produced by reading patch file data, which may have an abbreviated oid, allow consumers to know that the id is abbreviated.
* diff: simplify code for handling empty dirsPatrick Steinhardt2016-05-031-10/+6
| | | | | | | | | | | | | | | | | | | | When determining diffs between two iterators we may need to recurse into an unmatched directory for the "new" iterator when it is either a prefix to the current item of the "old" iterator or when untracked/ignored changes are requested by the user and the directory is untracked/ignored. When advancing into the directory and no files are found, we will get back `GIT_ENOTFOUND`. If so, we simply skip the directory, handling resulting unmatched old items in the next iteration. The other case of `iterator_advance_into` returning either `GIT_NOERROR` or any other error but `GIT_ENOTFOUND` will be handled by the caller, which will now either compare the first directory entry of the "new" iterator in case of `GIT_ENOERROR` or abort on other cases. Improve readability of the code to make the above logic more clear.
* iterator: cleanupsEdward Thomson2016-03-241-3/+2
| | | | Remove some unused functions, refactor some ugliness.
* diff: stop processing nitem when its removedEdward Thomson2016-03-231-1/+1
| | | | | When a directory is removed out from underneath us, stop trying to manipulate it.
* iterator: combine fs+workdir iterators more completelyEdward Thomson2016-03-231-7/+5
| | | | | | | | | | | | | Drop some of the layers of indirection between the workdir and the filesystem iterators. This makes the code a little bit easier to follow, and reduces the number of unnecessary allocations a bit as well. (Prior to this, when we filter entries, we would allocate them, filter them and then free them; now we do the filtering before allocation.) Also, rename `git_iterator_advance_over_with_status` to just `git_iterator_advance_over`. Mostly because it's a fucking long-ass function name otherwise.
* Horrible fix for #3173.Arthur Schreiber2016-02-111-4/+4
|
* diff: include commit message when formatting patchPatrick Steinhardt2015-12-011-1/+10
| | | | | | When formatting a patch as email we do not include the commit's message in the formatted patch output. Implement this and add a test that verifies behavior.
* checkout: only consider nsecs when built that wayEdward Thomson2015-11-231-46/+3
| | | | | | | | When examining the working directory and determining whether it's up-to-date, only consider the nanoseconds in the index entry when built with `GIT_USE_NSEC`. This prevents us from believing that the working directory is always dirty when the index was originally written with a git client that uinderstands nsecs (like git 2.x).
* Merge pull request #3170 from CmdrMoozy/nsec_fixCarlos Martín Nieto2015-11-121-3/+32
|\ | | | | git_index_entry__init_from_stat: set nsec fields in entry stats
| * diff: refactor complex timestamp check into its own functionAxel Rasmussen2015-10-011-5/+27
| |
| * diff/index: respect USE_NSEC for racily clean file detectionAxel Rasmussen2015-09-181-2/+5
| |
| * cmake: add USE_NSEC, and only check nanosec m/ctime if enabledAxel Rasmussen2015-09-181-0/+4
| |
* | Add diff progress callback.Jason Haslam2015-11-021-2/+13
| |
* | pool: Simplify implementationVicent Marti2015-10-281-2/+3
| |
* | diff: ignore nsecs when diffingEdward Thomson2015-10-221-1/+3
|/ | | | | | | | | Although our index contains the literal time present in the index, we do not read nanoseconds from disk, and thus we should not use them in any comparisons, lest we always think our working directory is dirty. Guard this behind a `GIT_USE_NSECS` for future improvement.
* diff: check pathspec on non-filesEdward Thomson2015-09-121-8/+17
| | | | | | | | | | | | When we're not doing pathspec matching, we let the iterator handle file matching for us. However, we can only trust the iterator to return *files* that match the pattern, because the iterator must return directories that are not strictly in the pathlist, but that are the parents of files that match the pattern, so that diff can later recurse into them. Thus, diff must examine non-files explicitly before including them in the delta list.
* diff: use new iterator pathlist handlingEdward Thomson2015-08-301-14/+14
| | | | | | | | When using literal pathspecs in diff with `GIT_DIFF_DISABLE_PATHSPEC_MATCH` turn on the faster iterator pathlist handling. Updates iterator pathspecs to include directory prefixes (eg, `foo/`) for compatibility with `GIT_DIFF_DISABLE_PATHSPEC_MATCH`.
* Move filelist into the iterator handling itself.Edward Thomson2015-08-281-12/+34
|
* iterator: use an options struct instead of argsEdward Thomson2015-08-281-19/+25
|
* Added git_diff_index_to_index()Pierre-Olivier Latour2015-06-301-0/+25
|
* Only write index if updated when passing GIT_DIFF_UPDATE_INDEXPierre-Olivier Latour2015-06-261-2/+4
| | | | | | When diffing the index with the workdir and GIT_DIFF_UPDATE_INDEX has been passed, the previous implementation was always writing the index to disk even if it wasn't modified.
* Merge pull request #3222 from git-up/conflictedEdward Thomson2015-06-231-2/+4
|\ | | | | Fixed GIT_DELTA_CONFLICTED not returned in some cases
| * Fixed GIT_DELTA_CONFLICTED not returned in some casesPierre-Olivier Latour2015-06-231-2/+4
| | | | | | | | | | | | | | | | If an index entry for a file that is not in HEAD is in conflicted state, when diffing HEAD with the index, the status field of the corresponding git_diff_delta was incorrectly reported as GIT_DELTA_ADDED instead of GIT_DELTA_CONFLICTED. This was due to handle_unmatched_new_item() initially setting the status to GIT_DELTA_CONFLICTED but then overriding it later with GIT_DELTA_ADDED.
* | diff: check files with the same or newer timestampsCarlos Martín Nieto2015-06-221-3/+4
|/ | | | | | | | | | When a file on the workdir has the same or a newer timestamp than the index, we need to perform a full check of the contents, as the update of the file may have happened just after we wrote the index. The iterator changes are such that we can reach inside the workdir iterator from the diff, though it may be better to have an accessor instead of moving these structs into the header.
* diff: preserve original mode in the indexEdward Thomson2015-06-201-10/+14
| | | | | | | When updating the index during a diff, preserve the original mode, which prevents us from dropping the mode to what we have interpreted as on our system (eg, what the working directory claims it to be, which may be a lie on some systems.)
* Introduce `GIT_DIFF_FLAG_EXISTS`Edward Thomson2015-05-281-1/+6
| | | | | | | | | | Mark the `old_file` and `new_file` sides of a delta with a new bit, `GIT_DIFF_FLAG_EXISTS`, that introduces that a particular side of the delta exists in the diff. This is useful for indicating whether a working directory item exists or not, in the presence of a conflict. Diff users may have previously used DELETED to determine this information.
* diff: prettify `maybe_modified` a littleEdward Thomson2015-05-281-12/+15
|
* introduce `git_index_entry_is_conflict`Edward Thomson2015-05-281-7/+8
| | | | | | | | | It's not always obvious the mapping between stage level and conflict-ness. More importantly, this can lead otherwise sane people to write constructs like `if (!git_index_entry_stage(entry))`, which (while technically correct) is unreadable. Provide a nice method to help avoid such messy thinking.
* diff conflicts: don't include incorrect IDEdward Thomson2015-05-281-16/+21
| | | | | | | | | Since a diff entry only concerns a single entry, zero the information for the index side of a conflict. (The index entry would otherwise erroneously include the lowest-stage index entry - generally the ancestor of a conflict.) Test that during status, the index side of the conflict is empty.
* diff: for conflicts w/o workdir, blank nitem sideEdward Thomson2015-05-281-13/+26
| | | | | Make sure that we provide a blanked nitem side when the item does not exist in the working directory.
* diff/status: introduce conflictsEdward Thomson2015-05-281-13/+64
| | | | | | | | | | | When diffing against an index, return a new `GIT_DELTA_CONFLICTED` delta type for items that are conflicted. For a single file path, only one delta will be produced (despite the fact that there are multiple entries in the index). Index iterators now have the (optional) ability to return conflicts in the index. Prior to this change, they would be omitted, and callers (like diff) would omit conflicted index entries entirely.
* diff: wrap the iterator functionsEdward Thomson2015-05-281-25/+73
| | | | | | Wrap the iterator current / advance functions so that we can extend them, but also handle GIT_ITEROVER cases in the iterator funcs instead of the callers.
* checkout: break case-changes into delete/addEdward Thomson2015-05-041-0/+13
| | | | | | | When checking out with a case-insensitive working directory, we want to change the case of items in the working directory to reflect changes that occured in the checkout target. Diff now has an option to break case-changing renames into delete/add.
* Fixed GIT_DIFF_UPDATE_INDEX not being aware of executable bit changesPierre-Olivier Latour2015-04-151-1/+1
| | | | | | | | | | | | In the prior implementation, enabling GIT_DIFF_UPDATE_INDEX would overwrite entries in the index with the ones generated from scanning the working if the OID was the same. Because this OID comparison ignores file modes, this means an file in the workdir with only an exec bit difference with the one in the index would end up being overwritten, resulting in the exec bit being loss. There might be other related bugs but the fix of comparing OIDs and file modes should address them all.
* Removed unnecessary conditionPierre-Olivier Latour2015-04-151-9/+6
| | | | The variable noid is guaranteed to be zero at this point of the code path.
* Use git_oid_cpy() instead of memcpy()Pierre-Olivier Latour2015-04-151-1/+1
|
* Avoid retaining / releasing the index more than necessary when ↵Pierre-Olivier Latour2015-03-111-2/+1
| | | | GIT_DIFF_UPDATE_INDEX is enabled
* config: borrow refcounted referencescmn/config-borrow-entryCarlos Martín Nieto2015-03-031-1/+2
| | | | | | | | | | | | | | | This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
* git_filter_opt_t -> git_filter_flag_tEdward Thomson2015-02-191-1/+1
| | | | | For consistency with the rest of the library, where an opt is an options *structure*.
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-2/+3
| | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-0/+2
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.