Re: [PATCH 3/3] get_sha1: support ref^{/regex} syntax

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 3/3] get_sha1: support ref^{/regex} syntax

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:15

Nguyen Thai Ngoc Duy [off-list ref] writes:
Perhaps we should just reject this case. No sane body would ever use it.
I'd have to say that dismissing before even trying is not a very
disciplined attitude.

Shouldn't an empty regexp simply match everything?  Even on FBSD8,

    $ grep '' /etc/passwd

seems to show everything.  How hard would it be to do this in the codepath
we are discussing?

Re: [PATCH 3/3] get_sha1: support ref^{/regex} syntax

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:50:15

On Wed, Dec 15, 2010 at 9:56 AM, Junio C Hamano [off-list ref] wrote:
Nguyen Thai Ngoc Duy [off-list ref] writes:
quoted
Perhaps we should just reject this case. No sane body would ever use it.
I'd have to say that dismissing before even trying is not a very
disciplined attitude.

Shouldn't an empty regexp simply match everything?  Even on FBSD8,

   $ grep '' /etc/passwd

seems to show everything.  How hard would it be to do this in the codepath
we are discussing?
To make '' match everything is easy. I'll cook up something when I get home.
-- 
Duy

[PATCH] get_sha1: handle special case $commit^{/}

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:50:15

Empty regex pattern should always match. But the exact behavior of
regexec() may vary. Because it always matches anyway, we can just
return 'matched' without calling regex machinery.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 On top of nd/oneline-sha1-name-from-specific-ref

 sha1_name.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 1ba4bc3..c5c59ce 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -599,6 +599,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
 		int ret;
 		struct commit_list *list = NULL;
 
+		/*
+		 * $commit^{/}. Some regex implementation may reject.
+		 * We don't need regex anyway. '' pattern always matches.
+		 */
+		if (sp[1] == '}')
+			return 0;
+
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
 		ret = get_sha1_oneline(prefix, sha1, list);
-- 
1.7.3.3.476.g10a82
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help