diff options
author | Martin Koegler <mkoegler@auto.tuwien.ac.at> | 2008-02-25 22:46:07 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-02-25 23:57:35 -0800 |
commit | 45163382437c3862d3beb88134b7a975a3a26443 (patch) | |
tree | 3a9d70907689107868c6daee8128687c22a55583 /builtin-fsck.c | |
parent | 7914053ba9901be1f1530f46e8e2e6ee6f4ae5b1 (diff) | |
download | git-45163382437c3862d3beb88134b7a975a3a26443.tar.gz |
builtin-fsck: reports missing parent commits
parse_commit ignores parent commits with certain errors
(eg. a non commit object is already loaded under the sha1 of
the parent). To make fsck reports such errors, it has to compare
the nummer of parent commits returned by parse commit with the
number of parent commits in the object or in the graft/shallow file.
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-fsck.c')
-rw-r--r-- | builtin-fsck.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/builtin-fsck.c b/builtin-fsck.c index 7321ab236b..727310afc2 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -397,6 +397,8 @@ static int fsck_commit(struct commit *commit) { char *buffer = commit->buffer; unsigned char tree_sha1[20], sha1[20]; + struct commit_graft *graft; + int parents = 0; if (verbose) fprintf(stderr, "Checking commit %s\n", @@ -411,6 +413,28 @@ static int fsck_commit(struct commit *commit) if (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\n') return objerror(&commit->object, "invalid 'parent' line format - bad sha1"); buffer += 48; + parents++; + } + graft = lookup_commit_graft(commit->object.sha1); + if (graft) { + struct commit_list *p = commit->parents; + parents = 0; + while (p) { + p = p->next; + parents++; + } + if (graft->nr_parent == -1 && !parents) + ; /* shallow commit */ + else if (graft->nr_parent != parents) + return objerror(&commit->object, "graft objects missing"); + } else { + struct commit_list *p = commit->parents; + while (p && parents) { + p = p->next; + parents--; + } + if (p || parents) + return objerror(&commit->object, "parent objects missing"); } if (memcmp(buffer, "author ", 7)) return objerror(&commit->object, "invalid format - expected 'author' line"); |