diff.c: move read_index() code back to the caller
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>
Nguyễn Thái Ngọc Duy committed
Aug 13, 2018 at 18:14 UTC
ff7fe37b0530c0ddb5a88fe41b963b68b3f66127
3 files changed
+5
-14
builtin/diff-tree.c
+5
-3
@@ -163,9 +163,11 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
163
int saved_nrl = 0;
164
int saved_dcctc = 0;
165
166
- if (opt->diffopt.detect_rename)
167
- opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
168
- DIFF_SETUP_USE_CACHE);
166
+ if (opt->diffopt.detect_rename) {
167
+ if (!the_index.cache)
168
+ read_index(&the_index);
169
+ opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
170
+ }
171
while (fgets(line, sizeof(line), stdin)) {
172
struct object_id oid;
173
diff.c
-10
@@ -4414,16 +4414,6 @@ void diff_setup_done(struct diff_options *options)
4414
4415
if (options->detect_rename && options->rename_limit < 0)
4416
options->rename_limit = diff_rename_limit_default;
4417
- if (options->setup & DIFF_SETUP_USE_CACHE) {
4418
- if (!active_cache)
4419
- /* read-cache does not die even when it fails
4420
- * so it is safe for us to do this here. Also
4421
- * it does not smudge active_cache or active_nr
4422
- * when it fails, so we do not have to worry about
4423
- * cleaning it up ourselves either.
4424
- */
4425
- read_cache();
4426
- }
4417
if (hexsz < options->abbrev)
4418
options->abbrev = hexsz; /* full */
4419
diff.h
-1
@@ -312,7 +312,6 @@ void diff_change(struct diff_options *,
312
struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
313
314
#define DIFF_SETUP_REVERSE 1
315
-#define DIFF_SETUP_USE_CACHE 2
315
#define DIFF_SETUP_USE_SIZE_CACHE 4
316
317
/*