{"thread":{"id":"36141","subject":"[PATCH 0/2] GSoC micro project, use skip_prefix() in fsck_commit()","startedAt":"2014-03-12T18:18:22Z","lastAt":"2014-03-12T18:18:24Z","messageCount":3,"participants":["Yuxuan Shui"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"236591","messageId":"1394648304-19159-1-git-send-email-yshuiv7@gmail.com","threadId":"36141","inReplyTo":null,"subject":"[PATCH 0/2] GSoC micro project, use skip_prefix() in fsck_commit()","fromName":"Yuxuan Shui","fromEmail":"yshuiv7@gmail.com","sentAt":"2014-03-12T18:18:22Z","receivedAt":"2014-03-12T18:18:22Z","isPatch":true,"sender":{"key":"yshuiv7@gmail.com","avatar":"https://avatars.githubusercontent.com/u/366851?v=4"},"body":"\nYuxuan Shui (2):\n  fsck.c: Change the type of fsck_ident()'s first argument\n  fsck.c: Rewrite fsck_commit() to use skip_prefix()\n\n fsck.c | 26 ++++++++++++++------------\n 1 file changed, 14 insertions(+), 12 deletions(-)\n\n-- \n1.9.0\n"},{"id":"236592","messageId":"1394648304-19159-2-git-send-email-yshuiv7@gmail.com","threadId":"36141","inReplyTo":"1394648304-19159-1-git-send-email-yshuiv7@gmail.com","subject":"[PATCH 1/2] fsck.c: Change the type of fsck_ident()'s first argument","fromName":"Yuxuan Shui","fromEmail":"yshuiv7@gmail.com","sentAt":"2014-03-12T18:18:23Z","receivedAt":"2014-03-12T18:18:23Z","isPatch":true,"sender":{"key":"yshuiv7@gmail.com","avatar":"https://avatars.githubusercontent.com/u/366851?v=4"},"body":"Since fsck_ident doesn't change the content of **ident, the type of\nident could be const char **.\n\nThis change is required to rewrite fsck_commit() to use skip_prefix().\n---\n fsck.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/fsck.c b/fsck.c\nindex 99c0497..1789c34 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -243,7 +243,7 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)\n \treturn retval;\n }\n \n-static int fsck_ident(char **ident, struct object *obj, fsck_error error_func)\n+static int fsck_ident(const char **ident, struct object *obj, fsck_error error_func)\n {\n \tif (**ident == '<')\n \t\treturn error_func(obj, FSCK_ERROR, \"invalid author/committer line - missing space before email\");\n-- \n1.9.0\n"},{"id":"236593","messageId":"1394648304-19159-3-git-send-email-yshuiv7@gmail.com","threadId":"36141","inReplyTo":"1394648304-19159-1-git-send-email-yshuiv7@gmail.com","subject":"[PATCH 2/2] fsck.c: Rewrite fsck_commit() to use skip_prefix()","fromName":"Yuxuan Shui","fromEmail":"yshuiv7@gmail.com","sentAt":"2014-03-12T18:18:24Z","receivedAt":"2014-03-12T18:18:24Z","isPatch":true,"sender":{"key":"yshuiv7@gmail.com","avatar":"https://avatars.githubusercontent.com/u/366851?v=4"},"body":"The purpose of skip_prefix() is much clearer than memcmp(). Also\nskip_prefix() takes one less argument and its return value makes more\nsense.\n---\n fsck.c | 24 +++++++++++++-----------\n 1 file changed, 13 insertions(+), 11 deletions(-)\n\ndiff --git a/fsck.c b/fsck.c\nindex 1789c34..7e6b829 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -281,7 +281,7 @@ static int fsck_ident(const char **ident, struct object *obj, fsck_error error_f\n \n static int fsck_commit(struct commit *commit, fsck_error error_func)\n {\n-\tchar *buffer = commit->buffer;\n+\tconst char *buffer = commit->buffer, *tmp;\n \tunsigned char tree_sha1[20], sha1[20];\n \tstruct commit_graft *graft;\n \tint parents = 0;\n@@ -290,15 +290,17 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)\n \tif (commit->date == ULONG_MAX)\n \t\treturn error_func(&commit->object, FSCK_ERROR, \"invalid author/committer line\");\n \n-\tif (memcmp(buffer, \"tree \", 5))\n+\tbuffer = skip_prefix(buffer, \"tree \");\n+\tif (buffer == NULL)\n \t\treturn error_func(&commit->object, FSCK_ERROR, \"invalid format - expected 'tree' line\");\n-\tif (get_sha1_hex(buffer+5, tree_sha1) || buffer[45] != '\\n')\n+\tif (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\\n')\n \t\treturn error_func(&commit->object, FSCK_ERROR, \"invalid 'tree' line format - bad sha1\");\n-\tbuffer += 46;\n-\twhile (!memcmp(buffer, \"parent \", 7)) {\n-\t\tif (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\\n')\n+\tbuffer += 41;\n+\twhile ((tmp = skip_prefix(buffer, \"parent \"))) {\n+\t\tbuffer = tmp;\n+\t\tif (get_sha1_hex(buffer, sha1) || buffer[40] != '\\n')\n \t\t\treturn error_func(&commit->object, FSCK_ERROR, \"invalid 'parent' line format - bad sha1\");\n-\t\tbuffer += 48;\n+\t\tbuffer += 41;\n \t\tparents++;\n \t}\n \tgraft = lookup_commit_graft(commit->object.sha1);\n@@ -322,15 +324,15 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)\n \t\tif (p || parents)\n \t\t\treturn error_func(&commit->object, FSCK_ERROR, \"parent objects missing\");\n \t}\n-\tif (memcmp(buffer, \"author \", 7))\n+\tbuffer = skip_prefix(buffer, \"author \");\n+\tif (buffer == NULL)\n \t\treturn error_func(&commit->object, FSCK_ERROR, \"invalid format - expected 'author' line\");\n-\tbuffer += 7;\n \terr = fsck_ident(&buffer, &commit->object, error_func);\n \tif (err)\n \t\treturn err;\n-\tif (memcmp(buffer, \"committer \", strlen(\"committer \")))\n+\tbuffer = skip_prefix(buffer, \"committer \");\n+\tif (buffer == NULL)\n \t\treturn error_func(&commit->object, FSCK_ERROR, \"invalid format - expected 'committer' line\");\n-\tbuffer += strlen(\"committer \");\n \terr = fsck_ident(&buffer, &commit->object, error_func);\n \tif (err)\n \t\treturn err;\n-- \n1.9.0\n"}]}