fsck: simplify fsck_commit_buffer() by using commit_list_count()
fsck_commit_buffer() checks that the number of items in the parents list of a commit matches the number of parent lines in its buffer or -- if a graft is used -- the number of parents in that graft. Simplify the code by using commit_list_count() instead of counting by hand. Also use different variables for the number of lines and the number of list items, making it easier to compare them. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
cb979dbd8f
commit
9d02150cf4
22
fsck.c
22
fsck.c
@ -281,7 +281,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
|
|||||||
{
|
{
|
||||||
unsigned char tree_sha1[20], sha1[20];
|
unsigned char tree_sha1[20], sha1[20];
|
||||||
struct commit_graft *graft;
|
struct commit_graft *graft;
|
||||||
int parents = 0;
|
unsigned parent_count, parent_line_count = 0;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!skip_prefix(buffer, "tree ", &buffer))
|
if (!skip_prefix(buffer, "tree ", &buffer))
|
||||||
@ -293,27 +293,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
|
|||||||
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
|
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
|
||||||
return error_func(&commit->object, FSCK_ERROR, "invalid 'parent' line format - bad sha1");
|
return error_func(&commit->object, FSCK_ERROR, "invalid 'parent' line format - bad sha1");
|
||||||
buffer += 41;
|
buffer += 41;
|
||||||
parents++;
|
parent_line_count++;
|
||||||
}
|
}
|
||||||
graft = lookup_commit_graft(commit->object.sha1);
|
graft = lookup_commit_graft(commit->object.sha1);
|
||||||
|
parent_count = commit_list_count(commit->parents);
|
||||||
if (graft) {
|
if (graft) {
|
||||||
struct commit_list *p = commit->parents;
|
if (graft->nr_parent == -1 && !parent_count)
|
||||||
parents = 0;
|
|
||||||
while (p) {
|
|
||||||
p = p->next;
|
|
||||||
parents++;
|
|
||||||
}
|
|
||||||
if (graft->nr_parent == -1 && !parents)
|
|
||||||
; /* shallow commit */
|
; /* shallow commit */
|
||||||
else if (graft->nr_parent != parents)
|
else if (graft->nr_parent != parent_count)
|
||||||
return error_func(&commit->object, FSCK_ERROR, "graft objects missing");
|
return error_func(&commit->object, FSCK_ERROR, "graft objects missing");
|
||||||
} else {
|
} else {
|
||||||
struct commit_list *p = commit->parents;
|
if (parent_count != parent_line_count)
|
||||||
while (p && parents) {
|
|
||||||
p = p->next;
|
|
||||||
parents--;
|
|
||||||
}
|
|
||||||
if (p || parents)
|
|
||||||
return error_func(&commit->object, FSCK_ERROR, "parent objects missing");
|
return error_func(&commit->object, FSCK_ERROR, "parent objects missing");
|
||||||
}
|
}
|
||||||
if (!skip_prefix(buffer, "author ", &buffer))
|
if (!skip_prefix(buffer, "author ", &buffer))
|
||||||
|
Loading…
Reference in New Issue
Block a user