X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=convert-cache.c;h=8916a3692f89df0d96e8bbdf885f6b9eae6a1212;hb=dd53c7ab297cc491eb5164198e63d670c7b48530;hp=93e477ad3b26ab5bb32fe1b638d5ba77075c1d4b;hpb=54c26fb9d0cdff94c7717125d0a222b324bfea8a;p=git.git diff --git a/convert-cache.c b/convert-cache.c index 93e477ad..8916a369 100644 --- a/convert-cache.c +++ b/convert-cache.c @@ -60,11 +60,21 @@ static void convert_ascii_sha1(void *buffer) struct entry *entry; if (get_sha1_hex(buffer, sha1)) - die("bad sha1"); + die("expected sha1, got '%s'", buffer); entry = convert_entry(sha1); memcpy(buffer, sha1_to_hex(entry->new_sha1), 40); } +static unsigned int convert_mode(unsigned int mode) +{ + unsigned int newmode; + + newmode = mode & S_IFMT; + if (S_ISREG(mode)) + newmode |= (mode & 0100) ? 0755 : 0644; + return newmode; +} + static int write_subdirectory(void *buffer, unsigned long size, const char *base, int baselen, unsigned char *result_sha1) { char *new = xmalloc(size); @@ -81,6 +91,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base if (!path || sscanf(buffer, "%o", &mode) != 1) die("bad tree conversion"); + mode = convert_mode(mode); path++; if (memcmp(path, base, baselen)) break; @@ -260,6 +271,8 @@ static void convert_commit(void *buffer, unsigned long size, unsigned char *resu void *orig_buffer = buffer; unsigned long orig_size = size; + if (memcmp(buffer, "tree ", 5)) + die("Bad commit '%s'", buffer); convert_ascii_sha1(buffer+5); buffer += 46; /* "tree " + "hex sha1" + "\n" */ while (!memcmp(buffer, "parent ", 7)) { @@ -295,6 +308,7 @@ static struct entry * convert_entry(unsigned char *sha1) die("unknown object type '%s' in %s", type, sha1_to_hex(sha1)); entry->converted = 1; free(buffer); + free(data); return entry; } @@ -304,7 +318,7 @@ int main(int argc, char **argv) struct entry *entry; if (argc != 2 || get_sha1(argv[1], sha1)) - usage("convert-cache "); + usage("git-convert-cache "); entry = convert_entry(sha1); printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1));