10 Feb 10:42
git status: small difference between stating whole repository and small subdirectory
Piotr Krukowiecki <piotr.krukowiecki <at> gmail.com>
2012-02-10 09:42:22 GMT
2012-02-10 09:42:22 GMT
Hi, I compared stating whole tree vs one small subdirectory, and I expected that for the subdirectory status will be very very fast. After all, it has only few files to stat. But it's not fast. Why? With cold cache (echo 3 | sudo tee /proc/sys/vm/drop_caches): $ time git status > /dev/null real 0m41.670s user 0m0.980s sys 0m2.908s $ time git status -- src/.../somedir > /dev/null real 0m17.380s user 0m0.748s sys 0m0.328s With warm cache: $ time git status > /dev/null real 0m0.792s user 0m0.404s sys 0m0.384s $ time git status -- src/.../somedir > /dev/null real 0m0.335s user 0m0.288s sys 0m0.048s(Continue reading)
Quick and dirty that passes that test. I think we could do better if
we analyse two way merge rules carefully and avoid this diff, but
that's too much for me right now.
-- 8< --
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 5bf96ba..c06287a 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -319,6 +319,10 @@ static void show_local_changes(struct object *head, struct diff_options *opts)
die(_("diff_setup_done failed"));
add_pending_object(&rev, head, NULL);
run_diff_index(&rev, 0);
+ if (!DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES)) {
+ struct tree *tree = parse_tree_indirect(head->sha1);
+ prime_cache_tree(&active_cache_tree, tree);
+ }
Browsing around in history, it seems that this was silently broken by
34110cd (Make 'unpack_trees()' have a separate source and destination
index, 2008-03-06), which introduced the distinction between source and
destination index. Before that they were the same, so the cache tree
would have been updated correctly.
> It makes "git checkout" with no changes just work (since we preserve the
> cache tree, and it doesn't need updated). It makes something like "git
> checkout HEAD^" work, keeping most of the cache-tree intact, but
> invalidating trees containing paths that were modified.
Great. Here's a test you could use. It's a bit noisy because the
RSS Feed