{"thread":{"id":"10002","subject":"[PATCH] Move convert-objects to contrib.","startedAt":"2007-09-25T03:14:21Z","lastAt":"2007-09-25T14:06:38Z","messageCount":4,"participants":["Matt Kraai","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"53957","messageId":"1190690061-6720-1-git-send-email-kraai@ftbfs.org","threadId":"10002","inReplyTo":null,"subject":"[PATCH] Move convert-objects to contrib.","fromName":"Matt Kraai","fromEmail":"kraai@ftbfs.org","sentAt":"2007-09-25T03:14:21Z","receivedAt":"2007-09-25T03:14:21Z","isPatch":true,"sender":{"key":"kraai@ftbfs.org","avatar":null},"body":"\nSigned-off-by: Matt Kraai <kraai@ftbfs.org>\n---\n .gitignore                                      |    1 -\n Documentation/cmd-list.perl                     |    1 -\n Documentation/git-convert-objects.txt           |   28 --\n Makefile                                        |    2 +-\n contrib/completion/git-completion.bash          |    1 -\n contrib/convert-objects/convert-objects.c       |  329 +++++++++++++++++++++++\n contrib/convert-objects/git-convert-objects.txt |   28 ++\n convert-objects.c                               |  329 -----------------------\n 8 files changed, 358 insertions(+), 361 deletions(-)\n delete mode 100644 Documentation/git-convert-objects.txt\n create mode 100644 contrib/convert-objects/convert-objects.c\n create mode 100644 contrib/convert-objects/git-convert-objects.txt\n delete mode 100644 convert-objects.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 63c918c..e0b91be 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -25,7 +25,6 @@ git-clone\n git-commit\n git-commit-tree\n git-config\n-git-convert-objects\n git-count-objects\n git-cvsexportcommit\n git-cvsimport\ndiff --git a/Documentation/cmd-list.perl b/Documentation/cmd-list.perl\nindex 4ee76ea..1061fd8 100755\n--- a/Documentation/cmd-list.perl\n+++ b/Documentation/cmd-list.perl\n@@ -94,7 +94,6 @@ git-clone                               mainporcelain\n git-commit                              mainporcelain\n git-commit-tree                         plumbingmanipulators\n git-config                              ancillarymanipulators\n-git-convert-objects                     ancillarymanipulators\n git-count-objects                       ancillaryinterrogators\n git-cvsexportcommit                     foreignscminterface\n git-cvsimport                           foreignscminterface\ndiff --git a/Documentation/git-convert-objects.txt b/Documentation/git-convert-objects.txt\ndeleted file mode 100644\nindex 9718abf..0000000\n--- a/Documentation/git-convert-objects.txt\n+++ /dev/null\n@@ -1,28 +0,0 @@\n-git-convert-objects(1)\n-======================\n-\n-NAME\n-----\n-git-convert-objects - Converts old-style git repository\n-\n-\n-SYNOPSIS\n---------\n-'git-convert-objects'\n-\n-DESCRIPTION\n------------\n-Converts old-style git repository to the latest format\n-\n-\n-Author\n-------\n-Written by Linus Torvalds <torvalds@osdl.org>\n-\n-Documentation\n---------------\n-Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.\n-\n-GIT\n----\n-Part of the gitlink:git[7] suite\ndiff --git a/Makefile b/Makefile\nindex 0055eef..94b16d0 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -233,7 +233,7 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \\\n \n # ... and all the rest that could be moved out of bindir to gitexecdir\n PROGRAMS = \\\n-\tgit-convert-objects$X git-fetch-pack$X \\\n+\tgit-fetch-pack$X \\\n \tgit-hash-object$X git-index-pack$X git-local-fetch$X \\\n \tgit-fast-import$X \\\n \tgit-daemon$X \\\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex cad842a..e760930 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -299,7 +299,6 @@ __git_commands ()\n \t\tcheck-attr)       : plumbing;;\n \t\tcheck-ref-format) : plumbing;;\n \t\tcommit-tree)      : plumbing;;\n-\t\tconvert-objects)  : plumbing;;\n \t\tcvsexportcommit)  : export;;\n \t\tcvsimport)        : import;;\n \t\tcvsserver)        : daemon;;\ndiff --git a/contrib/convert-objects/convert-objects.c b/contrib/convert-objects/convert-objects.c\nnew file mode 100644\nindex 0000000..90e7900\n--- /dev/null\n+++ b/contrib/convert-objects/convert-objects.c\n@@ -0,0 +1,329 @@\n+#include \"cache.h\"\n+#include \"blob.h\"\n+#include \"commit.h\"\n+#include \"tree.h\"\n+\n+struct entry {\n+\tunsigned char old_sha1[20];\n+\tunsigned char new_sha1[20];\n+\tint converted;\n+};\n+\n+#define MAXOBJECTS (1000000)\n+\n+static struct entry *convert[MAXOBJECTS];\n+static int nr_convert;\n+\n+static struct entry * convert_entry(unsigned char *sha1);\n+\n+static struct entry *insert_new(unsigned char *sha1, int pos)\n+{\n+\tstruct entry *new = xcalloc(1, sizeof(struct entry));\n+\thashcpy(new->old_sha1, sha1);\n+\tmemmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));\n+\tconvert[pos] = new;\n+\tnr_convert++;\n+\tif (nr_convert == MAXOBJECTS)\n+\t\tdie(\"you're kidding me - hit maximum object limit\");\n+\treturn new;\n+}\n+\n+static struct entry *lookup_entry(unsigned char *sha1)\n+{\n+\tint low = 0, high = nr_convert;\n+\n+\twhile (low < high) {\n+\t\tint next = (low + high) / 2;\n+\t\tstruct entry *n = convert[next];\n+\t\tint cmp = hashcmp(sha1, n->old_sha1);\n+\t\tif (!cmp)\n+\t\t\treturn n;\n+\t\tif (cmp < 0) {\n+\t\t\thigh = next;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tlow = next+1;\n+\t}\n+\treturn insert_new(sha1, low);\n+}\n+\n+static void convert_binary_sha1(void *buffer)\n+{\n+\tstruct entry *entry = convert_entry(buffer);\n+\thashcpy(buffer, entry->new_sha1);\n+}\n+\n+static void convert_ascii_sha1(void *buffer)\n+{\n+\tunsigned char sha1[20];\n+\tstruct entry *entry;\n+\n+\tif (get_sha1_hex(buffer, sha1))\n+\t\tdie(\"expected sha1, got '%s'\", (char*) buffer);\n+\tentry = convert_entry(sha1);\n+\tmemcpy(buffer, sha1_to_hex(entry->new_sha1), 40);\n+}\n+\n+static unsigned int convert_mode(unsigned int mode)\n+{\n+\tunsigned int newmode;\n+\n+\tnewmode = mode & S_IFMT;\n+\tif (S_ISREG(mode))\n+\t\tnewmode |= (mode & 0100) ? 0755 : 0644;\n+\treturn newmode;\n+}\n+\n+static int write_subdirectory(void *buffer, unsigned long size, const char *base, int baselen, unsigned char *result_sha1)\n+{\n+\tchar *new = xmalloc(size);\n+\tunsigned long newlen = 0;\n+\tunsigned long used;\n+\n+\tused = 0;\n+\twhile (size) {\n+\t\tint len = 21 + strlen(buffer);\n+\t\tchar *path = strchr(buffer, ' ');\n+\t\tunsigned char *sha1;\n+\t\tunsigned int mode;\n+\t\tchar *slash, *origpath;\n+\n+\t\tif (!path || strtoul_ui(buffer, 8, &mode))\n+\t\t\tdie(\"bad tree conversion\");\n+\t\tmode = convert_mode(mode);\n+\t\tpath++;\n+\t\tif (memcmp(path, base, baselen))\n+\t\t\tbreak;\n+\t\torigpath = path;\n+\t\tpath += baselen;\n+\t\tslash = strchr(path, '/');\n+\t\tif (!slash) {\n+\t\t\tnewlen += sprintf(new + newlen, \"%o %s\", mode, path);\n+\t\t\tnew[newlen++] = '\\0';\n+\t\t\thashcpy((unsigned char*)new + newlen, (unsigned char *) buffer + len - 20);\n+\t\t\tnewlen += 20;\n+\n+\t\t\tused += len;\n+\t\t\tsize -= len;\n+\t\t\tbuffer = (char *) buffer + len;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tnewlen += sprintf(new + newlen, \"%o %.*s\", S_IFDIR, (int)(slash - path), path);\n+\t\tnew[newlen++] = 0;\n+\t\tsha1 = (unsigned char *)(new + newlen);\n+\t\tnewlen += 20;\n+\n+\t\tlen = write_subdirectory(buffer, size, origpath, slash-origpath+1, sha1);\n+\n+\t\tused += len;\n+\t\tsize -= len;\n+\t\tbuffer = (char *) buffer + len;\n+\t}\n+\n+\twrite_sha1_file(new, newlen, tree_type, result_sha1);\n+\tfree(new);\n+\treturn used;\n+}\n+\n+static void convert_tree(void *buffer, unsigned long size, unsigned char *result_sha1)\n+{\n+\tvoid *orig_buffer = buffer;\n+\tunsigned long orig_size = size;\n+\n+\twhile (size) {\n+\t\tsize_t len = 1+strlen(buffer);\n+\n+\t\tconvert_binary_sha1((char *) buffer + len);\n+\n+\t\tlen += 20;\n+\t\tif (len > size)\n+\t\t\tdie(\"corrupt tree object\");\n+\t\tsize -= len;\n+\t\tbuffer = (char *) buffer + len;\n+\t}\n+\n+\twrite_subdirectory(orig_buffer, orig_size, \"\", 0, result_sha1);\n+}\n+\n+static unsigned long parse_oldstyle_date(const char *buf)\n+{\n+\tchar c, *p;\n+\tchar buffer[100];\n+\tstruct tm tm;\n+\tconst char *formats[] = {\n+\t\t\"%c\",\n+\t\t\"%a %b %d %T\",\n+\t\t\"%Z\",\n+\t\t\"%Y\",\n+\t\t\" %Y\",\n+\t\tNULL\n+\t};\n+\t/* We only ever did two timezones in the bad old format .. */\n+\tconst char *timezones[] = {\n+\t\t\"PDT\", \"PST\", \"CEST\", NULL\n+\t};\n+\tconst char **fmt = formats;\n+\n+\tp = buffer;\n+\twhile (isspace(c = *buf))\n+\t\tbuf++;\n+\twhile ((c = *buf++) != '\\n')\n+\t\t*p++ = c;\n+\t*p++ = 0;\n+\tbuf = buffer;\n+\tmemset(&tm, 0, sizeof(tm));\n+\tdo {\n+\t\tconst char *next = strptime(buf, *fmt, &tm);\n+\t\tif (next) {\n+\t\t\tif (!*next)\n+\t\t\t\treturn mktime(&tm);\n+\t\t\tbuf = next;\n+\t\t} else {\n+\t\t\tconst char **p = timezones;\n+\t\t\twhile (isspace(*buf))\n+\t\t\t\tbuf++;\n+\t\t\twhile (*p) {\n+\t\t\t\tif (!memcmp(buf, *p, strlen(*p))) {\n+\t\t\t\t\tbuf += strlen(*p);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t\tp++;\n+\t\t\t}\n+\t\t}\n+\t\tfmt++;\n+\t} while (*buf && *fmt);\n+\tprintf(\"left: %s\\n\", buf);\n+\treturn mktime(&tm);\n+}\n+\n+static int convert_date_line(char *dst, void **buf, unsigned long *sp)\n+{\n+\tunsigned long size = *sp;\n+\tchar *line = *buf;\n+\tchar *next = strchr(line, '\\n');\n+\tchar *date = strchr(line, '>');\n+\tint len;\n+\n+\tif (!next || !date)\n+\t\tdie(\"missing or bad author/committer line %s\", line);\n+\tnext++; date += 2;\n+\n+\t*buf = next;\n+\t*sp = size - (next - line);\n+\n+\tlen = date - line;\n+\tmemcpy(dst, line, len);\n+\tdst += len;\n+\n+\t/* Is it already in new format? */\n+\tif (isdigit(*date)) {\n+\t\tint datelen = next - date;\n+\t\tmemcpy(dst, date, datelen);\n+\t\treturn len + datelen;\n+\t}\n+\n+\t/*\n+\t * Hacky hacky: one of the sparse old-style commits does not have\n+\t * any date at all, but we can fake it by using the committer date.\n+\t */\n+\tif (*date == '\\n' && strchr(next, '>'))\n+\t\tdate = strchr(next, '>')+2;\n+\n+\treturn len + sprintf(dst, \"%lu -0700\\n\", parse_oldstyle_date(date));\n+}\n+\n+static void convert_date(void *buffer, unsigned long size, unsigned char *result_sha1)\n+{\n+\tchar *new = xmalloc(size + 100);\n+\tunsigned long newlen = 0;\n+\n+\t/* \"tree <sha1>\\n\" */\n+\tmemcpy(new + newlen, buffer, 46);\n+\tnewlen += 46;\n+\tbuffer = (char *) buffer + 46;\n+\tsize -= 46;\n+\n+\t/* \"parent <sha1>\\n\" */\n+\twhile (!memcmp(buffer, \"parent \", 7)) {\n+\t\tmemcpy(new + newlen, buffer, 48);\n+\t\tnewlen += 48;\n+\t\tbuffer = (char *) buffer + 48;\n+\t\tsize -= 48;\n+\t}\n+\n+\t/* \"author xyz <xyz> date\" */\n+\tnewlen += convert_date_line(new + newlen, &buffer, &size);\n+\t/* \"committer xyz <xyz> date\" */\n+\tnewlen += convert_date_line(new + newlen, &buffer, &size);\n+\n+\t/* Rest */\n+\tmemcpy(new + newlen, buffer, size);\n+\tnewlen += size;\n+\n+\twrite_sha1_file(new, newlen, commit_type, result_sha1);\n+\tfree(new);\n+}\n+\n+static void convert_commit(void *buffer, unsigned long size, unsigned char *result_sha1)\n+{\n+\tvoid *orig_buffer = buffer;\n+\tunsigned long orig_size = size;\n+\n+\tif (memcmp(buffer, \"tree \", 5))\n+\t\tdie(\"Bad commit '%s'\", (char*) buffer);\n+\tconvert_ascii_sha1((char *) buffer + 5);\n+\tbuffer = (char *) buffer + 46;    /* \"tree \" + \"hex sha1\" + \"\\n\" */\n+\twhile (!memcmp(buffer, \"parent \", 7)) {\n+\t\tconvert_ascii_sha1((char *) buffer + 7);\n+\t\tbuffer = (char *) buffer + 48;\n+\t}\n+\tconvert_date(orig_buffer, orig_size, result_sha1);\n+}\n+\n+static struct entry * convert_entry(unsigned char *sha1)\n+{\n+\tstruct entry *entry = lookup_entry(sha1);\n+\tenum object_type type;\n+\tvoid *buffer, *data;\n+\tunsigned long size;\n+\n+\tif (entry->converted)\n+\t\treturn entry;\n+\tdata = read_sha1_file(sha1, &type, &size);\n+\tif (!data)\n+\t\tdie(\"unable to read object %s\", sha1_to_hex(sha1));\n+\n+\tbuffer = xmalloc(size);\n+\tmemcpy(buffer, data, size);\n+\n+\tif (type == OBJ_BLOB) {\n+\t\twrite_sha1_file(buffer, size, blob_type, entry->new_sha1);\n+\t} else if (type == OBJ_TREE)\n+\t\tconvert_tree(buffer, size, entry->new_sha1);\n+\telse if (type == OBJ_COMMIT)\n+\t\tconvert_commit(buffer, size, entry->new_sha1);\n+\telse\n+\t\tdie(\"unknown object type %d in %s\", type, sha1_to_hex(sha1));\n+\tentry->converted = 1;\n+\tfree(buffer);\n+\tfree(data);\n+\treturn entry;\n+}\n+\n+int main(int argc, char **argv)\n+{\n+\tunsigned char sha1[20];\n+\tstruct entry *entry;\n+\n+\tsetup_git_directory();\n+\n+\tif (argc != 2)\n+\t\tusage(\"git-convert-objects <sha1>\");\n+\tif (get_sha1(argv[1], sha1))\n+\t\tdie(\"Not a valid object name %s\", argv[1]);\n+\n+\tentry = convert_entry(sha1);\n+\tprintf(\"new sha1: %s\\n\", sha1_to_hex(entry->new_sha1));\n+\treturn 0;\n+}\ndiff --git a/contrib/convert-objects/git-convert-objects.txt b/contrib/convert-objects/git-convert-objects.txt\nnew file mode 100644\nindex 0000000..9718abf\n--- /dev/null\n+++ b/contrib/convert-objects/git-convert-objects.txt\n@@ -0,0 +1,28 @@\n+git-convert-objects(1)\n+======================\n+\n+NAME\n+----\n+git-convert-objects - Converts old-style git repository\n+\n+\n+SYNOPSIS\n+--------\n+'git-convert-objects'\n+\n+DESCRIPTION\n+-----------\n+Converts old-style git repository to the latest format\n+\n+\n+Author\n+------\n+Written by Linus Torvalds <torvalds@osdl.org>\n+\n+Documentation\n+--------------\n+Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.\n+\n+GIT\n+---\n+Part of the gitlink:git[7] suite\ndiff --git a/convert-objects.c b/convert-objects.c\ndeleted file mode 100644\nindex 90e7900..0000000\n--- a/convert-objects.c\n+++ /dev/null\n@@ -1,329 +0,0 @@\n-#include \"cache.h\"\n-#include \"blob.h\"\n-#include \"commit.h\"\n-#include \"tree.h\"\n-\n-struct entry {\n-\tunsigned char old_sha1[20];\n-\tunsigned char new_sha1[20];\n-\tint converted;\n-};\n-\n-#define MAXOBJECTS (1000000)\n-\n-static struct entry *convert[MAXOBJECTS];\n-static int nr_convert;\n-\n-static struct entry * convert_entry(unsigned char *sha1);\n-\n-static struct entry *insert_new(unsigned char *sha1, int pos)\n-{\n-\tstruct entry *new = xcalloc(1, sizeof(struct entry));\n-\thashcpy(new->old_sha1, sha1);\n-\tmemmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));\n-\tconvert[pos] = new;\n-\tnr_convert++;\n-\tif (nr_convert == MAXOBJECTS)\n-\t\tdie(\"you're kidding me - hit maximum object limit\");\n-\treturn new;\n-}\n-\n-static struct entry *lookup_entry(unsigned char *sha1)\n-{\n-\tint low = 0, high = nr_convert;\n-\n-\twhile (low < high) {\n-\t\tint next = (low + high) / 2;\n-\t\tstruct entry *n = convert[next];\n-\t\tint cmp = hashcmp(sha1, n->old_sha1);\n-\t\tif (!cmp)\n-\t\t\treturn n;\n-\t\tif (cmp < 0) {\n-\t\t\thigh = next;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tlow = next+1;\n-\t}\n-\treturn insert_new(sha1, low);\n-}\n-\n-static void convert_binary_sha1(void *buffer)\n-{\n-\tstruct entry *entry = convert_entry(buffer);\n-\thashcpy(buffer, entry->new_sha1);\n-}\n-\n-static void convert_ascii_sha1(void *buffer)\n-{\n-\tunsigned char sha1[20];\n-\tstruct entry *entry;\n-\n-\tif (get_sha1_hex(buffer, sha1))\n-\t\tdie(\"expected sha1, got '%s'\", (char*) buffer);\n-\tentry = convert_entry(sha1);\n-\tmemcpy(buffer, sha1_to_hex(entry->new_sha1), 40);\n-}\n-\n-static unsigned int convert_mode(unsigned int mode)\n-{\n-\tunsigned int newmode;\n-\n-\tnewmode = mode & S_IFMT;\n-\tif (S_ISREG(mode))\n-\t\tnewmode |= (mode & 0100) ? 0755 : 0644;\n-\treturn newmode;\n-}\n-\n-static int write_subdirectory(void *buffer, unsigned long size, const char *base, int baselen, unsigned char *result_sha1)\n-{\n-\tchar *new = xmalloc(size);\n-\tunsigned long newlen = 0;\n-\tunsigned long used;\n-\n-\tused = 0;\n-\twhile (size) {\n-\t\tint len = 21 + strlen(buffer);\n-\t\tchar *path = strchr(buffer, ' ');\n-\t\tunsigned char *sha1;\n-\t\tunsigned int mode;\n-\t\tchar *slash, *origpath;\n-\n-\t\tif (!path || strtoul_ui(buffer, 8, &mode))\n-\t\t\tdie(\"bad tree conversion\");\n-\t\tmode = convert_mode(mode);\n-\t\tpath++;\n-\t\tif (memcmp(path, base, baselen))\n-\t\t\tbreak;\n-\t\torigpath = path;\n-\t\tpath += baselen;\n-\t\tslash = strchr(path, '/');\n-\t\tif (!slash) {\n-\t\t\tnewlen += sprintf(new + newlen, \"%o %s\", mode, path);\n-\t\t\tnew[newlen++] = '\\0';\n-\t\t\thashcpy((unsigned char*)new + newlen, (unsigned char *) buffer + len - 20);\n-\t\t\tnewlen += 20;\n-\n-\t\t\tused += len;\n-\t\t\tsize -= len;\n-\t\t\tbuffer = (char *) buffer + len;\n-\t\t\tcontinue;\n-\t\t}\n-\n-\t\tnewlen += sprintf(new + newlen, \"%o %.*s\", S_IFDIR, (int)(slash - path), path);\n-\t\tnew[newlen++] = 0;\n-\t\tsha1 = (unsigned char *)(new + newlen);\n-\t\tnewlen += 20;\n-\n-\t\tlen = write_subdirectory(buffer, size, origpath, slash-origpath+1, sha1);\n-\n-\t\tused += len;\n-\t\tsize -= len;\n-\t\tbuffer = (char *) buffer + len;\n-\t}\n-\n-\twrite_sha1_file(new, newlen, tree_type, result_sha1);\n-\tfree(new);\n-\treturn used;\n-}\n-\n-static void convert_tree(void *buffer, unsigned long size, unsigned char *result_sha1)\n-{\n-\tvoid *orig_buffer = buffer;\n-\tunsigned long orig_size = size;\n-\n-\twhile (size) {\n-\t\tsize_t len = 1+strlen(buffer);\n-\n-\t\tconvert_binary_sha1((char *) buffer + len);\n-\n-\t\tlen += 20;\n-\t\tif (len > size)\n-\t\t\tdie(\"corrupt tree object\");\n-\t\tsize -= len;\n-\t\tbuffer = (char *) buffer + len;\n-\t}\n-\n-\twrite_subdirectory(orig_buffer, orig_size, \"\", 0, result_sha1);\n-}\n-\n-static unsigned long parse_oldstyle_date(const char *buf)\n-{\n-\tchar c, *p;\n-\tchar buffer[100];\n-\tstruct tm tm;\n-\tconst char *formats[] = {\n-\t\t\"%c\",\n-\t\t\"%a %b %d %T\",\n-\t\t\"%Z\",\n-\t\t\"%Y\",\n-\t\t\" %Y\",\n-\t\tNULL\n-\t};\n-\t/* We only ever did two timezones in the bad old format .. */\n-\tconst char *timezones[] = {\n-\t\t\"PDT\", \"PST\", \"CEST\", NULL\n-\t};\n-\tconst char **fmt = formats;\n-\n-\tp = buffer;\n-\twhile (isspace(c = *buf))\n-\t\tbuf++;\n-\twhile ((c = *buf++) != '\\n')\n-\t\t*p++ = c;\n-\t*p++ = 0;\n-\tbuf = buffer;\n-\tmemset(&tm, 0, sizeof(tm));\n-\tdo {\n-\t\tconst char *next = strptime(buf, *fmt, &tm);\n-\t\tif (next) {\n-\t\t\tif (!*next)\n-\t\t\t\treturn mktime(&tm);\n-\t\t\tbuf = next;\n-\t\t} else {\n-\t\t\tconst char **p = timezones;\n-\t\t\twhile (isspace(*buf))\n-\t\t\t\tbuf++;\n-\t\t\twhile (*p) {\n-\t\t\t\tif (!memcmp(buf, *p, strlen(*p))) {\n-\t\t\t\t\tbuf += strlen(*p);\n-\t\t\t\t\tbreak;\n-\t\t\t\t}\n-\t\t\t\tp++;\n-\t\t\t}\n-\t\t}\n-\t\tfmt++;\n-\t} while (*buf && *fmt);\n-\tprintf(\"left: %s\\n\", buf);\n-\treturn mktime(&tm);\n-}\n-\n-static int convert_date_line(char *dst, void **buf, unsigned long *sp)\n-{\n-\tunsigned long size = *sp;\n-\tchar *line = *buf;\n-\tchar *next = strchr(line, '\\n');\n-\tchar *date = strchr(line, '>');\n-\tint len;\n-\n-\tif (!next || !date)\n-\t\tdie(\"missing or bad author/committer line %s\", line);\n-\tnext++; date += 2;\n-\n-\t*buf = next;\n-\t*sp = size - (next - line);\n-\n-\tlen = date - line;\n-\tmemcpy(dst, line, len);\n-\tdst += len;\n-\n-\t/* Is it already in new format? */\n-\tif (isdigit(*date)) {\n-\t\tint datelen = next - date;\n-\t\tmemcpy(dst, date, datelen);\n-\t\treturn len + datelen;\n-\t}\n-\n-\t/*\n-\t * Hacky hacky: one of the sparse old-style commits does not have\n-\t * any date at all, but we can fake it by using the committer date.\n-\t */\n-\tif (*date == '\\n' && strchr(next, '>'))\n-\t\tdate = strchr(next, '>')+2;\n-\n-\treturn len + sprintf(dst, \"%lu -0700\\n\", parse_oldstyle_date(date));\n-}\n-\n-static void convert_date(void *buffer, unsigned long size, unsigned char *result_sha1)\n-{\n-\tchar *new = xmalloc(size + 100);\n-\tunsigned long newlen = 0;\n-\n-\t/* \"tree <sha1>\\n\" */\n-\tmemcpy(new + newlen, buffer, 46);\n-\tnewlen += 46;\n-\tbuffer = (char *) buffer + 46;\n-\tsize -= 46;\n-\n-\t/* \"parent <sha1>\\n\" */\n-\twhile (!memcmp(buffer, \"parent \", 7)) {\n-\t\tmemcpy(new + newlen, buffer, 48);\n-\t\tnewlen += 48;\n-\t\tbuffer = (char *) buffer + 48;\n-\t\tsize -= 48;\n-\t}\n-\n-\t/* \"author xyz <xyz> date\" */\n-\tnewlen += convert_date_line(new + newlen, &buffer, &size);\n-\t/* \"committer xyz <xyz> date\" */\n-\tnewlen += convert_date_line(new + newlen, &buffer, &size);\n-\n-\t/* Rest */\n-\tmemcpy(new + newlen, buffer, size);\n-\tnewlen += size;\n-\n-\twrite_sha1_file(new, newlen, commit_type, result_sha1);\n-\tfree(new);\n-}\n-\n-static void convert_commit(void *buffer, unsigned long size, unsigned char *result_sha1)\n-{\n-\tvoid *orig_buffer = buffer;\n-\tunsigned long orig_size = size;\n-\n-\tif (memcmp(buffer, \"tree \", 5))\n-\t\tdie(\"Bad commit '%s'\", (char*) buffer);\n-\tconvert_ascii_sha1((char *) buffer + 5);\n-\tbuffer = (char *) buffer + 46;    /* \"tree \" + \"hex sha1\" + \"\\n\" */\n-\twhile (!memcmp(buffer, \"parent \", 7)) {\n-\t\tconvert_ascii_sha1((char *) buffer + 7);\n-\t\tbuffer = (char *) buffer + 48;\n-\t}\n-\tconvert_date(orig_buffer, orig_size, result_sha1);\n-}\n-\n-static struct entry * convert_entry(unsigned char *sha1)\n-{\n-\tstruct entry *entry = lookup_entry(sha1);\n-\tenum object_type type;\n-\tvoid *buffer, *data;\n-\tunsigned long size;\n-\n-\tif (entry->converted)\n-\t\treturn entry;\n-\tdata = read_sha1_file(sha1, &type, &size);\n-\tif (!data)\n-\t\tdie(\"unable to read object %s\", sha1_to_hex(sha1));\n-\n-\tbuffer = xmalloc(size);\n-\tmemcpy(buffer, data, size);\n-\n-\tif (type == OBJ_BLOB) {\n-\t\twrite_sha1_file(buffer, size, blob_type, entry->new_sha1);\n-\t} else if (type == OBJ_TREE)\n-\t\tconvert_tree(buffer, size, entry->new_sha1);\n-\telse if (type == OBJ_COMMIT)\n-\t\tconvert_commit(buffer, size, entry->new_sha1);\n-\telse\n-\t\tdie(\"unknown object type %d in %s\", type, sha1_to_hex(sha1));\n-\tentry->converted = 1;\n-\tfree(buffer);\n-\tfree(data);\n-\treturn entry;\n-}\n-\n-int main(int argc, char **argv)\n-{\n-\tunsigned char sha1[20];\n-\tstruct entry *entry;\n-\n-\tsetup_git_directory();\n-\n-\tif (argc != 2)\n-\t\tusage(\"git-convert-objects <sha1>\");\n-\tif (get_sha1(argv[1], sha1))\n-\t\tdie(\"Not a valid object name %s\", argv[1]);\n-\n-\tentry = convert_entry(sha1);\n-\tprintf(\"new sha1: %s\\n\", sha1_to_hex(entry->new_sha1));\n-\treturn 0;\n-}\n-- \n1.5.3.2\n"},{"id":"53976","messageId":"Pine.LNX.4.64.0709251100560.28395@racer.site","threadId":"10002","inReplyTo":"1190690061-6720-1-git-send-email-kraai@ftbfs.org","subject":"Re: [PATCH] Move convert-objects to contrib.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-25T10:01:58Z","receivedAt":"2007-09-25T10:01:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nthe commit message looks a little bit empty to me.  I'd at least mention \nwhy convert-objects was needed, why it is no longer needed, and that \nLinus, the original author, is okay with it.\n\nAnd you might want to use the \"-M\" flag to format-patch next time (detect \nrenames).\n\nCiao,\nDscho\n"},{"id":"53994","messageId":"20070925140425.GA6061@ftbfs.org","threadId":"10002","inReplyTo":"Pine.LNX.4.64.0709251100560.28395@racer.site","subject":"Re: [PATCH] Move convert-objects to contrib.","fromName":"Matt Kraai","fromEmail":"kraai@ftbfs.org","sentAt":"2007-09-25T14:04:25Z","receivedAt":"2007-09-25T14:04:25Z","isPatch":true,"sender":{"key":"kraai@ftbfs.org","avatar":null},"body":"On Tue, Sep 25, 2007 at 11:01:58AM +0100, Johannes Schindelin wrote:\n> the commit message looks a little bit empty to me.  I'd at least mention \n> why convert-objects was needed, why it is no longer needed, and that \n> Linus, the original author, is okay with it.\n> \n> And you might want to use the \"-M\" flag to format-patch next time (detect \n> renames).\n\nOK, thanks.  I've resubmitted the patch, (hopefully) taking both\nsuggestions into account.\n\n-- \nMatt\n"},{"id":"53995","messageId":"Pine.LNX.4.64.0709251506220.28395@racer.site","threadId":"10002","inReplyTo":"20070925140425.GA6061@ftbfs.org","subject":"Re: [PATCH] Move convert-objects to contrib.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-25T14:06:38Z","receivedAt":"2007-09-25T14:06:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 25 Sep 2007, Matt Kraai wrote:\n\n> On Tue, Sep 25, 2007 at 11:01:58AM +0100, Johannes Schindelin wrote:\n> > the commit message looks a little bit empty to me.  I'd at least \n> > mention why convert-objects was needed, why it is no longer needed, \n> > and that Linus, the original author, is okay with it.\n> > \n> > And you might want to use the \"-M\" flag to format-patch next time \n> > (detect renames).\n> \n> OK, thanks.  I've resubmitted the patch, (hopefully) taking both \n> suggestions into account.\n\nYep, thanks, a pleasure to the eye.\n\nCiao,\nDscho\n"}]}