X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=convert-objects.c;h=a67d6b479ec57816de1b259f9efed2258e999703;hb=ae448e3854d8b6e7e37aa88fa3917f5dd97f3210;hp=a892013f0f37480fbf13a9511f2146d1681ba136;hpb=e634aec752642dcf86c3fc82025e43381d6768c2;p=git.git diff --git a/convert-objects.c b/convert-objects.c index a892013f..a67d6b47 100644 --- a/convert-objects.c +++ b/convert-objects.c @@ -1,6 +1,10 @@ -#define _XOPEN_SOURCE /* glibc2 needs this */ +#define _XOPEN_SOURCE 500 /* glibc2 and AIX 5.3L need this */ +#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #include #include "cache.h" +#include "blob.h" +#include "commit.h" +#include "tree.h" struct entry { unsigned char old_sha1[20]; @@ -17,8 +21,7 @@ static struct entry * convert_entry(unsigned char *sha1); static struct entry *insert_new(unsigned char *sha1, int pos) { - struct entry *new = xmalloc(sizeof(struct entry)); - memset(new, 0, sizeof(*new)); + struct entry *new = xcalloc(1, sizeof(struct entry)); memcpy(new->old_sha1, sha1, 20); memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *)); convert[pos] = new; @@ -121,7 +124,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base buffer += len; } - write_sha1_file(new, newlen, "tree", result_sha1); + write_sha1_file(new, newlen, tree_type, result_sha1); free(new); return used; } @@ -261,8 +264,8 @@ static void convert_date(void *buffer, unsigned long size, unsigned char *result memcpy(new + newlen, buffer, size); newlen += size; - write_sha1_file(new, newlen, "commit", result_sha1); - free(new); + write_sha1_file(new, newlen, commit_type, result_sha1); + free(new); } static void convert_commit(void *buffer, unsigned long size, unsigned char *result_sha1) @@ -296,12 +299,12 @@ static struct entry * convert_entry(unsigned char *sha1) buffer = xmalloc(size); memcpy(buffer, data, size); - - if (!strcmp(type, "blob")) { - write_sha1_file(buffer, size, "blob", entry->new_sha1); - } else if (!strcmp(type, "tree")) + + if (!strcmp(type, blob_type)) { + write_sha1_file(buffer, size, blob_type, entry->new_sha1); + } else if (!strcmp(type, tree_type)) convert_tree(buffer, size, entry->new_sha1); - else if (!strcmp(type, "commit")) + else if (!strcmp(type, commit_type)) convert_commit(buffer, size, entry->new_sha1); else die("unknown object type '%s' in %s", type, sha1_to_hex(sha1)); @@ -316,8 +319,12 @@ int main(int argc, char **argv) unsigned char sha1[20]; struct entry *entry; - if (argc != 2 || get_sha1(argv[1], sha1)) + setup_git_directory(); + + if (argc != 2) usage("git-convert-objects "); + if (get_sha1(argv[1], sha1)) + die("Not a valid object name %s", argv[1]); entry = convert_entry(sha1); printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1));