X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=convert-cache.c;h=ee599f1c027fc829ab98a3ba489a5c4bfd7e9977;hb=9c2b1c0cd89d8cc8a3882e85c6b6535f282bf59f;hp=631d1aa910e7328c99642495f93908c749074f91;hpb=812666c8e66a21e668c0789d0422aa5a7db54961;p=git.git diff --git a/convert-cache.c b/convert-cache.c index 631d1aa9..ee599f1c 100644 --- a/convert-cache.c +++ b/convert-cache.c @@ -99,7 +99,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base continue; } - newlen += sprintf(new + newlen, "%o %.*s", S_IFDIR, slash - path, path); + newlen += sprintf(new + newlen, "%o %.*s", S_IFDIR, (int)(slash - path), path); new[newlen++] = 0; sha1 = (unsigned char *)(new + newlen); newlen += 20; @@ -116,6 +116,34 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base return used; } +static int convert_mode(char *buffer) +{ + char *end; + unsigned short mode = strtoul(buffer, &end, 8); + unsigned short newmode; + char num[10]; + int len; + + if (*end != ' ') + die("corrupt tree object"); + switch (mode) { + case S_IFREG | 0644: + case S_IFREG | 0755: + case S_IFLNK: + case S_IFDIR: + return 0; + } + newmode = 0; + if (S_ISREG(mode)) + newmode = (mode & 0100) ? 0755 : 0644; + newmode |= mode & S_IFMT; + len = sprintf(num, "%o", newmode); + if (len != end - buffer) + return error("unable to convert tree entry mode %o to %o", mode, newmode); + memcpy(buffer, num, len); + return 0; +} + static void convert_tree(void *buffer, unsigned long size, unsigned char *result_sha1) { void *orig_buffer = buffer; @@ -124,6 +152,7 @@ static void convert_tree(void *buffer, unsigned long size, unsigned char *result while (size) { int len = 1+strlen(buffer); + convert_mode(buffer); convert_binary_sha1(buffer + len); len += 20; @@ -303,8 +332,8 @@ int main(int argc, char **argv) unsigned char sha1[20]; struct entry *entry; - if (argc != 2 || get_sha1_hex(argv[1], sha1)) - usage("convert-cache "); + if (argc != 2 || get_sha1(argv[1], sha1)) + usage("git-convert-cache "); entry = convert_entry(sha1); printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1));