summaryrefslogtreecommitdiff
path: root/tests/diff
Commit message (Collapse)AuthorAgeFilesLines
* diff_file: properly refcount blobs when initializing file contentsPatrick Steinhardt2017-12-151-0/+39
| | | | | | | | | | | | | | When initializing a `git_diff_file_content` from a source whose data is derived from a blob, we simply assign the blob's pointer to the resulting struct without incrementing its refcount. Thus, the structure can only be used as long as the blob is kept alive by the caller. Fix the issue by using `git_blob_dup` instead of a direct assignment. This function will increment the refcount of the blob without allocating new memory, so it does exactly what we want. As `git_diff_file_content__unload` already frees the blob when `GIT_DIFF_FLAG__FREE_BLOB` is set, we don't need to add new code handling the free but only have to set that flag correctly.
* patch_parse: fix parsing patches only containing exact renamesPatrick Steinhardt2017-09-011-0/+21
| | | | | | | | Patches which contain exact renames only will not contain an actual diff body, but only a list of files that were renamed. Thus, the patch header is immediately followed by the terminating sequence "-- ". We currently do not recognize this character sequence as a possible terminating sequence. Add it and create a test to catch the failure.
* diff: implement function to calculate patch IDPatrick Steinhardt2017-06-261-0/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* diff_parse: correctly set options for parsed diffsPatrick Steinhardt2017-03-141-0/+21
| | | | | | | | | | | | The function `diff_parsed_alloc` allocates and initializes a `git_diff_parsed` structure. This structure also contains diff options. While we initialize its flags, we fail to do a real initialization of its values. This bites us when we want to actually use the generated diff as we do not se the option's version field, which is required to operate correctly. Fix the issue by executing `git_diff_init_options` on the embedded struct.
* patch_parse: fix parsing minimal trailing diff linePatrick Steinhardt2017-03-141-0/+21
| | | | | | | | | | | | | | | | | | | | In a diff, the shortest possible hunk with a modification (that is, no deletion) results from a file with only one line with a single character which is removed. Thus the following hunk @@ -1 +1 @@ -a + is the shortest valid hunk modifying a line. The function parsing the hunk body though assumes that there must always be at least 4 bytes present to make up a valid hunk, which is obviously wrong in this case. The absolute minimum number of bytes required for a modification is actually 2 bytes, that is the "+" and the following newline. Note: if there is no trailing newline, the assumption will not be offended as the diff will have a line "\ No trailing newline" at its end. This patch fixes the issue by lowering the amount of bytes required.
* patch_generate: fix `git_diff_foreach` only working with generated diffsPatrick Steinhardt2017-03-141-0/+29
| | | | | | | | | | | | | | | The current logic of `git_diff_foreach` makes the assumption that all diffs passed in are actually derived from generated diffs. With these assumptions we try to derive the actual diff by inspecting either the working directory files or blobs of a repository. This obviously cannot work for diffs parsed from a file, where we do not necessarily have a repository at hand. Since the introduced split of parsed and generated patches, there are multiple functions which help us to handle patches generically, being indifferent from where they stem from. Use these functions and remove the old logic specific to generated patches. This allows re-using the same code for invoking the callbacks on the deltas.
* Merge branch 'pr/3809'Edward Thomson2016-10-092-2/+38
|\
| * make git_diff_stats_to_buf not show 0 insertions or 0 deletionsSim Domingo2016-10-092-2/+38
| |
* | Teach `git_patch_from_diff` about parsed diffsethomson/patch_from_diffEdward Thomson2016-08-241-0/+45
| | | | | | | | | | Ensure that `git_patch_from_diff` can return the patch for parsed diffs, not just generate a patch for a generated diff.
* | patch: show copy information for identical copiesEdward Thomson2016-06-254-13/+98
| | | | | | | | | | | | | | When showing copy information because we are duplicating contents, for example, when performing a `diff --find-copies-harder -M100 -B100`, then show copy from/to lines in a patch, and do not show context. Ensure that we can also parse such patches.
* | patch::parse: test diff with exact rename and copyEdward Thomson2016-06-251-0/+5
| |
* | patch::parse: test diff with simple renameEdward Thomson2016-06-251-12/+27
| |
* | diff::parse tests: test parsing a diffEdward Thomson2016-06-253-0/+107
| | | | | | | | | | Test that we can create a diff file, then parse the results and that the two are identical in-memory.
* | introduce `git_diff_from_buffer` to parse diffsEdward Thomson2016-05-261-0/+60
| | | | | | | | Parse diff files into a `git_diff` structure.
* | git_diff_generated: abstract generated diffsEdward Thomson2016-05-262-0/+2
|/
* diff: test submodules are found with trailing `/`Edward Thomson2016-04-021-0/+47
| | | | | Test that submodules are found when the are included in a pathspec but have a trailing slash.
* iterator: give the tests a proper hierarchyEdward Thomson2016-03-241-1005/+0
| | | | | | Iterator tests were split over repo::iterator and diff::iterator, with duplication between the two. Move them to iterator::index, iterator::tree, and iterator::workdir.
* Added clar test for #3568Jeff Hostetler2016-03-231-0/+129
|
* iterators: refactored tree iteratorEdward Thomson2016-03-231-10/+3
| | | | | | | | Refactored the tree iterator to never recurse; simply process the next entry in order in `advance`. Additionally, reduce the number of allocations and sorting as much as possible to provide a ~30% speedup on case-sensitive iteration. (The gains for case-insensitive iteration are less majestic.)
* iterator: disambiguate reset and reset_rangeEdward Thomson2016-03-231-2/+2
| | | | | | Disambiguate the reset and reset_range functions. Now reset_range with a NULL path will clear the start or end; reset will leave the existing start and end unchanged.
* tree: re-use the id and filename in the odb objectCarlos Martín Nieto2016-03-201-1/+1
| | | | | Instead of copying over the data into the individual entries, point to the originals, which are already in a format we can use.
* tests: take the version from our defineCarlos Martín Nieto2016-03-031-1/+1
|
* tests: use legitimate object idsEdward Thomson2016-02-282-7/+9
| | | | | Use legitimate (existing) object IDs in tests so that we have the ability to turn on strict object validation when running tests.
* Merge pull request #3613 from ethomson/fixupsCarlos Martín Nieto2016-02-181-2/+2
|\ | | | | Remove most of the silly warnings
| * win32: introduce p_timeval that isn't stupidEdward Thomson2016-02-121-2/+2
| | | | | | | | | | Windows defines `timeval` with `long`, which we cannot sanely cope with. Instead, use a custom timeval struct.
* | Horrible fix for #3173.Arthur Schreiber2016-02-111-2/+2
|/
* diff: include commit message when formatting patchPatrick Steinhardt2015-12-011-0/+41
| | | | | | 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.
* Fix some warningsJacques Germishuys2015-11-201-0/+1
|
* Merge pull request #3498 from ethomson/windows_symlinksCarlos Martín Nieto2015-11-081-0/+61
|\ | | | | Diff: Honor `core.symlinks=false` and fake symlinks
| * diff: test "symlinks" in wd are respected on win32Edward Thomson2015-11-031-0/+61
| | | | | | | | | | | | | | | | When `core.symlinks = false`, we write the symlinks content (target) to a regular file. We should ensure that when we later see that regular file, we treat it specially - and that changing that regular file would actually change the symlink target. (For compatibility with Git for Windows).
* | Add diff progress callback.Jason Haslam2015-11-022-2/+29
|/
* tests: Fix warningsvmg/crudVicent Marti2015-10-211-1/+1
|
* Fix binary diffsGuille -bisho-2015-09-251-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git expects an empty line after the binary data: literal X ...binary data... <empty_line> The last literal block of the generated patches were not containing the required empty line. Example: diff --git a/binary_file b/binary_file index 3f1b3f9098131cfecea4a50ff8afab349ea66d22..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 6 Nc${NM%g@i}0ssZ|0lokL diff --git a/binary_file2 b/binary_file2 index 31be99be19470da4af5b28b21e27896a2f2f9ee2..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 13 Sc${NMEKbZyOexL+Qd|HZV+4u- git apply of that diff results in: error: corrupt binary patch at line 9: diff --git a/binary_file2 b/binary_file2 fatal: patch with only garbage at line 10 The proper formating is: diff --git a/binary_file b/binary_file index 3f1b3f9098131cfecea4a50ff8afab349ea66d22..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 6 Nc${NM%g@i}0ssZ|0lokL diff --git a/binary_file2 b/binary_file2 index 31be99be19470da4af5b28b21e27896a2f2f9ee2..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 13 Sc${NMEKbZyOexL+Qd|HZV+4u-
* diff::workdir: ensure ignored files are not returnedEdward Thomson2015-09-121-0/+43
| | | | | Ensure that a diff with the workdir is not erroneously returning directories.
* iterator: saner pathlist matching for idx iteratorEdward Thomson2015-08-311-24/+0
| | | | | | | | | | | | Some nicer refactoring for index iteration walks. The index iterator doesn't binary search through the pathlist space, since it lacks directory entries, and would have to binary search each index entry and all its parents (eg, when presented with an index entry of `foo/bar/file.c`, you would have to look in the pathlist for `foo/bar/file.c`, `foo/bar` and `foo`). Since the index entries and the pathlist are both nicely sorted, we walk the index entries in lockstep with the pathlist like we do for other iteration/diff/merge walks.
* diff: use new iterator pathlist handlingEdward Thomson2015-08-301-1/+25
| | | | | | | | 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`.
* diff: better document GIT_DIFF_PATHSPEC_DISABLEEdward Thomson2015-08-281-0/+210
| | | | | | Document that `GIT_DIFF_PATHSPEC_DISABLE` is not necessarily about explicit path matching, but also includes matching of directory names. Enforce this in a test.
* iterator: use an options struct instead of argsEdward Thomson2015-08-281-14/+46
|
* diff: don't error out on an invalid regexcmn/regex-nofailCarlos Martín Nieto2015-08-151-0/+26
| | | | | | When parsing user-provided regex patterns for functions, we must not fail to provide a diff just because a pattern is not well formed. Ignore it instead.
* Added git_diff_index_to_index()Pierre-Olivier Latour2015-06-301-0/+32
|
* Merge pull request #3265 from libgit2/leaksCarlos Martín Nieto2015-06-271-1/+5
|\ | | | | Plug a bunch of leaks
| * diff: fix leaks in diff printingCarlos Martín Nieto2015-06-261-1/+5
| |
* | Merge pull request #3263 from git-up/fixesCarlos Martín Nieto2015-06-262-2/+0
|\ \ | |/ |/| Fixes
| * Removed unused variablesPierre-Olivier Latour2015-06-262-2/+0
| |
* | test-diff-blob: Pass proper nibble sizesvmg/prefix-lenVicent Marti2015-06-261-14/+14
|/
* diff: test we don't update index unnecessarilyEdward Thomson2015-06-261-7/+69
| | | | | Test that workdir diffs, when presented with UPDATE_INDEX, only write the index when they actually make a change.
* Rename FALLBACK to UNSPECIFIEDcmn/rename-unspecifiedCarlos Martín Nieto2015-06-251-1/+1
| | | | | Fallback describes the mechanism, while unspecified explains what the user is thinking.
* Merge pull request #3097 from libgit2/cmn/submodule-config-stateCarlos Martín Nieto2015-06-242-9/+9
|\ | | | | Remove run-time configuration settings from submodules
| * submodule: add an ignore option to statusCarlos Martín Nieto2015-06-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This lets us specify in the status call which ignore rules we want to use (optionally falling back to whatever the submodule has in its configuration). This removes one of the reasons for having `_set_ignore()` set the value in-memory. We re-use the `IGNORE_RESET` value for this as it is no longer relevant but has a similar purpose to `IGNORE_FALLBACK`. Similarly, we remove `IGNORE_DEFAULT` which does not have use outside of initializers and move that to fall back to the configuration as well.
| * submodule: make set_ignore() affect the configurationCarlos Martín Nieto2015-06-221-8/+8
| | | | | | | | | | Instead of affecting a particular instance, make it change the configuration.