Commit Graph

128 Commits

Author SHA1 Message Date
Patrick Steinhardt
c0eba379d1 diff_parse: correctly set options for parsed diffs
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.
2017-03-14 13:09:35 +01:00
Patrick Steinhardt
ad5a909cfb patch_parse: fix parsing minimal trailing diff line
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.
2017-03-14 13:09:13 +01:00
Patrick Steinhardt
ace3508f4c patch_generate: fix git_diff_foreach only working with generated diffs
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.
2017-03-14 13:08:28 +01:00
Edward Thomson
610cff13a3 Merge branch 'pr/3809' 2016-10-09 16:05:48 +01:00
Sim Domingo
dc5cfdbab9 make git_diff_stats_to_buf not show 0 insertions or 0 deletions 2016-10-09 16:03:00 +01:00
Edward Thomson
b859faa61c Teach git_patch_from_diff about parsed diffs
Ensure that `git_patch_from_diff` can return the patch for parsed diffs,
not just generate a patch for a generated diff.
2016-08-24 09:08:57 -05:00
Edward Thomson
1a79cd959b patch: show copy information for identical copies
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.
2016-06-25 23:08:30 -04:00
Edward Thomson
9eb1938134 patch::parse: test diff with exact rename and copy 2016-06-25 23:08:30 -04:00
Edward Thomson
8a670dc4c0 patch::parse: test diff with simple rename 2016-06-25 23:08:28 -04:00
Edward Thomson
e774d5af76 diff::parse tests: test parsing a diff
Test that we can create a diff file, then parse the results and
that the two are identical in-memory.
2016-06-25 23:08:04 -04:00
Edward Thomson
7166bb1665 introduce git_diff_from_buffer to parse diffs
Parse diff files into a `git_diff` structure.
2016-05-26 13:01:09 -05:00
Edward Thomson
9be638ecf0 git_diff_generated: abstract generated diffs 2016-05-26 13:01:08 -05:00
Edward Thomson
2e0391f4f1 diff: test submodules are found with trailing /
Test that submodules are found when the are included in a pathspec
but have a trailing slash.
2016-04-02 13:02:41 -07:00
Edward Thomson
de034cd239 iterator: give the tests a proper hierarchy
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.
2016-03-24 15:59:48 -04:00
Jeff Hostetler
df25daef9b Added clar test for #3568 2016-03-23 17:17:02 -04:00
Edward Thomson
be30387e8b iterators: refactored tree iterator
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.)
2016-03-23 17:08:37 -04:00
Edward Thomson
684b35c41b iterator: disambiguate reset and reset_range
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.
2016-03-23 17:08:37 -04:00
Carlos Martín Nieto
60a194aa86 tree: re-use the id and filename in the odb object
Instead of copying over the data into the individual entries, point to
the originals, which are already in a format we can use.
2016-03-20 11:00:12 +01:00
Carlos Martín Nieto
e23efa6ddf tests: take the version from our define 2016-03-03 21:03:10 +01:00
Edward Thomson
4afe536ba1 tests: use legitimate object ids
Use legitimate (existing) object IDs in tests so that we have the
ability to turn on strict object validation when running tests.
2016-02-28 18:54:56 -05:00
Carlos Martín Nieto
5663d4f691 Merge pull request #3613 from ethomson/fixups
Remove most of the silly warnings
2016-02-18 12:31:56 +01:00
Edward Thomson
35439f5997 win32: introduce p_timeval that isn't stupid
Windows defines `timeval` with `long`, which we cannot
sanely cope with.  Instead, use a custom timeval struct.
2016-02-12 10:34:15 -08:00
Arthur Schreiber
3679ebaef5 Horrible fix for #3173. 2016-02-11 23:41:34 +01:00
Patrick Steinhardt
254e0a33ee diff: include commit message when formatting patch
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.
2015-12-01 10:12:53 +01:00
Jacques Germishuys
87428c556f Fix some warnings 2015-11-20 20:48:51 +02:00
Carlos Martín Nieto
1c34b717e0 Merge pull request #3498 from ethomson/windows_symlinks
Diff: Honor `core.symlinks=false` and fake symlinks
2015-11-08 05:10:18 +01:00
Edward Thomson
f20480ab0c diff: test "symlinks" in wd are respected on win32
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).
2015-11-03 12:06:43 -05:00
Jason Haslam
3138ad9366 Add diff progress callback. 2015-11-02 16:33:58 -05:00
Vicent Marti
bbe1957b8c tests: Fix warnings 2015-10-21 12:09:29 +02:00
Guille -bisho-
e4b2b919bb Fix binary diffs
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-
2015-09-25 10:37:41 -07:00
Edward Thomson
92f7d32b59 diff::workdir: ensure ignored files are not returned
Ensure that a diff with the workdir is not erroneously returning
directories.
2015-09-12 13:46:22 -04:00
Edward Thomson
d53c888069 iterator: saner pathlist matching for idx iterator
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.
2015-08-31 11:48:06 -04:00
Edward Thomson
4a0dbeb0d3 diff: use new iterator pathlist handling
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`.
2015-08-30 17:06:26 -04:00
Edward Thomson
3273ab3f0b diff: better document GIT_DIFF_PATHSPEC_DISABLE
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.
2015-08-28 20:45:08 -04:00
Edward Thomson
ed1c64464a iterator: use an options struct instead of args 2015-08-28 18:39:47 -04:00
Carlos Martín Nieto
e451cd5c03 diff: don't error out on an invalid regex
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.
2015-08-15 18:46:38 +02:00
Pierre-Olivier Latour
ccef5adb63 Added git_diff_index_to_index() 2015-06-30 10:03:32 -07:00
Carlos Martín Nieto
fa399750c6 Merge pull request #3265 from libgit2/leaks
Plug a bunch of leaks
2015-06-27 21:26:27 +02:00
Carlos Martín Nieto
9568660f62 diff: fix leaks in diff printing 2015-06-26 18:31:39 +02:00
Carlos Martín Nieto
cfafeb843d Merge pull request #3263 from git-up/fixes
Fixes
2015-06-26 18:11:05 +02:00
Pierre-Olivier Latour
492851c9a2 Removed unused variables 2015-06-26 08:18:06 -07:00
Vicent Marti
13e5e344a6 test-diff-blob: Pass proper nibble sizes 2015-06-26 16:52:26 +02:00
Edward Thomson
619423f238 diff: test we don't update index unnecessarily
Test that workdir diffs, when presented with UPDATE_INDEX, only
write the index when they actually make a change.
2015-06-26 02:00:20 -04:00
Carlos Martín Nieto
c2418f4613 Rename FALLBACK to UNSPECIFIED
Fallback describes the mechanism, while unspecified explains what the
user is thinking.
2015-06-25 12:48:44 +02:00
Carlos Martín Nieto
daacf96d10 Merge pull request #3097 from libgit2/cmn/submodule-config-state
Remove run-time configuration settings from submodules
2015-06-24 23:34:40 +02:00
Edward Thomson
ba8fb7c46a diff::binary tests: empty diff when forced binary
Ensure that even when we're forcing a binary diff that we do not
assume that there *is* a diff.  There should be an empty diff for
no change.
2015-06-24 11:39:59 -04:00
Carlos Martín Nieto
76633215d1 binary diff: test that the diff and patch otputs are the same
We test the generation of the textual patch via the patch function,
which are just one of two possibilities to get the output.

Add a second patch generation via the diff function to make sure both
outputs are in sync.
2015-06-24 14:33:02 +02:00
Edward Thomson
cc605e73ac Merge pull request #3222 from git-up/conflicted
Fixed GIT_DELTA_CONFLICTED not returned in some cases
2015-06-23 23:52:03 -04:00
Edward Thomson
bd670abd23 Merge pull request #3226 from libgit2/cmn/racy-diff-again
racy-git, the missing link
2015-06-23 23:30:58 -04:00
Pierre-Olivier Latour
8d8a2eefef Fixed GIT_DELTA_CONFLICTED not returned in some cases
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.
2015-06-23 07:48:26 -07:00