Commit Graph

119 Commits

Author SHA1 Message Date
yorah
0d32f39eb8 Notify '*' pathspec correctly when diffing
I also moved all tests related to notifying in their own file.
2013-04-11 09:59:26 +02:00
Russell Belfer
ad26434b3b Tests and more fixes for submodule diffs
This adds tests for diffs with submodules in them and (perhaps
unsurprisingly) requires further fixes to be made.  Specifically,
this fixes:

- when considering if a submodule is dirty in the workdir, it was
  being treated as dirty even if only the index was dirty.
- git_diff_patch_to_str (and git_diff_patch_print) were "printing"
  the headers for files (and submodules) that were unmodified or
  had no meaningful content.
- added comment to previous fix and removed unneeded parens.
2013-04-09 14:52:32 -07:00
Russell Belfer
ccfa68055c Fix some diff ignores and submodule dirty workdir
This started out trying to look at the problems from issue #1425
and gradually grew to a broader set of fixes.  There are two core
things fixed here:

1. When you had an ignore like "/bin" which is rooted at the top
   of your tree, instead of immediately adding the "bin/" entry
   as an ignored item in the diff, we were returning all of the
   direct descendants of the directory as ignored items.  This
   changes things to immediately ignore the directory.  Note that
   this effects the behavior in test_status_ignore__subdirectories
   so that we no longer exactly match core gits ignore behavior,
   but the new behavior probably makes more sense (i.e. we now
   will include an ignored directory inside an untracked directory
   that we previously would have left off).
2. When a submodule only contained working directory changes, the
   diff code was always considering it unmodified which was just
   an outright bug. The HEAD SHA of the submodule matches the SHA
   in the parent repo index, and since the SHAs matches, the diff
   code was overwriting the actual status with UNMODIFIED.

These fixes broke existing tests test_diff_workdir__submodules and
test_status_ignore__subdirectories but looking it over, I actually
think the new results are correct and the old results were wrong.
@nulltoken had actually commented on the subdirectory ignore issue
previously.

I also included in the tests some debugging versions of the
shared iteration callback routines that print status or diff
information.  These aren't used actively in the tests, but can be
quickly swapped in to test code to give a better picture of what
is being scanned in some of the complex test scenarios.
2013-03-25 23:58:40 -07:00
Russell Belfer
1098cfaeca Test fixes and cleanup
This fixes some places where the new tests were leaving the test
area in a bad state or were freeing data they should not free.
It also removes code that is extraneous to the core issue and
fixes an invalid SHA being looked up in one of the tests (which
was failing, but for the wrong reason).
2013-03-25 14:03:16 -07:00
Sven Strickroth
b8acb775e2 Added some tests for issue #1397
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-03-25 14:03:16 -07:00
Russell Belfer
1323c6d180 Add cl_repo_set_bool and cleanup tests
This adds a helper function for the cases where you want to
quickly set a single boolean config value for a repository.
This allowed me to remove a lot of code.
2013-03-22 14:27:56 -07:00
Russell Belfer
65025cb893 Three submodule status bug fixes
1. Fix sort order problem with submodules where "mod" was sorting
   after "mod-plus" because they were being sorted as "mod/" and
   "mod-plus/".  This involved pushing the "contains a .git entry"
   test significantly lower in the stack.
2. Reinstate behavior that a directory which contains a .git entry
   will be treated as a submodule during iteration even if it is
   not yet added to the .gitmodules.
3. Now that any directory containing .git is reported as submodule,
   we have to be more careful checking for GIT_EEXISTS when we
   do a submodule lookup, because that is the error code that is
   returned by git_submodule_lookup when you try to look up a
   directory containing .git that has no record in gitmodules or
   the index.
2013-03-18 17:24:13 -07:00
Vicent Martí
1ac10aae1d Merge pull request #1408 from arrbee/refactor-iterators
Refactor iterators
2013-03-12 09:23:53 -07:00
Edward Thomson
aa408cbfc4 handle small files in similarity metrics 2013-03-11 12:47:01 -05:00
Carlos Martín Nieto
1aa5318a9e diff: allow asking for diffs with no context
Previously, 0 meant default. This is problematic, as asking for 0
context lines is a valid thing to do.

