Commit Graph

15 Commits

Author SHA1 Message Date
nulltoken
c2e43fb1f2 diff: workdir diffing in a bare repo returns EBAREREPO 2012-10-18 23:38:27 +02:00
Russell Belfer
5d1308f25f Add test for diffs with submodules and bug fixes
The adds a test for the submodule diff capabilities and then
fixes a few bugs with how the output is generated.  It improves
the accuracy of OIDs in the diff delta object and makes the
submodule output more closely mirror the OIDs that will be used
by core git.
2012-10-08 15:22:40 -07:00
Russell Belfer
bae957b95d Add const to all shared pointers in diff API
There are a lot of places where the diff API gives the user access
to internal data structures and many of these were being exposed
through non-const pointers.  This replaces them all with const
pointers for any object that the user can access but is still
owned internally to the git_diff_list or git_diff_patch objects.

This will probably break some bindings...  Sorry!
2012-09-25 16:35:05 -07:00
Russell Belfer
5f69a31f7d Initial implementation of new diff patch API
Replacing the `git_iterator` object, this creates a simple API
for accessing the "patch" for any file pair in a diff list and
then gives indexed access to the hunks in the patch and the lines
in the hunk.  This is the initial implementation of this revised
API - it is still broken, but at least builds cleanly.
2012-09-25 16:35:05 -07:00
Russell Belfer
49d34c1c0c Fix problems in diff iterator record chaining
There is a bug in building the linked list of line records in the
diff iterator and also an off by one element error in the hunk
counts.  This fixes both of these, adds some test data with more
complex sets of hunk and line diffs to exercise this code better.
2012-09-13 13:17:38 -07:00
Russell Belfer
f335ecd6e1 Diff iterators
This refactors the diff output code so that an iterator object
can be used to traverse and generate the diffs, instead of just
the `foreach()` style with callbacks.  The code has been rearranged
so that the two styles can still share most functions.

This also replaces `GIT_REVWALKOVER` with `GIT_ITEROVER` and uses
that as a common error code for marking the end of iteration when
using a iterator style of object.
2012-09-05 15:17:24 -07:00
Carlos Martín Nieto
cdca82c784 Plug a few leaks 2012-06-20 00:46:34 +02:00
Russell Belfer
145e696b49 Minor fixes, cleanups, and clarifications
There are three actual changes in this commit:

1. When the trailing newline of a file is removed in a diff, the
   change will now be reported with `GIT_DIFF_LINE_DEL_EOFNL` passed
   to the callback.  Previously, the `ADD_EOFNL` constant was given
   which was just an error in my understanding of when the various
   circumstances arose.  `GIT_DIFF_LINE_ADD_EOFNL` is deprecated and
   should never be generated.  A new newline is simply an `ADD`.
2. Rewrote the `diff_delta__merge_like_cgit` function that contains
   the core logic of the `git_diff_merge` implementation.  The new
   version doesn't actually have significantly different behavior,
   but the logic should be much more obvious, I think.
3. Fixed a bug in `git_diff_merge` where it freed a string pool
   while some of the string data was still in use.  This led to
   `git_diff_print_patch` accessing memory that had been freed.

The rest of this commit contains improved documentation in `diff.h`
to make the behavior and the equivalencies with core git clearer,
and a bunch of new tests to cover the various cases, oh and a minor
simplification of `examples/diff.c`.
2012-06-08 12:11:13 -07:00
Russell Belfer
0abd724454 Fix filemode comparison in diffs
File modes were both not being ignored properly on platforms
where they should be ignored, nor be diffed consistently on
platforms where they are supported.

This change adds a number of diff and status filemode change
tests.  This also makes sure that filemode-only changes are
included in the diff output when they occur and that filemode
changes are ignored successfully when core.filemode is false.

There is no code that automatically toggles core.filemode
based on the capabilities of the current platform, so the user
still needs to be careful in their .git/config file.
2012-06-08 12:09:10 -07:00
Adam Roben
8e60c712ac Fix git_status_file for files that start with a character > 0x7f
git_status_file would always return GIT_ENOTFOUND for these files.

The underlying bug was that git__strcmp_cb, which is used by
git_path_with_stat_cmp to sort entries in the working directory,
compares strings based on unsigned chars (this is confirmed by the
strcmp(3) manpage), while git__prefixcmp, which is used by
workdir_iterator__entry_cmp to search for a path in the working
directory, compares strings based on char. So the sort puts this path at
the end of the list, while the search expects it to be at the beginning.

The fix was simply to make git__prefixcmp compare using unsigned chars,
just like strcmp(3). The rest of the change is just adding/updating
tests.
2012-06-07 09:50:19 -04:00
Russell Belfer
1a6e8f8a54 Update clar and remove old helpers
This updates to the latest clar which includes the helpers
`cl_assert_equal_s` and `cl_assert_equal_i`.  Convert the code
over to use those and remove the old libgit2-only helpers.
2012-04-17 10:35:11 -07:00
Russell Belfer
14a513e058 Add support for pathspec to diff and status
This adds preliminary support for pathspecs to diff and status.
The implementation is not very optimized (it still looks at
every single file and evaluated the the pathspec match against
them), but it works.
2012-04-13 15:00:29 -07:00
Russell Belfer
c19bc93cef Fixing memory leaks indicated by valgrind
This clears up the memory leaks that valgrind seems to find on
my machine.
2012-03-02 15:51:55 -08:00
Russell Belfer
854eccbb2d Clean up GIT_UNUSED macros on all platforms
It turns out that commit 31e9cfc4cbcaf1b38cdd3dbe3282a8f57e5366a5
did not fix the GIT_USUSED behavior on all platforms.  This commit
walks through and really cleans things up more thoroughly, getting
rid of the unnecessary stuff.

To remove the use of some GIT_UNUSED, I ended up adding a couple
of new iterators for hashtables that allow you to iterator just
over keys or just over values.

In making this change, I found a bug in the clar tests (where we
were doing *count++ but meant to do (*count)++ to increment the
value).  I fixed that but then found the test failing because it
was not really using an empty repo.  So, I took some of the code
that I wrote for iterator testing and moved it to clar_helpers.c,
then made use of that to make it easier to open fixtures on a
per test basis even within a single test file.
2012-03-02 15:51:55 -08:00
Russell Belfer
74fa4bfae3 Update diff to use iterators
This is a major reorganization of the diff code.  This changes
the diff functions to use the iterators for traversing the
content.  This allowed a lot of code to be simplified.  Also,
this moved the functions relating to outputting a diff into a
new file (diff_output.c).

This includes a number of other changes - adding utility
functions, extending iterators, etc. plus more tests for the
diff code.  This also takes the example diff.c program much
further in terms of emulating git-diff command line options.
2012-03-02 15:49:29 -08:00