Fix performance regression for partial commits
When running "git commit paths" to create a partial commit, we used to carefully build the temporary index so that we do not lose the cached stat information. The rewrite of the command in C lost it by carelessly using read_tree(). This resurrects the earlier behaviour to keep the cached stat information as much as possible by using one-tree merge logic. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Jan 13, 2008 at 00:30 UTC
fa9dcf80e1048ea996349891a885ac325019fcac
1 file changed
+28
-9
builtin-commit.c
+28
-9
@@ -21,6 +21,7 @@
21
#include "utf8.h"
22
#include "parse-options.h"
23
#include "path-list.h"
24
+#include "unpack-trees.h"
25
26
static const char * const builtin_commit_usage[] = {
27
"git-commit [options] [--] <filepattern>...",
@@ -177,10 +178,34 @@ static void add_remove_files(struct path_list *list)
178
}
179
}
180
181
+static void create_base_index(void)
182
+{
183
+ struct tree *tree;
184
+ struct unpack_trees_options opts;
185
+ struct tree_desc t;
186
+
187
+ if (initial_commit) {
188
+ discard_cache();
189
+ return;
190
+ }
191
+
192
+ memset(&opts, 0, sizeof(opts));
193
+ opts.head_idx = 1;
194
+ opts.index_only = 1;
195
+ opts.merge = 1;
196
+
197
+ opts.fn = oneway_merge;
198
+ tree = parse_tree_indirect(head_sha1);
199
+ if (!tree)
200
+ die("failed to unpack HEAD tree object");
201
+ parse_tree(tree);
202
+ init_tree_desc(&t, tree->buffer, tree->size);
203
+ unpack_trees(1, &t, &opts);
204
+}
205
+
206
static char *prepare_index(int argc, const char **argv, const char *prefix)
207
{
208
int fd;
183
- struct tree *tree;
209
struct path_list partial;
210
const char **pathspec = NULL;
211
@@ -278,14 +303,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
303
304
fd = hold_lock_file_for_update(&false_lock,
305
git_path("next-index-%d", getpid()), 1);
281
- discard_cache();
282
- if (!initial_commit) {
283
- tree = parse_tree_indirect(head_sha1);
284
- if (!tree)
285
- die("failed to unpack HEAD tree object");
286
- if (read_tree(tree, 0, NULL))
287
- die("failed to read HEAD tree object");
288
- }
306
+
307
+ create_base_index();
308
add_remove_files(&partial);
309
refresh_cache(REFRESH_QUIET);
310