{"thread":{"id":"12296","subject":"[PATCH 4/4 v2] builtin-fsck: reports missing parent commits","startedAt":"2008-02-24T16:14:47Z","lastAt":"2008-02-24T16:14:47Z","messageCount":1,"participants":["Martin Koegler"],"isPatch":true,"patchVersion":2,"patchTotal":4},"messages":[{"id":"69801","messageId":"12038696874197-git-send-email-mkoegler@auto.tuwien.ac.at","threadId":"12296","inReplyTo":null,"subject":"[PATCH 4/4 v2] builtin-fsck: reports missing parent commits","fromName":"Martin Koegler","fromEmail":"mkoegler@auto.tuwien.ac.at","sentAt":"2008-02-24T16:14:47Z","receivedAt":"2008-02-24T16:14:47Z","isPatch":true,"sender":{"key":"mkoegler@auto.tuwien.ac.at","avatar":null},"body":"Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n---\nSorry, I found a bug in the last version.\n\n builtin-fsck.c |   24 ++++++++++++++++++++++++\n commit.c       |    2 +-\n commit.h       |    1 +\n 3 files changed, 26 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 512346a..98d81d9 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -394,6 +394,8 @@ static int fsck_commit(struct commit *commit)\n {\n \tchar *buffer = commit->buffer;\n \tunsigned char tree_sha1[20], sha1[20];\n+\tstruct commit_graft *graft;\n+\tint parents = 0;\n \n \tif (verbose)\n \t\tfprintf(stderr, \"Checking commit %s\\n\",\n@@ -411,6 +413,28 @@ static int fsck_commit(struct commit *commit)\n \t\tif (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\\n')\n \t\t\treturn objerror(&commit->object, \"invalid 'parent' line format - bad sha1\");\n \t\tbuffer += 48;\n+\t\tparents++;\n+\t}\n+\tgraft = lookup_commit_graft(commit->object.sha1);\n+\tif (graft) {\n+\t\tstruct commit_list *p = commit->parents;\n+\t\tparents = 0;\n+\t\twhile (p && parents) {\n+\t\t\tp = p->next;\n+\t\t\tparents++;\n+\t\t}\n+\t\tif (graft->nr_parent == -1 && !parents)\n+\t\t\t; /* shallow commit */\n+\t\telse if (graft->nr_parent != parents)\n+\t\t\treturn objerror(&commit->object, \"graft objects missing\");\n+\t} else {\n+\t\tstruct commit_list *p = commit->parents;\n+\t\twhile (p && parents) {\n+\t\t\tp = p->next;\n+\t\t\tparents--;\n+\t\t}\n+\t\tif (p || parents)\n+\t\t\treturn objerror(&commit->object, \"parent objects missing\");\n \t}\n \tif (memcmp(buffer, \"author \", 7))\n \t\treturn objerror(&commit->object, \"invalid format - expected 'author' line\");\ndiff --git a/commit.c b/commit.c\nindex 6684c4e..94d5b3d 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -193,7 +193,7 @@ static void prepare_commit_graft(void)\n \tcommit_graft_prepared = 1;\n }\n \n-static struct commit_graft *lookup_commit_graft(const unsigned char *sha1)\n+struct commit_graft *lookup_commit_graft(const unsigned char *sha1)\n {\n \tint pos;\n \tprepare_commit_graft();\ndiff --git a/commit.h b/commit.h\nindex 80d65b9..a1e9591 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -116,6 +116,7 @@ struct commit_graft {\n struct commit_graft *read_graft_line(char *buf, int len);\n int register_commit_graft(struct commit_graft *, int);\n int read_graft_file(const char *graft_file);\n+struct commit_graft *lookup_commit_graft(const unsigned char *sha1);\n \n extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);\n \n-- \n1.5.4.2.g12981.dirty\n"}]}