-#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 <time.h>
#include "cache.h"
+#include "blob.h"
+#include "commit.h"
+#include "tree.h"
struct entry {
unsigned char old_sha1[20];
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;
if (!slash) {
newlen += sprintf(new + newlen, "%o %s", mode, path);
new[newlen++] = '\0';
- memcpy(new + newlen, buffer + len - 20, 20);
+ memcpy(new + newlen, (char *) buffer + len - 20, 20);
newlen += 20;
used += len;
size -= len;
- buffer += len;
+ buffer = (char *) buffer + len;
continue;
}
used += len;
size -= len;
- buffer += len;
+ buffer = (char *) buffer + len;
}
- write_sha1_file(new, newlen, "tree", result_sha1);
+ write_sha1_file(new, newlen, tree_type, result_sha1);
free(new);
return used;
}
while (size) {
int len = 1+strlen(buffer);
- convert_binary_sha1(buffer + len);
+ convert_binary_sha1((char *) buffer + len);
len += 20;
if (len > size)
die("corrupt tree object");
size -= len;
- buffer += len;
+ buffer = (char *) buffer + len;
}
write_subdirectory(orig_buffer, orig_size, "", 0, result_sha1);
// "tree <sha1>\n"
memcpy(new + newlen, buffer, 46);
newlen += 46;
- buffer += 46;
+ buffer = (char *) buffer + 46;
size -= 46;
// "parent <sha1>\n"
while (!memcmp(buffer, "parent ", 7)) {
memcpy(new + newlen, buffer, 48);
newlen += 48;
- buffer += 48;
+ buffer = (char *) buffer + 48;
size -= 48;
}
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)
if (memcmp(buffer, "tree ", 5))
die("Bad commit '%s'", (char*) buffer);
- convert_ascii_sha1(buffer+5);
- buffer += 46; /* "tree " + "hex sha1" + "\n" */
+ convert_ascii_sha1((char *) buffer + 5);
+ buffer = (char *) buffer + 46; /* "tree " + "hex sha1" + "\n" */
while (!memcmp(buffer, "parent ", 7)) {
- convert_ascii_sha1(buffer+7);
- buffer += 48;
+ convert_ascii_sha1((char *) buffer + 7);
+ buffer = (char *) buffer + 48;
}
convert_date(orig_buffer, orig_size, result_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));
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 <sha1>");
+ 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));