Code

gitweb: Fix support for legacy gitweb config for snapshots
[git.git] / mktree.c
index 9a6f0d2f6b0be1307985b4bd56d0bc84abd1df02..d86dde89d63e21994fd2538d5ac3a21ead3a7338 100644 (file)
--- a/mktree.c
+++ b/mktree.c
@@ -30,7 +30,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
        ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);
        ent->mode = mode;
        ent->len = len;
-       memcpy(ent->sha1, sha1, 20);
+       hashcpy(ent->sha1, sha1);
        memcpy(ent->name, path, len+1);
 }
 
@@ -49,7 +49,6 @@ static void write_tree(unsigned char *sha1)
        int i;
 
        qsort(entries, used, sizeof(*entries), ent_compare);
-       size = 100;
        for (size = i = 0; i < used; i++)
                size += 32 + entries[i]->len;
        buffer = xmalloc(size);
@@ -65,7 +64,7 @@ static void write_tree(unsigned char *sha1)
                offset += sprintf(buffer + offset, "%o ", ent->mode);
                offset += sprintf(buffer + offset, "%s", ent->name);
                buffer[offset++] = 0;
-               memcpy(buffer + offset, ent->sha1, 20);
+               hashcpy((unsigned char*)buffer + offset, ent->sha1);
                offset += 20;
        }
        write_sha1_file(buffer, offset, tree_type, sha1);
@@ -96,7 +95,7 @@ int main(int ac, char **av)
                int len;
                char *ptr, *ntr;
                unsigned mode;
-               char type[20];
+               enum object_type type;
                char *path;
 
                read_line(&sb, stdin, line_termination);
@@ -116,11 +115,12 @@ int main(int ac, char **av)
                    ntr[41] != '\t' ||
                    get_sha1_hex(ntr + 1, sha1))
                        die("input format error: %s", sb.buf);
-               if (sha1_object_info(sha1, type, NULL))
+               type = sha1_object_info(sha1, NULL);
+               if (type < 0)
                        die("object %s unavailable", sha1_to_hex(sha1));
                *ntr++ = 0; /* now at the beginning of SHA1 */
-               if (strcmp(ptr, type))
-                       die("object type %s mismatch (%s)", ptr, type);
+               if (type != type_from_string(ptr))
+                       die("object type %s mismatch (%s)", ptr, typename(type));
                ntr += 41; /* at the beginning of name */
                if (line_termination && ntr[0] == '"')
                        path = unquote_c_style(ntr, NULL);