Simplify detection of tag commits via ^{}
authorJonas Fonseca <fonseca@diku.dk>
Thu, 1 Jun 2006 02:08:44 +0000 (04:08 +0200)
committerJonas Fonseca <fonseca@antimatter.localdomain>
Thu, 1 Jun 2006 02:08:44 +0000 (04:08 +0200)
tig.c

diff --git a/tig.c b/tig.c
index 4e1ffcb..f541697 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2420,25 +2420,22 @@ read_ref(char *id, int idlen, char *name, int namelen)
 {
        struct ref *ref;
        bool tag = FALSE;
-       bool tag_commit = FALSE;
 
-       /* Commits referenced by tags has "^{}" appended. */
-       if (name[namelen - 1] == '}') {
+       if (!strncmp(name, "refs/tags/", STRING_SIZE("refs/tags/"))) {
+               /* Commits referenced by tags has "^{}" appended. */
+               if (name[namelen - 1] != '}')
+                       return OK;
+
                while (namelen > 0 && name[namelen] != '^')
                        namelen--;
-               if (namelen > 0)
-                       tag_commit = TRUE;
-               name[namelen] = 0;
-       }
 
-       if (!strncmp(name, "refs/tags/", STRING_SIZE("refs/tags/"))) {
-               if (!tag_commit)
-                       return OK;
-               name += STRING_SIZE("refs/tags/");
                tag = TRUE;
+               namelen -= STRING_SIZE("refs/tags/");
+               name    += STRING_SIZE("refs/tags/");
 
        } else if (!strncmp(name, "refs/heads/", STRING_SIZE("refs/heads/"))) {
-               name += STRING_SIZE("refs/heads/");
+               namelen -= STRING_SIZE("refs/heads/");
+               name    += STRING_SIZE("refs/heads/");
 
        } else if (!strcmp(name, "HEAD")) {
                return OK;
@@ -2449,10 +2446,12 @@ read_ref(char *id, int idlen, char *name, int namelen)
                return ERR;
 
        ref = &refs[refs_size++];
-       ref->name = strdup(name);
+       ref->name = malloc(namelen + 1);
        if (!ref->name)
                return ERR;
 
+       strncpy(ref->name, name, namelen);
+       ref->name[namelen] = 0;
        ref->tag = tag;
        string_copy(ref->id, id);