Commit Graph

172 Commits

Author SHA1 Message Date
Russell Belfer
a5140f4dda Fix rename detection for tree-to-tree diffs
The performance improvements I introduced for rename detection
were not able to run successfully for tree-to-tree diffs because
the blob size was not known early enough and so the file signature
always had to be calculated nonetheless.

This change separates loading blobs into memory from calculating
the signature.  I can't avoid having to load the large blobs into
memory, but by moving it forward, I'm able to avoid the signature
calculation if the blob won't come into play for renames.
2013-07-24 17:11:49 -07:00
Russell Belfer
397357a048 Add rename test that used to be really slow
Before the optimization commits, this test used to take about 20
seconds to run on my machine.  Afterwards, there is still a couple
seconds of data setup, but the actual diff and rename detection
runs in a fraction of a second.
2013-07-24 13:12:00 -07:00
nulltoken
d6cb13d743 tests: Fix memory leak 2013-07-13 14:14:43 +02:00
Russell Belfer
584f2d3013 Fix warnings on Win64 2013-07-11 11:04:42 -07:00
Russell Belfer
125655fe3f Untracked directories with .git should be ignored
This restores a behavior that was accidentally lost during some
diff refactoring where an untracked directory that contains a .git
item should be treated as IGNORED, not as UNTRACKED.  The submodule
code already detects this, but the diff code was not handling the
scenario right.

This also updates a number of existing tests that were actually
exercising the behavior but did not have the right expectations in
place.  It actually makes the new
`test_diff_submodules__diff_ignore_options` test feel much better
because the "not-a-submodule" entries are now ignored instead of
showing up as untracked items.

Fixes #1697
2013-07-10 12:15:03 -07:00
Russell Belfer
9564229af4 Add tests for diff.ignoreSubmdules config 2013-07-10 12:15:03 -07:00
Russell Belfer
f9775a37aa Add ignore_submodules to diff options
This adds correct support for an equivalent to --ignore-submodules
in diff, where an actual ignore value can be passed to diff to
override the per submodule settings in the configuration.

This required tweaking the constants for ignore values so that
zero would not be used and could represent an unset option to the
diff.  This was an opportunity to move the submodule values into
include/git2/types.h and to rename the poorly named DEFAULT values
for ignore and update constants to RESET instead.

Now the GIT_DIFF_IGNORE_SUBMODULES flag is exactly the same as
setting the ignore_submodules option to GIT_SUBMODULE_IGNORE_ALL
(which is actually a minor change from the old behavior in that
submodules will now be treated as UNMODIFIED deltas instead of
being left out totally - if you set GIT_DIFF_INCLUDE_UNMODIFIED).

This includes tests for the various new settings.
2013-07-10 12:15:03 -07:00
Russell Belfer
2e3e273e33 Update diff to new internal submodule status API
Submodules now expose an internal status API that allows diff to
get back the OID values from the submodule very easily and also
to avoiding caching issues and to override the ignore setting for
the submodule.
2013-07-10 12:14:13 -07:00
Russell Belfer
e807860fa9 Add timestamp check to submodule status
This is probably not the final form of this change, but this is
a preliminary version of checking a timestamp to see if the cached
working directory HEAD OID matches the current.  Right now, this
uses the timestamp on the index and is, like most of our timestamp
checking, subject to having only second accuracy.
2013-07-10 12:14:13 -07:00
Russell Belfer
4535f04409 More diff submodule tests for cache issues
The submodules code caches data about submodules in a way that
can cause problems.  This adds some tests that try making various
modifications to the state of a submodule to see where we can
catch out problems in the submodule caching.

Right now, I've put in an extra git_submodule_reload_all so that
the test will pass, but with that commented out, the test fails.
I'm working on fixing the broken version of the test at which
point I'll commit the fix and delete the extra reload that makes
the test pass.
2013-07-10 12:14:12 -07:00
Russell Belfer
3e7d7100e2 Fix diff test helper to show parent file/line 2013-07-10 12:14:12 -07:00
Russell Belfer
49621a34af Fix memory leak in test 2013-07-10 12:14:12 -07:00
Russell Belfer
12f8fe0054 More improvements to submodule diff tests
This controls for the diff.mnemonicprefix setting so that can't
break the tests.  Also, this expands one test to emulate an
ObjectiveGit test more closely.
2013-07-10 12:14:12 -07:00
Russell Belfer
0105b55e8f Add another submodule test of dirty wd 2013-07-10 12:14:12 -07:00
Russell Belfer
2b672d5b64 Add git_pathspec_match_diff API
This adds an additional pathspec API that will match a pathspec
against a diff object.  This is convenient if you want to handle
renames (so you need the whole diff and can't use the pathspec
constraint built into the diff API) but still want to tell if the
diff had any files that matched the pathspec.

