summaryrefslogtreecommitdiff
path: root/src/diff.c
Commit message (Collapse)AuthorAgeFilesLines
* diff: use GIT_ASSERTEdward Thomson2020-11-271-8/+11
|
* tree-wide: do not compile deprecated functions with hard deprecationPatrick Steinhardt2020-06-091-0/+6
| | | | | | | | | | | | | | | | | | | | | | When compiling libgit2 with -DDEPRECATE_HARD, we add a preprocessor definition `GIT_DEPRECATE_HARD` which causes the "git2/deprecated.h" header to be empty. As a result, no function declarations are made available to callers, but the implementations are still available to link against. This has the problem that function declarations also aren't visible to the implementations, meaning that the symbol's visibility will not be set up correctly. As a result, the resulting library may not expose those deprecated symbols at all on some platforms and thus cause linking errors. Fix the issue by conditionally compiling deprecated functions, only. While it becomes impossible to link against such a library in case one uses deprecated functions, distributors of libgit2 aren't expected to pass -DDEPRECATE_HARD anyway. Instead, users of libgit2 should manually define GIT_DEPRECATE_HARD to hide deprecated functions. Using "real" hard deprecation still makes sense in the context of CI to test we don't use deprecated symbols ourselves and in case a dependant uses libgit2 in a vendored way and knows it won't ever use any of the deprecated symbols anyway.
* tree-wide: mark local functions as staticPatrick Steinhardt2020-06-091-6/+6
| | | | | | | We've accumulated quite some functions which are never used outside of their respective code unit, but which are lacking the `static` keyword. Add it to reduce their linkage scope and allow the compiler to optimize better.
* tree-wide: remove unused functionsPatrick Steinhardt2020-06-081-5/+0
| | | | | We have some functions which aren't used anywhere. Let's remove them to get rid of unneeded baggage.
* diff: make patchid computation work with all types of commits.Gregory Herrero2019-11-281-61/+21
| | | | | | | | | | Current implementation of patchid is not computing a correct patchid when given a patch where, for example, a new file is added or removed. Some more corner cases need to be handled to have same behavior as git patch-id command. Add some more tests to cover those corner cases. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
* Don't use enum for flagsSven Strickroth2019-09-261-1/+1
| | | | | | Using an `enum` causes trouble when used with C++ as bitwise operations are not possible w/o casting (e.g., `opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY;` is invalid as there is no `&=` operator for `enum`). Signed-off-by: Sven Strickroth <email@cs-ware.de>
* diff: ignore EOFNL for computing patch IDsPatrick Steinhardt2019-07-111-2/+10
| | | | | | | | The patch ID is supposed to be mostly context-insignificant and thus only includes added or deleted lines. As such, we shouldn't honor end-of-file-without-newline markers in diffs. Ignore such lines to fix how we compute the patch ID for such diffs.
* Rename opt init functions to `options_init`Edward Thomson2019-06-141-4/+21
| | | | | | | | | | | | | In libgit2 nomenclature, when we need to verb a direct object, we name a function `git_directobject_verb`. Thus, if we need to init an options structure named `git_foo_options`, then the name of the function that does that should be `git_foo_options_init`. The previous names of `git_foo_init_options` is close - it _sounds_ as if it's initializing the options of a `foo`, but in fact `git_foo_options` is its own noun that should be respected. Deprecate the old names; they'll now call directly to the new ones.
* diff: explicitly cast in flush_hunkEdward Thomson2019-01-251-1/+1
| | | | Quiet down a warning from MSVC about how we're potentially losing data.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-9/+9
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* 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.