Thread (21 messages) flat view 21 messages, 6 authors, 2016-06-15

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

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

Nguyễn Thái Ngọc Duy [off-list ref] writes:
quoted hunk ↗ jump to hunk
diff --git a/sha1_name.c b/sha1_name.c
index f4ccdc5..00e52b0 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -562,6 +563,11 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
 		expected_type = OBJ_BLOB;
 	else if (sp[0] == '}')
 		expected_type = OBJ_NONE;
+	else if (sp[0] == '/') {
+		if (sp[1] == '}')
+			return -1;
Why?  $commit^{/} may be a no-op but I do not see a strong reason to
waste extra two lines to forbid it.
quoted hunk ↗ jump to hunk
@@ -584,11 +590,23 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
 		 * barf.
 		 */
 		o = peel_to_type(name, len, o, expected_type);
-		if (o) {
-			hashcpy(sha1, o->sha1);
-			return 0;
+		if (!o)
+			return -1;
I can see you are trying to reduce nesting of

        if (o) {
		do true thing
                return 0
	}
        return -1;

but then we should apply the same to outer "if (!expected_type) ... else",
too, to unnest the "else" clause by returning from the true branch of that
"if".
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help