When the pathspec is matched against a diff, instead of keeping
a list of filenames that matched, instead the API keeps the list
of git_diff_deltas that matched and they can be retrieved via a
new API git_pathspec_match_list_diff_entry.

There are a couple of other minor API extensions here that were
mostly for the sake of convenience and to reduce dependencies
on knowing the internal data structure between files inside the
library.
2013-07-10 20:50:33 +02:00
Russell Belfer
a5f9b5f8d8 Diff hunk context off by one on long lines
The diff hunk context string that is returned to xdiff need not
be NUL terminated because the xdiff code just copies the number of
bytes that you report directly into the output.  There was an off
by one in the diff driver code when the header context was longer
than the output buffer size, the output buffer length included
the NUL byte which was copied into the hunk header.

Fixes #1710
2013-07-05 16:59:38 -07:00
nulltoken
c4ac556ee7 Fix compilation warnings 2013-06-29 13:27:55 +02:00
Russell Belfer
c67ff958c4 Fix bug marking submodule diffs as unmodified
There was a bug where submodules whose HEAD had not been moved
were being marked as having an UNMODIFIED delta record instead
of being left MODIFIED.  This fixes that and fixes the tests to
notice if a submodule has been incorrectly marked as UNMODIFIED.
2013-06-27 07:38:27 -07:00
Justin Spahr-Summers
c7974b49d0 Fail on unmodified deltas when they're unexpected 2013-06-26 12:03:33 -07:00
Vicent Marti
c0e58e430b test-rename: This is not a decimal, silly 2013-06-25 00:12:19 +02:00
Russell Belfer
94ef2a353c Add test for fixed diff bug
Add test for bug fixed in 852ded9698
Sorry, I wrote that bug fix and forgot to check in a test at the
same time.  Here is one that fails on the old version of the code
and now works.
2013-06-20 15:15:10 -07:00
Russell Belfer
e4acc3ba19 Fix rename looped reference issues
This makes the diff rename tracking code more careful about the
order in which it processes renames and more thorough in updating
the mapping of correct renames when an earlier rename update
alters the index of a later matched pair.
2013-06-18 16:14:35 -07:00
Edward Thomson
3b334075c9 test illustrating tri-cyclic rename failure 2013-06-18 09:39:10 -07:00
Edward Thomson
f0f2ff9cac test failure when renames produce similar similarities 2013-06-18 09:39:10 -07:00
Russell Belfer
74ded02457 Add "as_path" parameters to blob and buffer diffs
This adds parameters to the four functions that allow for blob-to-
blob and blob-to-buffer differencing (either via callbacks or by
making a git_diff_patch object).  These parameters let you say
that filename we should pretend the blob has while doing the diff.
If you pass NULL, there should be no change from the existing
behavior, which is to skip using attributes for file type checks
and just look at content.  With the parameters, you can plug into
the new diff driver functionality and get binary or non-binary
behavior, plus function context regular expressions, etc.

This commit also fixes things so that the git_diff_delta that is
generated by these functions will actually be populated with the
data that we know about the blobs (or buffers) so you can use it
appropriately.  It also fixes a bug in generating patches from
the git_diff_patch objects created via these functions.

Lastly, there is one other behavior change that may matter.  If
there is no difference between the two blobs, these functions no
longer generate any diff callbacks / patches unless you have
passed in GIT_DIFF_INCLUDE_UNMODIFIED.  This is pretty natural,
but could potentially change the behavior of existing usage.
2013-06-17 17:03:34 -07:00
Russell Belfer
de0555a347 Fix memory leaks in diff rename tests
This fixes a couple objects I forgot to free, and also updates
the valgrind suppressions file on the Mac to cover a few more
cases that had crept in.
2013-06-17 10:03:50 -07:00
Russell Belfer
f3b5bc835a Add test of rename with no changes
A tree to index rename with no changes was getting erased by
the iteration routine (if the routine actually loaded the data
for the unmodified file).  This invokes the code path that was
previously messing up the diff and iterates twice to make sure
that the iteration process itself doesn't modify the data.
2013-06-17 10:03:50 -07:00
Russell Belfer
6ea999bb88 Make index_insert keep existing case
In a case insensitive index, if you attempt to add a file from
disk with a different case pattern, the old case pattern in the
index should be preserved.

