Re: [PATCH v2 8/9] sha1_name: simplify track finding

2014-04-10 Thread Felipe Contreras
Ramkumar Ramachandra wrote:
> Felipe Contreras wrote:
> > It's more efficient to check for the braces first.
> 
> Why is it more efficient? So you can error out quickly in the case of
> a malformed string?

That's one reason. The other is that get_sha1_basic() calls upstream_mark()
when we _already_ know there's a @{foo}.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 8/9] sha1_name: simplify track finding

2014-04-10 Thread Ramkumar Ramachandra
Felipe Contreras wrote:
> It's more efficient to check for the braces first.

Why is it more efficient? So you can error out quickly in the case of
a malformed string? I'm personally not thrilled about this change.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 8/9] sha1_name: simplify track finding

2014-04-10 Thread Felipe Contreras
It's more efficient to check for the braces first.

Signed-off-by: Felipe Contreras 
---
 sha1_name.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 906f09d..aa3f3e0 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -417,7 +417,7 @@ static int ambiguous_path(const char *path, int len)
 
 static inline int upstream_mark(const char *string, int len)
 {
-   const char *suffix[] = { "@{upstream}", "@{u}" };
+   const char *suffix[] = { "upstream", "u" };
int i;
 
for (i = 0; i < ARRAY_SIZE(suffix); i++) {
@@ -475,7 +475,7 @@ static int get_sha1_basic(const char *str, int len, 
unsigned char *sha1)
nth_prior = 1;
continue;
}
-   if (!upstream_mark(str + at, len - at)) {
+   if (!upstream_mark(str + at + 2, len - at - 3)) 
{
reflog_len = (len-1) - (at+2);
len = at;
}
@@ -1089,7 +1089,10 @@ static int interpret_upstream_mark(const char *name, int 
namelen,
 {
int len;
 
-   len = upstream_mark(name + at, namelen - at);
+   if (name[at + 1] != '{' || name[namelen - 1] != '}')
+   return -1;
+
+   len = upstream_mark(name + at + 2, namelen - at - 3);
if (!len)
return -1;
 
@@ -1097,7 +1100,7 @@ static int interpret_upstream_mark(const char *name, int 
namelen,
return -1;
 
set_shortened_ref(buf, get_upstream_branch(name, at));
-   return len + at;
+   return len + at + 3;
 }
 
 /*
-- 
1.9.1+fc1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html