unpack_trees(): fix diff-index regression.
When skip_unmerged option is not given, unpack_trees() should not just skip unmerged cache entries but keep them in the result for the caller to sort them out. For callers other than diff-index, the incoming index should never be unmerged, but diff-index is a special case caller. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Mar 10, 2008 at 23:51 UTC
20a16eb33eee99fd3eab00c72f012b98d4eeee76
2 files changed
+18
-2
diff-lib.c
+18
@@ -641,6 +641,21 @@ static void do_oneway_diff(struct unpack_trees_options *o,
641
show_modified(revs, tree, idx, 1, cached, match_missing);
642
}
643
644
+static inline void skip_same_name(struct cache_entry *ce, struct unpack_trees_options *o)
645
+{
646
+ int len = ce_namelen(ce);
647
+ const struct index_state *index = o->src_index;
648
+
649
+ while (o->pos < index->cache_nr) {
650
+ struct cache_entry *next = index->cache[o->pos];
651
+ if (len != ce_namelen(next))
652
+ break;
653
+ if (memcmp(ce->name, next->name, len))
654
+ break;
655
+ o->pos++;
656
+ }
657
+}
658
+
659
/*
660
* The unpack_trees() interface is designed for merging, so
661
* the different source entries are designed primarily for
@@ -662,6 +677,9 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
677
struct cache_entry *tree = src[1];
678
struct rev_info *revs = o->unpack_data;
679
680
+ if (idx && ce_stage(idx))
681
+ skip_same_name(idx, o);
682
+
683
/*
684
* Unpack-trees generates a DF/conflict entry if
685
* there was a directory in the index and a tree
unpack-trees.c
-2
@@ -116,7 +116,6 @@ static int unpack_index_entry(struct cache_entry *ce, struct unpack_trees_option
116
add_entry(o, ce, 0, 0);
117
return 0;
118
}
119
- return 0;
119
}
120
return call_unpack_fn(src, o);
121
}
@@ -286,7 +285,6 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
285
add_entry(o, ce, 0, 0);
286
return mask;
287
}
289
- continue;
288
}
289
src[0] = ce;
290
}