oneway_merge(): only lstat() when told to update worktree

Although the subject line of 613f027 (read-tree -u one-way merge fix to check out locally modified paths., 2006-05-15) mentions "read-tree -u", it did not seem to check whether -u was in effect. Not checking whether -u is in effect makes e.g. "read-tree --reset" lstat() the worktree, even though the worktree stat should not matter for that operation. This speeds up e.g. "git reset" a little on the linux-2.6 repo (best of five, warm cache): Before After real 0m0.288s 0m0.233s user 0m0.190s 0m0.150s sys 0m0.090s 0m0.080s Signed-off-by: Martin von Zweigbergk <martinvonz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin von Zweigbergk committed Dec 20, 2012 at 13:03 UTC 686b2de0ceb2c5a1fb6c8822a8aceb8a05e2fc76
1 file changed +1 -1
unpack-trees.c
+1 -1
@@ -1834,7 +1834,7 @@ int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1834
1835 if (old && same(old, a)) {
1836 int update = 0;
1837 - if (o->reset && !ce_uptodate(old) && !ce_skip_worktree(old)) {
1837 + if (o->reset && o->update && !ce_uptodate(old) && !ce_skip_worktree(old)) {
1838 struct stat st;
1839 if (lstat(old->name, &st) ||
1840 ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE))