[PATCH 2/3] fsck_commit: remove duplicate tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



All tests on the commit buffer in fsck_cmd are ready done by
parse_commit_buffer.

This patch rips out all redundant tests. It still leaves the check for
author, as this is can be used as starting point for validation the
author/committer information.

Signed-off-by: Martin Koegler <mkoegler@xxxxxxxxxxxxxxxxx>
---
 builtin-fsck.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/builtin-fsck.c b/builtin-fsck.c
index cc7524b..ba785ec 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -354,7 +354,7 @@ static int fsck_tree(struct tree *item)
 static int fsck_commit(struct commit *commit)
 {
 	char *buffer = commit->buffer;
-	unsigned char tree_sha1[20], sha1[20];
+	unsigned char tree_sha1[20];
 
 	if (verbose)
 		fprintf(stderr, "Checking commit %s\n",
@@ -363,22 +363,17 @@ static int fsck_commit(struct commit *commit)
 	if (!commit->date)
 		return objerror(&commit->object, "invalid author/committer line");
 
-	if (memcmp(buffer, "tree ", 5))
-		return objerror(&commit->object, "invalid format - expected 'tree' line");
-	if (get_sha1_hex(buffer+5, tree_sha1) || buffer[45] != '\n')
+	if (get_sha1_hex(buffer+5, tree_sha1))
 		return objerror(&commit->object, "invalid 'tree' line format - bad sha1");
 	buffer += 46;
-	while (!memcmp(buffer, "parent ", 7)) {
-		if (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\n')
-			return objerror(&commit->object, "invalid 'parent' line format - bad sha1");
+	while (!memcmp(buffer, "parent ", 7))
 		buffer += 48;
-	}
 	if (memcmp(buffer, "author ", 7))
 		return objerror(&commit->object, "invalid format - expected 'author' line");
 	free(commit->buffer);
 	commit->buffer = NULL;
 	if (!commit->tree)
-		return objerror(&commit->object, "could not load commit's tree %s", tree_sha1);
+		return objerror(&commit->object, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
 	if (!commit->parents && show_root)
 		printf("root %s\n", sha1_to_hex(commit->object.sha1));
 	return 0;
-- 
1.5.4.g22bc

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux