diff options
author | Jeff King <peff@peff.net> | 2014-08-19 22:14:30 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-08-20 13:38:37 -0700 |
commit | e09867f0605702c2d4e65b99e178cdaa215a7370 (patch) | |
tree | 8e4d20014a8be2fbe2d4e7c0c4b094713df89369 /combine-diff.c | |
parent | fce135c4ffc87f85e1c3b5c57a6d9e1abdbd074d (diff) | |
download | git-e09867f0605702c2d4e65b99e178cdaa215a7370.tar.gz |
intersect_paths: respect mode in git's tree-sortjk/diff-tree-t-fix
When we do a combined diff, we individually diff against
each parent, and then use intersect_paths to do a parallel
walk through the sorted results and come up with a final
list of interesting paths.
The sort order here is that returned by the diffs, which
means it is in git's tree-order which sorts sub-trees as if
their paths have "/" at the end. When we do our parallel
walk, we need to use a comparison function which provides
the same order.
Since 8518ff8 (combine-diff: optimize combine_diff_path sets
intersection, 2014-01-20), we use a simple strcmp to
compare the pathnames, and get this wrong. It's somewhat
hard to trigger because normally a diff does not produce
tree entries at all, and therefore the sort order is the
same as a strcmp. However, if the "-t" option is used with
the diff, then we will produce diff_filepairs for both trees
and files.
We can use base_name_compare to do the comparison, just as
the tree-diff code does. Even though what we have are not
technically base names (they are full paths within the
tree), the end result is the same (we do not care about
interior slashes at all, only about the final character).
However, since we do not have the length of each path
stored, we take a slight shortcut: if neither of the entries
is a sub-tree then the comparison is equivalent to a strcmp.
This lets us skip the extra strlen calls in the common case
without having to reimplement base_name_compare from
scratch.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'combine-diff.c')
-rw-r--r-- | combine-diff.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/combine-diff.c b/combine-diff.c index 24ca7e2334..4e043060f0 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -12,6 +12,16 @@ #include "sha1-array.h" #include "revision.h" +static int compare_paths(const struct combine_diff_path *one, + const struct diff_filespec *two) +{ + if (!S_ISDIR(one->mode) && !S_ISDIR(two->mode)) + return strcmp(one->path, two->path); + + return base_name_compare(one->path, strlen(one->path), one->mode, + two->path, strlen(two->path), two->mode); +} + static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr, int n, int num_parent) { struct diff_queue_struct *q = &diff_queued_diff; @@ -52,7 +62,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr, i = 0; while ((p = *tail) != NULL) { cmp = ((i >= q->nr) - ? -1 : strcmp(p->path, q->queue[i]->two->path)); + ? -1 : compare_paths(p, q->queue[i]->two)); if (cmp < 0) { /* p->path not in q->queue[]; drop it */ |