Skip to content

Commit fcba80a

Browse files
Takuto Ikutadscho
Takuto Ikuta
authored andcommitted
reset.c: enable fscache
In git reset --hard, unpack-trees() is called with oneway_merge(). oneway_merge calls lstat for each files in a repository. It is bottleneck of git reset --hard, especially in large repository. This patch improves time by using fscache. In chromium repository, time of git reset --hard is changed like below. I took 3 times stats in the repository. master: TotalSeconds: 21.0337971 TotalSeconds: 20.0046612 TotalSeconds: 20.6501752 Avg: 20.5628778333333 this patch: TotalSeconds: 4.8552376 TotalSeconds: 4.8722343 TotalSeconds: 4.9268245 Avg: 4.88476546666667 Signed-off-by: Takuto Ikuta <[email protected]>
1 parent 44db187 commit fcba80a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

builtin/reset.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
5252
struct tree *tree;
5353
struct unpack_trees_options opts;
5454
int ret = -1;
55+
int unpack_result;
5556

5657
memset(&opts, 0, sizeof(opts));
5758
opts.head_idx = 1;
@@ -91,7 +92,11 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
9192
}
9293
nr++;
9394

94-
if (unpack_trees(nr, desc, &opts))
95+
enable_fscache(1);
96+
unpack_result = unpack_trees(nr, desc, &opts);
97+
enable_fscache(0);
98+
99+
if (unpack_result)
95100
goto out;
96101

97102
if (reset_type == MIXED || reset_type == HARD) {

0 commit comments

Comments
 (0)