* [PATCH 1/2] Update :/abc ambiguity check
@ 2013-01-21 13:00 Nguyễn Thái Ngọc Duy
2013-01-21 13:00 ` [PATCH 2/2] grep: avoid accepting ambiguous revision Nguyễn Thái Ngọc Duy
2013-01-21 19:27 ` [PATCH 1/2] Update :/abc ambiguity check Junio C Hamano
0 siblings, 2 replies; 5+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2013-01-21 13:00 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
:/abc may mean two things:
- as a revision, it means the revision that has "abc" in commit
message.
- as a pathpec, it means "abc" from root.
Currently we see ":/abc" as a rev (most of the time), but never see it
as a pathspec even if "abc" exists and "git log :/abc" will gladly
take ":/abc" as rev even it's ambiguous. This patch makes it:
- ambiguous when "abc" exists on worktree
- a rev if abc does not exist on worktree
- a path if abc is not found in any commits (although better use
"--" to avoid ambiguation because searching through commit DAG is
expensive)
A plus from this patch is, because ":/" never matches anything as a
rev, it is never considered a valid rev and because root directory
always exists, ":/" is always unambiguously seen as a pathspec.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
This makes "git grep foo :/" work. For such an often used command,
the less I type the better.
The ".. is expensive" thing is not cool. But it hopefully does not
happen often. I expect people rely on shell's tab completion more
than :/typing-path-to-somewhere-manually. Copy/paste happens more
often. I usually type ":" then copy a path from diff --git line.
We should probably kill ":/abc as a rev" and replace it with @{/abc}
or something less ambiguous.
setup.c | 9 ++++++++-
t/t4208-log-magic-pathspec.sh | 17 +++++++++++++++--
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/setup.c b/setup.c
index f108c4b..47acc11 100644
--- a/setup.c
+++ b/setup.c
@@ -66,7 +66,14 @@ int check_filename(const char *prefix, const char *arg)
const char *name;
struct stat st;
- name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
+ if (!prefixcmp(arg, ":/")) {
+ if (arg[2] == '\0') /* ":/" is root dir, always exists */
+ return 1;
+ name = arg + 2;
+ } else if (prefix)
+ name = prefix_filename(prefix, strlen(prefix), arg);
+ else
+ name = arg;
if (!lstat(name, &st))
return 1; /* file exists */
if (errno == ENOENT || errno == ENOTDIR)
diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh
index 2c482b6..72300b5 100755
--- a/t/t4208-log-magic-pathspec.sh
+++ b/t/t4208-log-magic-pathspec.sh
@@ -11,11 +11,24 @@ test_expect_success 'setup' '
mkdir sub
'
-test_expect_success '"git log :/" should be ambiguous' '
- test_must_fail git log :/ 2>error &&
+test_expect_success '"git log :/" should not be ambiguous' '
+ git log :/
+'
+
+test_expect_success '"git log :/a" should be ambiguous (applied both rev and worktree)' '
+ : >a &&
+ test_must_fail git log :/a 2>error &&
grep ambiguous error
'
+test_expect_success '"git log :/a -- " should not be ambiguous' '
+ git log :/a --
+'
+
+test_expect_success '"git log -- :/a" should not be ambiguous' '
+ git log -- :/a
+'
+
test_expect_success '"git log :" should be ambiguous' '
test_must_fail git log : 2>error &&
grep ambiguous error
--
1.8.0.rc2.23.g1fb49df
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] grep: avoid accepting ambiguous revision
2013-01-21 13:00 [PATCH 1/2] Update :/abc ambiguity check Nguyễn Thái Ngọc Duy
@ 2013-01-21 13:00 ` Nguyễn Thái Ngọc Duy
2013-01-21 19:27 ` [PATCH 1/2] Update :/abc ambiguity check Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2013-01-21 13:00 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/grep.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/builtin/grep.c b/builtin/grep.c
index 0e1b6c8..8025964 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -823,6 +823,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
struct object *object = parse_object(sha1);
if (!object)
die(_("bad object %s"), arg);
+ if (!seen_dashdash)
+ verify_non_filename(prefix, arg);
add_object_array(object, arg, &list);
continue;
}
--
1.8.0.rc2.23.g1fb49df
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] Update :/abc ambiguity check
2013-01-21 13:00 [PATCH 1/2] Update :/abc ambiguity check Nguyễn Thái Ngọc Duy
2013-01-21 13:00 ` [PATCH 2/2] grep: avoid accepting ambiguous revision Nguyễn Thái Ngọc Duy
@ 2013-01-21 19:27 ` Junio C Hamano
2013-01-22 2:46 ` Duy Nguyen
1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2013-01-21 19:27 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> :/abc may mean two things:
>
> - as a revision, it means the revision that has "abc" in commit
> message.
>
> - as a pathpec, it means "abc" from root.
>
> Currently we see ":/abc" as a rev (most of the time), but never see it
> as a pathspec even if "abc" exists and "git log :/abc" will gladly
> take ":/abc" as rev even it's ambiguous. This patch makes it:
>
> - ambiguous when "abc" exists on worktree
> - a rev if abc does not exist on worktree
> - a path if abc is not found in any commits (although better use
The "any commits" above sounds very scary. Are you really going to
check against all the commits?
> "--" to avoid ambiguation because searching through commit DAG is
> expensive)
>
> A plus from this patch is, because ":/" never matches anything as a
> rev, it is never considered a valid rev and because root directory
> always exists, ":/" is always unambiguously seen as a pathspec.
That is the primary plus in practice, I think, and it is a big one.
When naming a directory that belongs to a different subdirectory
hierarchy, typing ":/that/directory/name" is not any easier than
having your shell help you complete "../../that/directory/name"; I
suspect nobody uses the relative-to-root notation to name anything
but the root in real life.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] Update :/abc ambiguity check
2013-01-21 19:27 ` [PATCH 1/2] Update :/abc ambiguity check Junio C Hamano
@ 2013-01-22 2:46 ` Duy Nguyen
2013-01-22 4:10 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Duy Nguyen @ 2013-01-22 2:46 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Tue, Jan 22, 2013 at 2:27 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>
>> :/abc may mean two things:
>>
>> - as a revision, it means the revision that has "abc" in commit
>> message.
>>
>> - as a pathpec, it means "abc" from root.
>>
>> Currently we see ":/abc" as a rev (most of the time), but never see it
>> as a pathspec even if "abc" exists and "git log :/abc" will gladly
>> take ":/abc" as rev even it's ambiguous. This patch makes it:
>>
>> - ambiguous when "abc" exists on worktree
>> - a rev if abc does not exist on worktree
>> - a path if abc is not found in any commits (although better use
>
> The "any commits" above sounds very scary. Are you really going to
> check against all the commits?
If I remember correctly :/ will search through commit chains until it
finds a commit that matches. So :/non-existent-string definitely
searches through all commits.
>> "--" to avoid ambiguation because searching through commit DAG is
>> expensive)
>>
>> A plus from this patch is, because ":/" never matches anything as a
>> rev, it is never considered a valid rev and because root directory
>> always exists, ":/" is always unambiguously seen as a pathspec.
>
> That is the primary plus in practice, I think, and it is a big one.
>
> When naming a directory that belongs to a different subdirectory
> hierarchy, typing ":/that/directory/name" is not any easier than
> having your shell help you complete "../../that/directory/name"; I
> suspect nobody uses the relative-to-root notation to name anything
> but the root in real life.
As I noted in the patch comment, I do copy/paste repo-absolute paths
from a diff quite often (just skip the "a" and "b" prefix). Sometimes
I hope "git diff" has an option to produce relative paths..
--
Duy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] Update :/abc ambiguity check
2013-01-22 2:46 ` Duy Nguyen
@ 2013-01-22 4:10 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2013-01-22 4:10 UTC (permalink / raw)
To: Duy Nguyen; +Cc: git
Duy Nguyen <pclouds@gmail.com> writes:
>>> ... take ":/abc" as rev even it's ambiguous. This patch makes it:
>>>
>>> - ambiguous when "abc" exists on worktree
>>> - a rev if abc does not exist on worktree
>>> - a path if abc is not found in any commits (although better use
>>
>> The "any commits" above sounds very scary. Are you really going to
>> check against all the commits?
>
> If I remember correctly :/ will search through commit chains until it
> finds a commit that matches. So :/non-existent-string definitely
> searches through all commits.
That is the real work the user asked us to do, so it is not a wasted
latency. The description looked as if you were doing extra work
only for disambiguation, which triggered my "Huh?" meter.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-01-22 4:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-21 13:00 [PATCH 1/2] Update :/abc ambiguity check Nguyễn Thái Ngọc Duy
2013-01-21 13:00 ` [PATCH 2/2] grep: avoid accepting ambiguous revision Nguyễn Thái Ngọc Duy
2013-01-21 19:27 ` [PATCH 1/2] Update :/abc ambiguity check Junio C Hamano
2013-01-22 2:46 ` Duy Nguyen
2013-01-22 4:10 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).