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>
Johannes Schindelin committed
Jan 20, 2008 at 15:19 UTC
204ce979a5ed6f182e56bea5282c7b4a2d91208a
1 file changed
+13
-79
diff-lib.c
+13
-79
@@ -577,81 +577,6 @@ static int show_modified(struct rev_info *revs,
577
return 0;
578
}
579
580
-static int diff_cache(struct rev_info *revs,
581
- struct cache_entry **ac, int entries,
582
- const char **pathspec,
583
- int cached, int match_missing)
584
-{
585
- while (entries) {
586
- struct cache_entry *ce = *ac;
587
- int same = (entries > 1) && ce_same_name(ce, ac[1]);
588
-
589
- if (DIFF_OPT_TST(&revs->diffopt, QUIET) &&
590
- DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
591
- break;
592
-
593
- if (!ce_path_match(ce, pathspec))
594
- goto skip_entry;
595
-
596
- switch (ce_stage(ce)) {
597
- case 0:
598
- /* No stage 1 entry? That means it's a new file */
599
- if (!same) {
600
- show_new_file(revs, ce, cached, match_missing);
601
- break;
602
- }
603
- /* Show difference between old and new */
604
- show_modified(revs, ac[1], ce, 1,
605
- cached, match_missing);
606
- break;
607
- case 1:
608
- /* No stage 3 (merge) entry?
609
- * That means it's been deleted.
610
- */
611
- if (!same) {
612
- diff_index_show_file(revs, "-", ce,
613
- ce->sha1, ce->ce_mode);
614
- break;
615
- }
616
- /* We come here with ce pointing at stage 1
617
- * (original tree) and ac[1] pointing at stage
618
- * 3 (unmerged). show-modified with
619
- * report-missing set to false does not say the
620
- * file is deleted but reports true if work
621
- * tree does not have it, in which case we
622
- * fall through to report the unmerged state.
623
- * Otherwise, we show the differences between
624
- * the original tree and the work tree.
625
- */
626
- if (!cached &&
627
- !show_modified(revs, ce, ac[1], 0,
628
- cached, match_missing))
629
- break;
630
- diff_unmerge(&revs->diffopt, ce->name,
631
- ce->ce_mode, ce->sha1);
632
- break;
633
- case 3:
634
- diff_unmerge(&revs->diffopt, ce->name,
635
- 0, null_sha1);
636
- break;
637
-
638
- default:
639
- die("impossible cache entry stage");
640
- }
641
-
642
-skip_entry:
643
- /*
644
- * Ignore all the different stages for this file,
645
- * we've handled the relevant cases now.
646
- */
647
- do {
648
- ac++;
649
- entries--;
650
- } while (entries && ce_same_name(ce, ac[0]));
651
- }
652
- return 0;
653
-}
654
-
580
/*
581
* This turns all merge entries into "stage 3". That guarantees that
582
* 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)
751
int i;
752
struct cache_entry **dst;
753
struct cache_entry *last = NULL;
754
+ struct unpack_trees_options opts;
755
+ struct tree_desc t;
756
757
/*
758
* 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)
780
tree = parse_tree_indirect(tree_sha1);
781
if (!tree)
782
die("bad tree object %s", sha1_to_hex(tree_sha1));
856
- if (read_tree(tree, 1, opt->paths))
857
- return error("unable to read tree %s", sha1_to_hex(tree_sha1));
858
- return diff_cache(&revs, active_cache, active_nr, revs.prune_data,
859
- 1, 0);
783
+
784
+ memset(&opts, 0, sizeof(opts));
785
+ opts.head_idx = 1;
786
+ opts.index_only = 1;
787
+ opts.merge = 1;
788
+ opts.fn = oneway_diff;
789
+ opts.unpack_data = &revs;
790
+
791
+ init_tree_desc(&t, tree->buffer, tree->size);
792
+ unpack_trees(1, &t, &opts);
793
+ return 0;
794
}