From: blacksimit <cengoguzhanunlu@gmail.com>
To: sunshine@sunshineco.com, git@vger.kernel.org
Cc: Oguzhan Unlu <cengoguzhanunlu@gmail.com>
Subject: [PATCH v2] Rewrite fsck.c:fsck_commit() replace memcmp() with starts_with()
Date: Fri, 21 Mar 2014 18:37:18 +0200 [thread overview]
Message-ID: <1395419838-25527-1-git-send-email-cengoguzhanunlu@gmail.com> (raw)
From: Oguzhan Unlu <cengoguzhanunlu@gmail.com>
My solution to make lines containing buffer += a_number; clearer to anyone is following; I defined a new int, magic_num, then assigned lengths of used strings to magic_num and then changed assignment lines through using magic_num so that where the number which is added to buffer is known although I eliminated 3rd parameter of memcmp() when using starts_with().
Signed-off-by: Oguzhan Unlu <cengoguzhanunlu@gmail.com>
---
I didn't use skip_prefix() in this microproject and I plan to apply for GSOC 2014. I expect your feedbacks!
fsck.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/fsck.c b/fsck.c
index d43be98..4e5ca30 100644
--- a/fsck.c
+++ b/fsck.c
@@ -289,14 +289,17 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
struct commit_graft *graft;
int parents = 0;
int err;
-
+ int magic_num;
+
+ magic_num = strlen("tree "); /* magic_num is 5 */
if (!starts_with(buffer, "tree "))
return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'tree' line");
- if (get_sha1_hex(buffer+5, tree_sha1) || buffer[45] != '\n')
+ if (get_sha1_hex(buffer+magic_num, tree_sha1) || buffer[45] != '\n')
return error_func(&commit->object, FSCK_ERROR, "invalid 'tree' line format - bad sha1");
buffer += 46;
+ magic_num = strlen("parent "); /* magic_num is 7 */
while (starts_with(buffer, "parent ")) {
- if (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\n')
+ if (get_sha1_hex(buffer+magic_num, sha1) || buffer[47] != '\n')
return error_func(&commit->object, FSCK_ERROR, "invalid 'parent' line format - bad sha1");
buffer += 48;
parents++;
@@ -322,15 +325,17 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
if (p || parents)
return error_func(&commit->object, FSCK_ERROR, "parent objects missing");
}
+ magic_num = strlen("author "); /* magic_num is 7 */
if (!starts_with(buffer, "author "))
return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'author' line");
- buffer += 7;
+ buffer += magic_num;
err = fsck_ident(&buffer, &commit->object, error_func);
if (err)
return err;
+ magic_num = strlen("committer"); /* magic_num is 7 */
if (!starts_with(buffer, "committer "))
return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'committer' line");
- buffer += strlen("committer ");
+ buffer += magic_num;
err = fsck_ident(&buffer, &commit->object, error_func);
if (err)
return err;
--
1.9.1.286.g5172cb3
next reply other threads:[~2014-03-21 16:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-21 16:37 blacksimit [this message]
2014-03-21 18:43 ` [PATCH v2] Rewrite fsck.c:fsck_commit() replace memcmp() with starts_with() Junio C Hamano
2014-03-21 19:01 ` Matthieu Moy
2014-03-21 19:33 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1395419838-25527-1-git-send-email-cengoguzhanunlu@gmail.com \
--to=cengoguzhanunlu@gmail.com \
--cc=git@vger.kernel.org \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).