Skip to content

Commit ff7fe37

Browse files
pcloudsgitster
authored andcommitted
diff.c: move read_index() code back to the caller
This code is only needed for diff-tree (since f0c6b2a ([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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4dcd706 commit ff7fe37

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

builtin/diff-tree.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
163163
int saved_nrl = 0;
164164
int saved_dcctc = 0;
165165

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+
}
169171
while (fgets(line, sizeof(line), stdin)) {
170172
struct object_id oid;
171173

diff.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,16 +4414,6 @@ void diff_setup_done(struct diff_options *options)
44144414

44154415
if (options->detect_rename && options->rename_limit < 0)
44164416
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-
}
44274417
if (hexsz < options->abbrev)
44284418
options->abbrev = hexsz; /* full */
44294419

diff.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ void diff_change(struct diff_options *,
312312
struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
313313

314314
#define DIFF_SETUP_REVERSE 1
315-
#define DIFF_SETUP_USE_CACHE 2
316315
#define DIFF_SETUP_USE_SIZE_CACHE 4
317316

318317
/*

0 commit comments

Comments
 (0)