Change GIT_DIFF_OPTIONS_INIT to default to three and stop treating 0
as a magic value. In case no options are provided, make sure the
options in the diff object default to 3.
2013-03-09 16:04:34 +01:00
Russell Belfer
9bea03ce77 Add INCLUDE_TREES, DONT_AUTOEXPAND iterator flags
This standardizes iterator behavior across all three iterators
(index, tree, and working directory).  Previously the working
directory iterator behaved differently from the other two.

Each iterator can now operate in one of three modes:

1. *No tree results, auto expand trees* means that only non-
   tree items will be returned and when a tree/directory is
   encountered, we will automatically descend into it.
2. *Tree results, auto expand trees* means that results will
   be given for every item found, including trees, but you
   only need to call normal git_iterator_advance to yield
   every item (i.e. trees returned with pre-order iteration).
3. *Tree results, no auto expand* means that calling the
   normal git_iterator_advance when looking at a tree will
   not descend into the tree, but will skip over it to the
   next entry in the parent.

Previously, behavior 1 was the only option for index and tree
iterators, and behavior 3 was the only option for workdir.

The main public API implications of this are that the
`git_iterator_advance_into()` call is now valid for all
iterators, not just working directory iterators, and all the
existing uses of working directory iterators explicitly use
the GIT_ITERATOR_DONT_AUTOEXPAND (for now).

Interestingly, the majority of the implementation was in the
index iterator, since there are no tree entries there and now
have to fake them.  The tree and working directory iterators
only required small modifications.
2013-03-06 16:52:01 -08:00
Russell Belfer
169dc61607 Make iterator APIs consistent with standards
The iterator APIs are not currently consistent with the parameter
ordering of the rest of the codebase.  This rearranges the order
of parameters, simplifies the naming of a number of functions, and
makes somewhat better use of macros internally to clean up the
iterator code.

This also expands the test coverage of iterator functionality,
making sure that case sensitive range-limited iteration works
correctly.
2013-03-06 16:52:01 -08:00
Carlos Martín Nieto
323bb88514 Fix a few leaks
`git_diff_get_patch()` would unconditionally load the patch object and
then simply leak it if the user hadn't requested it. Short-circuit
loading the object if the user doesn't want it.

The rest of the plugs are simply calling the free functions of objects
allocated during the tests.
2013-03-04 00:21:56 +01:00
Russell Belfer
487fc724ff Allow empty config object and use it
This removes assertions that prevent us from having an empty
git_config object and then updates some tests that were
dependent on global config state to use an empty config before
running anything.
2013-03-01 13:41:53 -08:00
Russell Belfer
7d46b34baf Control for core.autocrlf during testing 2013-03-01 12:26:05 -08:00
Vicent Martí
e68e33f33d Merge pull request #1233 from arrbee/file-similarity-metric
Add file similarity scoring to diff rename/copy detection
2013-02-27 14:50:32 -08:00
Russell Belfer
1be4ba9842 More rename detection tests
This includes tests for crlf changes, whitespace changes with the
default comparison and with the ignore whitespace comparison, and
more sensitivity checking for the comparison code.
2013-02-22 11:13:01 -08:00
Philip Kelley
7beeb3f420 Rename 'exp' so it doesn't conflict with exp() 2013-02-22 14:03:44 -05:00
Russell Belfer
6f9d5ce818 Fix tests for find_similar and related
This fixes both a test that I broke in diff::patch where I was
relying on the current state of the working directory for the
renames test data and fixes an unstable test in diff::rename
where the environment setting for the "diff.renames" config was
being allowed to influence the test results.
2013-02-22 10:17:08 -08:00
Russell Belfer
d4b747c1cb Add diff rename tests with partial similarity
This adds some new tests that actually exercise the similarity
metric between files to detect renames, copies, and split modified
files that are too heavily modified.

There is still more testing to do - these tests are just partially
covering the cases.

There is also one bug fix in this where a change set with only
MODIFY being broken into ADD/DELETE (due to low self-similarity)
without any additional RENAMED entries would end up not processing
the split requests (because the num_rewrites counter got reset).
2013-02-21 16:44:44 -08:00
Russell Belfer
960a04dd56 Initial integration of similarity metric to diff
This is the initial integration of the similarity metric into
the `git_diff_find_similar()` code path.  The existing tests all
pass, but the new functionality isn't currently well tested.  The
integration does go through the pluggable metric interface, so it
should be possible to drop in an alternative to the internal
metric that libgit2 implements.

