All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkout: swap the order of ambiguity check for :/ syntax
@ 2016-08-22 12:35 Nguyễn Thái Ngọc Duy
  2016-08-24 16:35 ` Junio C Hamano
  2016-09-07 11:19 ` [PATCH 0/3] fix checkout ambiguation in subdir Nguyễn Thái Ngọc Duy
  0 siblings, 2 replies; 12+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2016-08-22 12:35 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This should speed up "git checkout :/long/path/taken/from/diffstat"
because we don't have to walk through the commit graph to see if
"long/path/taken/from/diffstat" exists in any commit message.

This is in the the same spirit as 4db86e8 (Update :/abc ambiguity check
- 2013-01-21), but instead of considering this case ("abc" in ":/abc"
exists on worktree) ambiguous and shouting, we just assume the user
means "pathspec" not "ref".

It's not wonderful, but it's in line with how git-checkout stops caring
about ambiguity after the first argument can be resolved as a ref
(there's even a test for it, t2010.6). In other words, we assume the
user means "ref" not "pathspec" when that happens. Here we simply swap
the order of checking specifically for :/ on practical ground.

Last note, to be pedantic, we should check if "abc" from ":/abc" exists
as an _index_ entry, not on disk. But chances are they exist in both
places anyway...

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/checkout.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 8672d07..6f016db 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -973,6 +973,22 @@ static int parse_branchname_arg(int argc, const char **argv,
 	if (!strcmp(arg, "-"))
 		arg = "@{-1}";
 
+	if (dash_dash_pos < 0 && starts_with(arg, ":/") &&
+	    check_filename(opts->prefix, arg)) {
+		/*
+		 * Normally if the first argument is ambiguous, we
+		 * choose to believe the user specifies an extended
+		 * SHA-1 syntax unless it turns out not true, then we
+		 * see if it's a pathspec.
+		 *
+		 * :/ here is an exception because resolving :/abc may
+		 * involve walking through the entire commit
+		 * graph. Expensive and slow. If :/abc points to an
+		 * existing file, ignore ambiguity and go with
+		 * pathspec (i.e. skip get_sha1_mb()).
+		 */
+		return 0;	/* case (2) */
+	}
 	if (get_sha1_mb(arg, rev)) {
 		/*
 		 * Either case (3) or (4), with <something> not being
-- 
2.8.2.524.g6ff3d78


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-09-09 19:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 12:35 [PATCH] checkout: swap the order of ambiguity check for :/ syntax Nguyễn Thái Ngọc Duy
2016-08-24 16:35 ` Junio C Hamano
2016-08-25  9:21   ` Duy Nguyen
2016-08-25 17:19     ` Junio C Hamano
2016-08-26 13:34       ` Duy Nguyen
2016-09-07 11:19 ` [PATCH 0/3] fix checkout ambiguation in subdir Nguyễn Thái Ngọc Duy
2016-09-07 11:19   ` [PATCH 1/3] checkout: add some spaces between code and comment Nguyễn Thái Ngọc Duy
2016-09-07 11:19   ` [PATCH 2/3] checkout.txt: document a common case that ignores ambiguation rules Nguyễn Thái Ngọc Duy
2016-09-08 20:03     ` Junio C Hamano
2016-09-09 19:21       ` Junio C Hamano
2016-09-07 11:19   ` [PATCH 3/3] checkout: fix ambiguity check in subdir Nguyễn Thái Ngọc Duy
2016-09-08 20:04     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.