This fixes that (and a couple of minor warnings).
2013-06-17 10:03:49 -07:00
Edward Thomson
1540b19990 some simple case-sensitive index tests 2013-06-17 10:03:49 -07:00
yorah
519072c9bf diff: fix warning 2013-06-14 20:01:36 +02:00
Vicent Martí
88c401bec8 Merge pull request #1643 from ethomson/rename_source
Keep data about source of similarity
2013-06-12 14:54:32 -07:00
Russell Belfer
f9c824c592 Add patch from blobs API
This adds two new public APIs: git_diff_patch_from_blobs and
git_diff_patch_from_blob_and_buffer, plus it refactors the code
for git_diff_blobs and git_diff_blob_to_buffer so that they code
is almost entirely shared between these APIs, and adds tests for
the new APIs.
2013-06-12 11:55:27 -07:00
Russell Belfer
54faddd299 Fix some diff driver memory leaks 2013-06-12 11:54:11 -07:00
Russell Belfer
42e6cf7860 Add diff drivers tests (and fix bugs)
This adds real tests for user-configured diff drivers and in the
process found a bunch of bugs.
2013-06-11 17:45:14 -07:00
Russell Belfer
5dc98298a1 Implement regex pattern diff driver
This implements the loading of regular expression pattern lists
for diff drivers that search for function context in that way.
This also changes the way that diff drivers update options and
interface with xdiff APIs to make them a little more flexible.
2013-06-11 11:22:22 -07:00
Edward Thomson
bda3fbb1ac failing unit test for similar renames 2013-06-10 15:16:58 -05:00
Russell Belfer
114f5a6c41 Reorganize diff and add basic diff driver
This is a significant reorganization of the diff code to break it
into a set of more clearly distinct files and to document the new
organization.  Hopefully this will make the diff code easier to
understand and to extend.

This adds a new `git_diff_driver` object that looks of diff driver
information from the attributes and the config so that things like
function content in diff headers can be provided.  The full driver
spec is not implemented in the commit - this is focused on the
reorganization of the code and putting the driver hooks in place.

This also removes a few #includes from src/repository.h that were
overbroad, but as a result required extra #includes in a variety
of places since including src/repository.h no longer results in
pulling in the whole world.
2013-06-10 10:10:39 -07:00
Russell Belfer
cee695ae6b Make iterators use GIT_ITEROVER & smart advance
1. internal iterators now return GIT_ITEROVER when you go past the
   last item in the iteration.
2. git_iterator_advance will "advance" to the first item in the
   iteration if it is called immediately after creating the
   iterator, which allows a simpler idiom for basic iteration.
3. if git_iterator_advance encounters an error reading data (e.g.
   a missing tree or an unreadable file), it returns the error
   but also attempts to advance past the invalid data to prevent
   an infinite loop.

Updated all tests and internal usage of iterators to account for
these new behaviors.
2013-05-31 12:18:43 -07:00
Russell Belfer
49f70f2c37 Fill out diff rename test coverage
This extends the rename tests to make sure that every rename
scenario in the inner loop of git_diff_find_similar is actually
exercised.  Also, fixes an incorrect assert that was in one of
the clauses that was not previously being exercised.
2013-05-23 15:48:06 -07:00
Russell Belfer
67db583dab More diff rename tests; better split swap handling
This adds a couple more tests of different rename scenarios.

Also, this fixes a problem with the case where you have two
"split" deltas and the left half of one matches the right half of
the other.  That case was already being handled, but in the wrong
order in a way that could result in bad output.  Also, if the swap
also happened to put the other two halves into the correct place
(i.e. two files exchanged places with each other), then the second
delta was left with the SPLIT flag set when it really should be
cleared.
2013-05-23 15:06:07 -07:00
Russell Belfer
a21cbb12db Significant rename detection rewrite
This flips rename detection around so instead of creating a
forward mapping from deltas to possible rename targets, instead
it creates a reverse mapping, looking at possible targets and
trying to find a source that they could have been renamed or
copied from.  This is important because each output can only
have a single source, but a given source could map to multiple
outputs (in the form of COPIED records).