This comes along with a behavior change for an existing interface;
namely, passing two NULLs to git_diff_blobs (or passing NULLs to
git_diff_blob_to_buffer) will now call the file_cb parameter zero
times instead of one time.  I know it's strange that that change
is paired with this other change, but it emerged from some
initialization changes that I ended up making.
2013-02-21 12:40:33 -08:00
Russell Belfer
71a3d27ea6 Replace diff delta binary with flags
Previously the git_diff_delta recorded if the delta was binary.
This replaces that (with no net change in structure size) with
a full set of flags.  The flag values that were already in use
for individual git_diff_file objects are reused for the delta
flags, too (along with renaming those flags to make it clear that
they are used more generally).

This (a) makes things somewhat more consistent (because I was
using a -1 value in the "boolean" binary field to indicate unset,
whereas now I can just use the flags that are easier to understand),
and (b) will make it easier for me to add some additional flags to
the delta object in the future, such as marking the results of a
copy/rename detection or other deltas that might want a special
indicator.

While making this change, I officially moved some of the flags that
were internal only into the private diff header.

This also allowed me to remove a gross hack in rename/copy detect
code where I was overwriting the status field with an internal
value.
2013-02-20 15:10:21 -08:00
Vicent Martí
fcd7733ded Merge pull request #1318 from nulltoken/topic/diff-tree-coverage
Topic/diff tree coverage
2013-02-14 12:49:46 -08:00
Russell Belfer
c2c0874de2 More diff tests with binary data 2013-02-11 14:45:46 -08:00
Russell Belfer
390a3c8141 Merge pull request #1190 from nulltoken/topic/reset-paths
reset: Allow the selective reset of pathspecs
2013-02-11 11:44:00 -08:00
yorah
0d64ba4837 diff: add a notify callback to git_diff__from_iterators
The callback will be called for each file, just before the `git_delta_t` gets inserted into the diff list.

When the callback:
- returns < 0, the diff process will be aborted
- returns > 0, the delta will not be inserted into the diff list, but the diff process continues
- returns 0, the delta is inserted into the diff list, and the diff process continues
2013-02-07 20:44:35 +01:00
nulltoken
e8993455d1 diff: Enhance tree-to-tree diff test coverage
These tests are related to issue libgit2/libgit2sharp#196
2013-02-06 19:45:44 +01:00
nulltoken
7e8580452c diff: refactor git_diff_tree_to_tree() tests 2013-02-06 16:13:23 +01:00
nulltoken
3ad052218c Fix MSVC compilation warnings
Fix #1308
2013-02-05 20:33:27 +01:00
Russell Belfer
3bf68be443 Free buffer at end of test 2013-01-30 11:25:20 -08:00
Russell Belfer
f1e2735c74 Add helper for diff line stats
This adds a `git_diff_patch_line_stats()` API that gets the total
number of adds, deletes, and context lines in a patch.  This will
make it a little easier to emulate `git diff --stat` and the like.

Right now, this relies on generating the `git_diff_patch` object,
which is a pretty heavyweight way to get stat information.  At
some future point, it would probably be nice to be able to get
this information without allocating the entire `git_diff_patch`,
but that's a much larger project.
2013-01-30 11:10:39 -08:00
Russell Belfer
cce548e3e0 Fix case sensitivity bug with tree iterators
With the new code to make tree iterators support ignore_case,
there is a bug in setting the start entry for range bounded
iterators where memcmp was being used instead of strncasecmp.
This fixes that and expands the tree iterator test to cover
the cases that were broken.
2013-01-22 15:28:25 -08:00
Russell Belfer
25423d03b8 Support case insensitive tree iterators and status
This makes tree iterators directly support case insensitivity by
using a secondary index that can be sorted by icase.  Also, this
fixes the ambiguity check in the git_status_file API to also be
case insensitive.  Lastly, this adds new test cases for case
insensitive range boundary checking for all types of iterators.

