Code

clean up pathspec matching
[git.git] / fast-import.c
index 3c035a57886329acf4d53a600af0a82ee55d514b..f0e08aca70c16e9309dde87954593a76ad37b9ef 100644 (file)
@@ -43,7 +43,7 @@ Format of STDIN stream:
 
   new_tag ::= 'tag' sp tag_str lf
     'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
-    'tagger' sp name '<' email '>' when lf
+    ('tagger' sp name '<' email '>' when lf)?
     tag_msg;
   tag_msg ::= data;
 
@@ -554,6 +554,10 @@ static void *pool_alloc(size_t len)
        struct mem_pool *p;
        void *r;
 
+       /* round up to a 'uintmax_t' alignment */
+       if (len & (sizeof(uintmax_t) - 1))
+               len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));
+
        for (p = mem_pool; p; p = p->next_pool)
                if ((p->end - p->next_free >= len))
                        break;
@@ -572,9 +576,6 @@ static void *pool_alloc(size_t len)
        }
 
        r = p->next_free;
-       /* round out to a 'uintmax_t' alignment */
-       if (len & (sizeof(uintmax_t) - 1))
-               len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));
        p->next_free += len;
        return r;
 }
@@ -982,8 +983,10 @@ static void end_packfile(void)
 
                pack_id++;
        }
-       else
+       else {
+               close(old_p->pack_fd);
                unlink(old_p->pack_name);
+       }
        free(old_p);
 
        /* We can't carry a delta across packfiles. */
@@ -1745,9 +1748,12 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
 {
        const char *orig_src = src;
        char *endp, sign;
+       unsigned long date;
+
+       errno = 0;
 
-       strtoul(src, &endp, 10);
-       if (endp == src || *endp != ' ')
+       date = strtoul(src, &endp, 10);
+       if (errno || endp == src || *endp != ' ')
                return -1;
 
        src = endp + 1;
@@ -1755,8 +1761,8 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
                return -1;
        sign = *src;
 
-       strtoul(src + 1, &endp, 10);
-       if (endp == src || *endp || (endp - orig_src) >= maxlen)
+       date = strtoul(src + 1, &endp, 10);
+       if (errno || endp == src || *endp || (endp - orig_src) >= maxlen)
                return -1;
 
        strcpy(result, orig_src);
@@ -1866,12 +1872,13 @@ static void file_change_m(struct branch *b)
        if (!p)
                die("Corrupt mode: %s", command_buf.buf);
        switch (mode) {
+       case 0644:
+       case 0755:
+               mode |= S_IFREG;
        case S_IFREG | 0644:
        case S_IFREG | 0755:
        case S_IFLNK:
        case S_IFGITLINK:
-       case 0644:
-       case 0755:
                /* ok */
                break;
        default:
@@ -1938,7 +1945,7 @@ static void file_change_m(struct branch *b)
                            typename(type), command_buf.buf);
        }
 
-       tree_content_set(&b->branch_tree, p, sha1, S_IFREG | mode, NULL);
+       tree_content_set(&b->branch_tree, p, sha1, mode, NULL);
 }
 
 static void file_change_d(struct branch *b)
@@ -2262,23 +2269,27 @@ static void parse_new_tag(void)
        read_next_command();
 
        /* tagger ... */
-       if (prefixcmp(command_buf.buf, "tagger "))
-               die("Expected tagger command, got %s", command_buf.buf);
-       tagger = parse_ident(command_buf.buf + 7);
+       if (!prefixcmp(command_buf.buf, "tagger ")) {
+               tagger = parse_ident(command_buf.buf + 7);
+               read_next_command();
+       } else
+               tagger = NULL;
 
        /* tag payload/message */
-       read_next_command();
        parse_data(&msg);
 
        /* build the tag object */
        strbuf_reset(&new_data);
+
        strbuf_addf(&new_data,
-               "object %s\n"
-               "type %s\n"
-               "tag %s\n"
-               "tagger %s\n"
-               "\n",
-               sha1_to_hex(sha1), commit_type, t->name, tagger);
+                   "object %s\n"
+                   "type %s\n"
+                   "tag %s\n",
+                   sha1_to_hex(sha1), commit_type, t->name);
+       if (tagger)
+               strbuf_addf(&new_data,
+                           "tagger %s\n", tagger);
+       strbuf_addch(&new_data, '\n');
        strbuf_addbuf(&new_data, &msg);
        free(tagger);