@matheusbsbs / matheus-bagliano / commits / 4516338243
Fork 0

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>

Martin Koegler committed Feb 25, 2008 at 22:46 UTC 45163382437c3862d3beb88134b7a975a3a26443
3 files changed +26 -1
builtin-fsck.c
+24
@@ -397,6 +397,8 @@ static int fsck_commit(struct commit *commit)
397 {
398 char *buffer = commit->buffer;
399 unsigned char tree_sha1[20], sha1[20];
400 + struct commit_graft *graft;
401 + int parents = 0;
402
403 if (verbose)
404 fprintf(stderr, "Checking commit %s\n",
@@ -411,6 +413,28 @@ static int fsck_commit(struct commit *commit)
413 if (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\n')
414 return objerror(&commit->object, "invalid 'parent' line format - bad sha1");
415 buffer += 48;
416 + parents++;
417 + }
418 + graft = lookup_commit_graft(commit->object.sha1);
419 + if (graft) {
420 + struct commit_list *p = commit->parents;
421 + parents = 0;
422 + while (p) {
423 + p = p->next;
424 + parents++;
425 + }
426 + if (graft->nr_parent == -1 && !parents)
427 + ; /* shallow commit */
428 + else if (graft->nr_parent != parents)
429 + return objerror(&commit->object, "graft objects missing");
430 + } else {
431 + struct commit_list *p = commit->parents;
432 + while (p && parents) {
433 + p = p->next;
434 + parents--;
435 + }
436 + if (p || parents)
437 + return objerror(&commit->object, "parent objects missing");
438 }
439 if (memcmp(buffer, "author ", 7))
440 return objerror(&commit->object, "invalid format - expected 'author' line");
commit.c
+1 -1
@@ -193,7 +193,7 @@ static void prepare_commit_graft(void)
193 commit_graft_prepared = 1;
194 }
195
196 -static struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
196 +struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
197 {
198 int pos;
199 prepare_commit_graft();
commit.h
+1
@@ -101,6 +101,7 @@ struct commit_graft {
101 struct commit_graft *read_graft_line(char *buf, int len);
102 int register_commit_graft(struct commit_graft *, int);
103 int read_graft_file(const char *graft_file);
104 +struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
105
106 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
107