With this change, it should be possible to deprecate the spool
and sort iterator, but I haven't done that yet.
2013-01-15 09:51:35 -08:00
Russell Belfer
a49340c3e5 Test for ignore_case ranges on workdir iterator
This adds a test that confirms that the working directory iterator
can actually correctly process ranges of files case insensitively
with proper sorting and proper boundaries.
2013-01-15 09:51:34 -08:00
Russell Belfer
134d8c918c Update iterator API with flags for ignore_case
This changes the iterator API so that flags can be passed in to
the constructor functions to control the ignore_case behavior.
At this point, the flags are not supported on tree iterators (i.e.
there is no functional change over the old API), but the API
changes are all made to accomodate this.

By the way, I went with a flags parameter because in the future
I have a couple of other ideas for iterator flags that will make
it easier to fix some diff/status/checkout bugs.
2013-01-15 09:51:34 -08:00
Russell Belfer
4b18103755 Minor iterator API cleanups
In preparation for further iterator changes, this cleans up a few
small things in the iterator API:

* removed the git_iterator_for_repo_index_range API
* made git_iterator_free not be inlined
* minor param name and test function name tweaks
2013-01-15 09:49:32 -08:00
Russell Belfer
805c476c83 Fix diff patch line number calculation
This was just wrong.  Added a test that verifying patch line
numbers even for hunks further into a file and then fixed the
algorithm.  I needed to add a little extra state into the patch
so that I could track old and new file numbers independently,
but it should be okay.
2013-01-11 11:20:44 -08:00
Carlos Martín Nieto
2086e1baef tests: plug a couple of leaks 2013-01-11 16:54:57 +01:00
Russell Belfer
de59055017 Resolve crash with diff against empty file
It is not legal inside our `p_mmap` function to mmap a zero length
file.  This adds a test that exercises that case inside diff and
fixes the code path where we would try to do that.

The fix turns out not to be a lot of code since our default file
content is already initialized to "" which works in this case.

Fixes #1210
2013-01-08 17:11:11 -08:00
Russell Belfer
f2b7f7a6cb Share git_diff_blobs/git_diff_blob_to_buffer code
This moves the implementation of these two APIs into common code
that will be shared between the two.  Also, this adds tests for
the `git_diff_blob_to_buffer` API.  Lastly, this adds some extra
`const` to a few places that can use it.
2013-01-07 15:44:22 -08:00
Sascha Cunz
d5cf4665a9 Fix some leaks and (possibly) dangling pointers in tests
Also adds some asserts.
2012-12-19 08:04:31 +01:00
Vicent Martí
e62171e2fc Merge pull request #1151 from arrbee/fix-diff-constructor-names
Fix diff constructor names
2012-12-17 11:10:25 -08:00
Russell Belfer
56c72b759c Fix diff constructor name order confusion
The diff constructor functions had some confusing names, where the
"old" side of the diff was coming after the "new" side.  This
reverses the order in the function name to make it less confusing.

Specifically...

* git_diff_index_to_tree becomes git_diff_tree_to_index
* git_diff_workdir_to_index becomes git_diff_index_to_workdir
* git_diff_workdir_to_tree becomes git_diff_tree_to_workdir
2012-12-17 11:00:53 -08:00
nulltoken
a3337f10bb blob: introduce git_blob_is_binary() 2012-12-17 17:20:31 +01:00
Russell Belfer
91e7d26303 Fix iterator reset and add reset ranges
The `git_iterator_reset` command has not been working in all cases
particularly when there is a start and end range.  This fixes it
and adds tests for it, and also extends it with the ability to
update the start/end range strings when an iterator is reset.
2012-12-10 15:38:41 -08:00
Russell Belfer
9950d27ab6 Clean up iterator APIs
This removes the need to explicitly pass the repo into iterators
where the repo is implied by the other parameters.  This moves
the repo to be owned by the parent struct.  Also, this has some
iterator related updates to the internal diff API to lay the
groundwork for checkout improvements.
2012-12-10 15:38:28 -08:00
Ben Straub
0ab3a2ab2c Deploy GIT_INIT_STRUCTURE 2012-11-30 20:34:50 -08:00
Ben Straub
ca901e7b0f Deploy GIT_DIFF_FIND_OPTIONS_INIT 2012-11-30 13:12:15 -08:00
Ben Straub
2f8d30becb Deploy GIT_DIFF_OPTIONS_INIT 2012-11-30 13:12:14 -08:00
Vicent Martí
e2934db2c7 Merge pull request #1090 from arrbee/ignore-invalid-by-default
Ignore invalid entries by default
2012-11-29 02:05:46 -08:00