[PATCH 11/16] revert_or_cherry_pick(): get oneline_body from get_oneline()

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

 



Currently the one-line commit message for the cherry-picked commit
is found with strchr(get_oneline(), ' ').  That wastes a few CPU
cycles, and more importantly, it makes it difficult to tweak the
output from get_oneline() later.  Teach get_oneline() to store the
one-line commit message using a caller-supplied pointer to avoid these
problems.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
Maybe the next few patches should be squashed.  They are separated one
commit per idea, but they affect the same code.

 builtin/revert.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/builtin/revert.c b/builtin/revert.c
index eff5268..4b2042f 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -73,7 +73,7 @@ static void parse_args(int argc, const char **argv)
 		exit(1);
 }
 
-static char *get_oneline(const char *message)
+static char *get_oneline(const char *message, char **body)
 {
 	char *result;
 	const char *p = message, *abbrev, *eol;
@@ -99,6 +99,7 @@ static char *get_oneline(const char *message)
 	memcpy(result + abbrev_len, "... ", 4);
 	memcpy(result + abbrev_len + 4, p, oneline_len);
 	result[abbrev_len + 4 + oneline_len] = '\0';
+	*body = result + abbrev_len + 4;
 	return result;
 }
 
@@ -249,7 +250,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 	unsigned char head[20];
 	struct commit *base, *next, *parent;
 	int i, index_fd, clean;
-	char *oneline, *reencoded_message = NULL;
+	char *oneline, *oneline_body, *reencoded_message = NULL;
 	const char *message, *encoding;
 	char *defmsg = git_pathdup("MERGE_MSG");
 	struct merge_options o;
@@ -341,15 +342,13 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 					git_commit_encoding, encoding)))
 		message = reencoded_message;
 
-	oneline = get_oneline(message);
+	oneline = get_oneline(message, &oneline_body);
 
 	if (action == REVERT) {
-		char *oneline_body = strchr(oneline, ' ');
-
 		base = commit;
 		next = parent;
 		add_to_msg("Revert \"");
-		add_to_msg(oneline_body + 1);
+		add_to_msg(oneline_body);
 		add_to_msg("\"\n\nThis reverts commit ");
 		add_to_msg(sha1_to_hex(commit->object.sha1));
 
-- 
1.7.0

--
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]