summaryrefslogtreecommitdiff
path: root/diff-lib.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2008-03-11 22:13:44 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2008-03-11 22:13:44 -0700
commitb85997d14d1873a4baa3d04966cd5947e6134acd (patch)
treeb21c76c4bc0d3fbb4221283334065216e17beff1 /diff-lib.c
parentMerge branch 'maint' (diff)
parentunpack_trees(): fix diff-index regression. (diff)
downloadtgif-b85997d14d1873a4baa3d04966cd5947e6134acd.tar.xz
Merge branch 'lt/unpack-trees'
* lt/unpack-trees: unpack_trees(): fix diff-index regression. traverse_trees_recursive(): propagate merge errors up unpack_trees(): minor memory leak fix in unused destination index Make 'unpack_trees()' have a separate source and destination index Make 'unpack_trees()' take the index to work on as an argument Add 'const' where appropriate to index handling functions Fix tree-walking compare_entry() in the presense of --prefix Move 'unpack_trees()' over to 'traverse_trees()' interface Make 'traverse_trees()' traverse conflicting DF entries in parallel Add return value to 'traverse_tree()' callback Make 'traverse_tree()' use linked structure rather than 'const char *base' Add 'df_name_compare()' helper function
Diffstat (limited to 'diff-lib.c')
-rw-r--r--diff-lib.c55
1 files changed, 21 insertions, 34 deletions
diff --git a/diff-lib.c b/diff-lib.c
index 4581b594d0..52dbac34a4 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -600,8 +600,7 @@ static void mark_merge_entries(void)
*/
static void do_oneway_diff(struct unpack_trees_options *o,
struct cache_entry *idx,
- struct cache_entry *tree,
- int idx_pos, int idx_nr)
+ struct cache_entry *tree)
{
struct rev_info *revs = o->unpack_data;
int match_missing, cached;
@@ -642,32 +641,19 @@ static void do_oneway_diff(struct unpack_trees_options *o,
show_modified(revs, tree, idx, 1, cached, match_missing);
}
-/*
- * Count how many index entries go with the first one
- */
-static inline int count_skip(const struct cache_entry *src, int pos)
+static inline void skip_same_name(struct cache_entry *ce, struct unpack_trees_options *o)
{
- int skip = 1;
-
- /* We can only have multiple entries if the first one is not stage-0 */
- if (ce_stage(src)) {
- struct cache_entry **p = active_cache + pos;
- int namelen = ce_namelen(src);
-
- for (;;) {
- const struct cache_entry *ce;
- pos++;
- if (pos >= active_nr)
- break;
- ce = *++p;
- if (ce_namelen(ce) != namelen)
- break;
- if (memcmp(ce->name, src->name, namelen))
- break;
- skip++;
- }
+ int len = ce_namelen(ce);
+ const struct index_state *index = o->src_index;
+
+ while (o->pos < index->cache_nr) {
+ struct cache_entry *next = index->cache[o->pos];
+ if (len != ce_namelen(next))
+ break;
+ if (memcmp(ce->name, next->name, len))
+ break;
+ o->pos++;
}
- return skip;
}
/*
@@ -685,17 +671,14 @@ static inline int count_skip(const struct cache_entry *src, int pos)
* the fairly complex unpack_trees() semantic requirements, including
* the skipping, the path matching, the type conflict cases etc.
*/
-static int oneway_diff(struct cache_entry **src,
- struct unpack_trees_options *o,
- int index_pos)
+static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
{
- int skip = 0;
struct cache_entry *idx = src[0];
struct cache_entry *tree = src[1];
struct rev_info *revs = o->unpack_data;
- if (index_pos >= 0)
- skip = count_skip(idx, index_pos);
+ if (idx && ce_stage(idx))
+ skip_same_name(idx, o);
/*
* Unpack-trees generates a DF/conflict entry if
@@ -707,9 +690,9 @@ static int oneway_diff(struct cache_entry **src,
tree = NULL;
if (ce_path_match(idx ? idx : tree, revs->prune_data))
- do_oneway_diff(o, idx, tree, index_pos, skip);
+ do_oneway_diff(o, idx, tree);
- return skip;
+ return 0;
}
int run_diff_index(struct rev_info *revs, int cached)
@@ -734,6 +717,8 @@ int run_diff_index(struct rev_info *revs, int cached)
opts.merge = 1;
opts.fn = oneway_diff;
opts.unpack_data = revs;
+ opts.src_index = &the_index;
+ opts.dst_index = NULL;
init_tree_desc(&t, tree->buffer, tree->size);
if (unpack_trees(1, &t, &opts))
@@ -787,6 +772,8 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
opts.merge = 1;
opts.fn = oneway_diff;
opts.unpack_data = &revs;
+ opts.src_index = &the_index;
+ opts.dst_index = &the_index;
init_tree_desc(&t, tree->buffer, tree->size);
if (unpack_trees(1, &t, &opts))