Additionally, this makes a couple of tweaks to the public rename
detection APIs, mostly renaming a couple of options that control
the behavior to make more sense and to be more like core Git.

I walked through the tests looking at the exact results and
updated the expectations based on what I saw.  The new code is
different from the old because it cannot give some nonsense
results (like A was renamed to both B and C) which were part of
the outputs previously.
2013-05-22 10:37:12 -07:00
Russell Belfer
4742148d54 Add more diff rename detection tests
This adds a bunch more rename detection tests including checks
vs the working directory, the new exact match options, some more
whitespace variants, etc.

This also adds a git_futils_writebuffer helper function and uses
it in checkout.  This is mainly added because I wanted an easy
way to write out a git_buf to disk inside my test code.
2013-05-20 13:41:39 -07:00
Russell Belfer
d958e37a48 Fix issues with git_diff_find_similar
There are a number of bugs in the rename code that only were
obvious when I started testing it against large old repos with
more complex patterns.  (The code to do that testing is not ready
to merge with libgit2, but I do plan to add more thorough tests.)

This contains a significant number of changes and also tweaks the
public API slightly to make emulating core git easier.

Most notably, this separates the GIT_DIFF_FIND_AND_BREAK_REWRITES
flag into FIND_REWRITES (which adds a self-similarity score to
every modified file) and BREAK_REWRITES (which splits the modified
deltas into add/remove pairs in the diff list).  When you do a raw
output of core git, rewrites show up as M090 or such, not at A and
D output, so I wanted to be able to emulate that.

Publicly, this also changes the flags to be uint16_t since we
don't need values out of that range.

Internally, this contains significant changes from a number of
small bug fixes (like using the wrong side of the diff to decide
if the object could be found in the ODB vs the workdir) to larger
issues about which files can and should be compared and how the
various edge cases of similarity scores should be treated.

Honestly, I don't think this is the last update that will have to
be made to this code, but I think this moves us closer to correct
behavior and I tried to document the code so it would be easier
to follow..
2013-05-17 17:21:45 -07:00
Russell Belfer
79ef3be449 Fix diff crash when last item is untracked dir
When the last item in a diff was an untracked directory that only
contained ignored items, the loop to scan the contents would run
off the end of the iterator and dereference a NULL pointer.  This
includes a test that reproduces the problem and a fix.
2013-05-15 14:50:05 -07:00
nulltoken
b4d33e46c4 Fix some memory leaks 2013-05-14 21:54:26 +02:00
Russell Belfer
e9ba61f399 Fix diff output for renames and copies
If you use rename detection, the renamed and copied files would
not show any text diffs because the function that decides if
data should be loaded didn't know which sides of the diff to
load for those cases.

This adds a test that looks at the patch generated for diff
entries that are COPIED or RENAMED.
2013-05-10 09:32:42 -07:00
Russell Belfer
c2f602f8a5 Fix line numbering for patches with eofnl
When a patch contained an eofnl change (i.e. the last line either
gained or lost a newline), the oldno and newno line number values
for the lines in the last hunk of the patch were not useful.  This
makes them behave in a more expected manner.
2013-05-07 07:15:39 -07:00
Russell Belfer
fd96f98e14 More tests for files with no newline at end 2013-05-07 04:36:42 -07:00
Russell Belfer
e35e2684f6 Add GIT_DIFF_LINE_CONTEXT_EOFNL
This adds a new line origin constant for the special line that
is used when both files end without a newline.

In the course of writing the tests for this, I was having problems
with modifying a file but not having diff notice because it was
the same size and modified less than one second from the start of
the test, so I decided to start working on nanosecond timestamp
support.  This commit doesn't contain the nanosecond support, but
it contains the reorganization of maybe_modified and the hooks so
that if the nanosecond data were being read by stat() (or rather
being copied by git_index_entry__init_from_stat), then the nsec
would be taken into account.

This new stuff could probably use some more tests, although there
is some amount of it here.
2013-05-07 04:32:17 -07:00
Russell Belfer
a66c4bc846 More tests for diff untracked directories
This includes more tests for various scenarios when diff includes
an untracked directory in the workdir with contents either ignored
or not.
2013-04-30 04:25:56 -07:00