Also use unpack_trees() in do_diff_cache()
As in run_diff_index(), we call unpack_trees() with the oneway_diff() function in do_diff_cache() now. This makes the function diff_cache() obsolete. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
d1f2d7e8ca
commit
204ce979a5
92
diff-lib.c
92
diff-lib.c
@ -577,81 +577,6 @@ static int show_modified(struct rev_info *revs,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_cache(struct rev_info *revs,
|
|
||||||
struct cache_entry **ac, int entries,
|
|
||||||
const char **pathspec,
|
|
||||||
int cached, int match_missing)
|
|
||||||
{
|
|
||||||
while (entries) {
|
|
||||||
struct cache_entry *ce = *ac;
|
|
||||||
int same = (entries > 1) && ce_same_name(ce, ac[1]);
|
|
||||||
|
|
||||||
if (DIFF_OPT_TST(&revs->diffopt, QUIET) &&
|
|
||||||
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!ce_path_match(ce, pathspec))
|
|
||||||
goto skip_entry;
|
|
||||||
|
|
||||||
switch (ce_stage(ce)) {
|
|
||||||
case 0:
|
|
||||||
/* No stage 1 entry? That means it's a new file */
|
|
||||||
if (!same) {
|
|
||||||
show_new_file(revs, ce, cached, match_missing);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* Show difference between old and new */
|
|
||||||
show_modified(revs, ac[1], ce, 1,
|
|
||||||
cached, match_missing);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
/* No stage 3 (merge) entry?
|
|
||||||
* That means it's been deleted.
|
|
||||||
*/
|
|
||||||
if (!same) {
|
|
||||||
diff_index_show_file(revs, "-", ce,
|
|
||||||
ce->sha1, ce->ce_mode);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* We come here with ce pointing at stage 1
|
|
||||||
* (original tree) and ac[1] pointing at stage
|
|
||||||
* 3 (unmerged). show-modified with
|
|
||||||
* report-missing set to false does not say the
|
|
||||||
* file is deleted but reports true if work
|
|
||||||
* tree does not have it, in which case we
|
|
||||||
* fall through to report the unmerged state.
|
|
||||||
* Otherwise, we show the differences between
|
|
||||||
* the original tree and the work tree.
|
|
||||||
*/
|
|
||||||
if (!cached &&
|
|
||||||
!show_modified(revs, ce, ac[1], 0,
|
|
||||||
cached, match_missing))
|
|
||||||
break;
|
|
||||||
diff_unmerge(&revs->diffopt, ce->name,
|
|
||||||
ce->ce_mode, ce->sha1);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
diff_unmerge(&revs->diffopt, ce->name,
|
|
||||||
0, null_sha1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
die("impossible cache entry stage");
|
|
||||||
}
|
|
||||||
|
|
||||||
skip_entry:
|
|
||||||
/*
|
|
||||||
* Ignore all the different stages for this file,
|
|
||||||
* we've handled the relevant cases now.
|
|
||||||
*/
|
|
||||||
do {
|
|
||||||
ac++;
|
|
||||||
entries--;
|
|
||||||
} while (entries && ce_same_name(ce, ac[0]));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This turns all merge entries into "stage 3". That guarantees that
|
* This turns all merge entries into "stage 3". That guarantees that
|
||||||
* when we read in the new tree (into "stage 1"), we won't lose sight
|
* when we read in the new tree (into "stage 1"), we won't lose sight
|
||||||
@ -826,6 +751,8 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
|
|||||||
int i;
|
int i;
|
||||||
struct cache_entry **dst;
|
struct cache_entry **dst;
|
||||||
struct cache_entry *last = NULL;
|
struct cache_entry *last = NULL;
|
||||||
|
struct unpack_trees_options opts;
|
||||||
|
struct tree_desc t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is used by git-blame to run diff-cache internally;
|
* This is used by git-blame to run diff-cache internally;
|
||||||
@ -853,8 +780,15 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
|
|||||||
tree = parse_tree_indirect(tree_sha1);
|
tree = parse_tree_indirect(tree_sha1);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
die("bad tree object %s", sha1_to_hex(tree_sha1));
|
die("bad tree object %s", sha1_to_hex(tree_sha1));
|
||||||
if (read_tree(tree, 1, opt->paths))
|
|
||||||
return error("unable to read tree %s", sha1_to_hex(tree_sha1));
|
memset(&opts, 0, sizeof(opts));
|
||||||
return diff_cache(&revs, active_cache, active_nr, revs.prune_data,
|
opts.head_idx = 1;
|
||||||
1, 0);
|
opts.index_only = 1;
|
||||||
|
opts.merge = 1;
|
||||||
|
opts.fn = oneway_diff;
|
||||||
|
opts.unpack_data = &revs;
|
||||||
|
|
||||||
|
init_tree_desc(&t, tree->buffer, tree->size);
|
||||||
|
unpack_trees(1, &t, &opts);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user