diff-lib: simplify do_diff_cache()
[gitweb.git] / diff-lib.c
index 3b5f2242a597ff1b44a3af6be72cb14e6e0d5455..b5bb58d1832db97fc87addbc19f2234424e52dd6 100644 (file)
@@ -102,9 +102,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                int changed;
                unsigned dirty_submodule = 0;
 
-               if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
-                   !revs->diffopt.filter &&
-                   DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
+               if (diff_can_quit_early(&revs->diffopt))
                        break;
 
                if (!ce_path_match(ce, &revs->prune_data))
@@ -381,7 +379,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
        if (cached && idx && ce_stage(idx)) {
                struct diff_filepair *pair;
                pair = diff_unmerge(&revs->diffopt, idx->name);
-               fill_filespec(pair->one, idx->sha1, idx->ce_mode);
+               if (tree)
+                       fill_filespec(pair->one, tree->sha1, tree->ce_mode);
                return;
        }
 
@@ -481,33 +480,9 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
 {
        struct tree *tree;
        struct rev_info revs;
-       int i;
-       struct cache_entry **dst;
-       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;
-        * it potentially needs to repeatedly run this, so we will
-        * start by removing the higher order entries the last round
-        * left behind.
-        */
-       dst = active_cache;
-       for (i = 0; i < active_nr; i++) {
-               struct cache_entry *ce = active_cache[i];
-               if (ce_stage(ce)) {
-                       if (last && !strcmp(ce->name, last->name))
-                               continue;
-                       cache_tree_invalidate_path(active_cache_tree,
-                                                  ce->name);
-                       last = ce;
-                       ce->ce_flags |= CE_REMOVE;
-               }
-               *dst++ = ce;
-       }
-       active_nr = dst - active_cache;
-
        init_revisions(&revs, NULL);
        init_pathspec(&revs.prune_data, opt->pathspec.raw);
        tree = parse_tree_indirect(tree_sha1);
@@ -522,7 +497,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
        opts.fn = oneway_diff;
        opts.unpack_data = &revs;
        opts.src_index = &the_index;
-       opts.dst_index = &the_index;
+       opts.dst_index = NULL;
 
        init_tree_desc(&t, tree->buffer, tree->size);
        if (unpack_trees(1, &t, &opts))