]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff.c: move read_index() code back to the caller
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 13 Aug 2018 16:14:18 +0000 (18:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Aug 2018 21:14:42 +0000 (14:14 -0700)
This code is only needed for diff-tree (since f0c6b2a2fd ([PATCH]
Optimize diff-tree -[CM] --stdin - 2005-05-27)). Let the caller do the
preparation instead and avoid read_index() in diff.c code.

read_index() should be avoided (in addition to the_index) because it
uses get_index_file() underneath to get the path $GIT_DIR/index. This
effectively pulls the_repository in and may become the only reason to
pull a 'struct repository *' in diff.c. Let's keep the dependencies as
few as possible and kick it back to diff-tree.c

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/diff-tree.c
diff.c
diff.h

index 91ba67070e252fa13a0e32e08a251ca58c7f930b..d07bf2e4c4b5c2ec2f93930c0dd16897df32b25f 100644 (file)
@@ -163,9 +163,11 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
                int saved_nrl = 0;
                int saved_dcctc = 0;
 
-               if (opt->diffopt.detect_rename)
-                       opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
-                                              DIFF_SETUP_USE_CACHE);
+               if (opt->diffopt.detect_rename) {
+                       if (!the_index.cache)
+                               read_index(&the_index);
+                       opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
+               }
                while (fgets(line, sizeof(line), stdin)) {
                        struct object_id oid;
 
diff --git a/diff.c b/diff.c
index 04d044bbb67b77a9992a499d4f7728bb85cfe94f..72ce8007fdf1e64325a7f8545d40a12f6abec1d1 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4414,16 +4414,6 @@ void diff_setup_done(struct diff_options *options)
 
        if (options->detect_rename && options->rename_limit < 0)
                options->rename_limit = diff_rename_limit_default;
-       if (options->setup & DIFF_SETUP_USE_CACHE) {
-               if (!active_cache)
-                       /* read-cache does not die even when it fails
-                        * so it is safe for us to do this here.  Also
-                        * it does not smudge active_cache or active_nr
-                        * when it fails, so we do not have to worry about
-                        * cleaning it up ourselves either.
-                        */
-                       read_cache();
-       }
        if (hexsz < options->abbrev)
                options->abbrev = hexsz; /* full */
 
diff --git a/diff.h b/diff.h
index 20c697dbfef58d95d69bea00decc5aebee3d404a..3ada6ad33c0a03cccc5d0d65c848937945895cd6 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -312,7 +312,6 @@ void diff_change(struct diff_options *,
 struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
 
 #define DIFF_SETUP_REVERSE             1
-#define DIFF_SETUP_USE_CACHE           2
 #define DIFF_SETUP_USE_SIZE_CACHE      4
 
 /*