git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Jonathan Nieder <jrnieder@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 3/4] revert: simplify insn parsing logic
Date: Thu, 29 Mar 2012 19:28:14 +0530	[thread overview]
Message-ID: <1333029495-10034-4-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1333029495-10034-1-git-send-email-artagnon@gmail.com>

Our instruction sheet parser first looks for a valid action by
checking that the buffer starts with either "pick" or "revert".  Then,
it looks for either spaces or tabs before looking for the object name,
erroring out if it doesn't find any.  Simplify this logic without
making any functional changes by looking for ("pick " or "pick\t") or
("revert " or "revert\t") in the first place.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 sequencer.c |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 458cffb..02e58ad 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -517,22 +517,19 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
 {
 	unsigned char commit_sha1[20];
 	enum replay_action action;
-	int namelen, padding;
+	int namelen;
 
-	if (!prefixcmp(bol, "pick")) {
+	if (!prefixcmp(bol, "pick ") || !prefixcmp(bol, "pick\t")) {
 		action = REPLAY_PICK;
 		bol += strlen("pick");
-	} else if (!prefixcmp(bol, "revert")) {
+	} else if (!prefixcmp(bol, "revert ") || !prefixcmp(bol, "revert\t")) {
 		action = REPLAY_REVERT;
 		bol += strlen("revert");
 	} else
 		return NULL;
 
 	/* Eat up extra spaces/ tabs before object name */
-	padding = strspn(bol, " \t");
-	if (!padding)
-		return NULL;
-	bol += padding;
+	bol += strspn(bol, " \t");
 
 	/*
 	 * Verify that the action matches up with the one in
-- 
1.7.8.1.362.g5d6df.dirty

  parent reply	other threads:[~2012-03-29 13:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-29 13:58 [PATCH 0/4] Minor sequencer.c cleanups Ramkumar Ramachandra
2012-03-29 13:58 ` [PATCH 1/4] sha1_name: introduce getn_sha1() to take length Ramkumar Ramachandra
2012-04-03 22:08   ` Jonathan Nieder
2012-04-04  7:35     ` Matthieu Moy
2012-04-04 15:40     ` Ramkumar Ramachandra
2012-04-04 20:53       ` Jonathan Nieder
2012-03-29 13:58 ` [PATCH 2/4] revert: use getn_sha1() to simplify insn parsing Ramkumar Ramachandra
2012-03-29 13:58 ` Ramkumar Ramachandra [this message]
2012-04-02 20:33   ` [PATCH 3/4] revert: simplify insn parsing logic Junio C Hamano
2012-04-03  4:50     ` Ramkumar Ramachandra
2012-03-29 13:58 ` [PATCH 4/4] revert: report fine-grained errors from insn parser Ramkumar Ramachandra

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=1333029495-10034-4-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.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).