git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ashwin Jha <ajha.dev@gmail.com>
To: git@vger.kernel.org
Subject: Re: [PATCH] GSoC Miniproject 15. Rewrite fsck.c:fsck_commit()
Date: Fri, 21 Mar 2014 21:12:34 +0530	[thread overview]
Message-ID: <532C5DEA.1030006@gmail.com> (raw)
In-Reply-To: <1395366886-16839-1-git-send-email-ajha.dev@gmail.com>


-------- Original Message --------
Subject: 	[PATCH] GSoC Miniproject 15. Rewrite fsck.c:fsck_commit()
Date: 	Fri, 21 Mar 2014 07:24:46 +0530
From: 	Ashwin Jha <ajha.dev@gmail.com>
To: 	git@vger.kernel.org
CC: 	Ashwin Jha <ajha.dev@gmail.com>



modified fsck.c:fsck_commit(). Replaced memcmp() with starts_with() function.
starts_with() seems much more relevant than memcmp(). It uses one less argument
and its return value makes more sense.
skip_prefix() is not used as it uses strcmp() internally which seems unnecessarily
for current task. The current task can be easily done by providing offsets to the
buffer pointer (the way it is implemented currently).

Signed-off-by: Ashwin Jha <ajha.dev@gmail.com>
---
  fsck.c |   11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fsck.c b/fsck.c
index 64bf279..82e1640 100644
--- a/fsck.c
+++ b/fsck.c
@@ -6,6 +6,7 @@
  #include "commit.h"
  #include "tag.h"
  #include "fsck.h"
+#include "strbuf.h"
  
  static int fsck_walk_tree(struct tree *tree, fsck_walk_func walk, void *data)
  {
@@ -290,12 +291,12 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
  	int parents = 0;
  	int err;
  
-	if (memcmp(buffer, "tree ", 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')
  		return error_func(&commit->object, FSCK_ERROR, "invalid 'tree' line format - bad sha1");
  	buffer += 46;
-	while (!memcmp(buffer, "parent ", 7)) {
+	while (starts_with(buffer, "parent ")) {
  		if (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\n')
  			return error_func(&commit->object, FSCK_ERROR, "invalid 'parent' line format - bad sha1");
  		buffer += 48;
@@ -322,15 +323,15 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
  		if (p || parents)
  			return error_func(&commit->object, FSCK_ERROR, "parent objects missing");
  	}
-	if (memcmp(buffer, "author ", 7))
+	if (!starts_with(buffer, "author "))
  		return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'author' line");
  	buffer += 7;
  	err = fsck_ident(&buffer, &commit->object, error_func);
  	if (err)
  		return err;
-	if (memcmp(buffer, "committer ", strlen("committer ")))
+	if (!starts_with(buffer, "committer "))
  		return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'committer' line");
-	buffer += strlen("committer ");
+	buffer += 10;
  	err = fsck_ident(&buffer, &commit->object, error_func);
  	if (err)
  		return err;
-- 
1.7.9.5

  parent reply	other threads:[~2014-03-21 15:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-21  1:54 [PATCH] GSoC Miniproject 15. Rewrite fsck.c:fsck_commit() Ashwin Jha
2014-03-21  3:33 ` Eric Sunshine
2014-03-21 15:42 ` Ashwin Jha [this message]
     [not found] <CADi-0_PN=jV4TmS=_SH2rebHvE9zEveG6Eo8zrJt_43=b-_Ryw@mail.gmail.com>
2014-03-21 18:41 ` Eric Sunshine
2014-03-21 19:56   ` Ashwin Jha

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=532C5DEA.1030006@gmail.com \
    --to=ajha.dev@gmail.com \
    --cc=git@vger.kernel.org \
    /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).