[PATCH 1/2] pretty: refactor --format "magic" placeholders

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

 



Instead of assuming each magic token is a single character,
let's handle arbitrary-sized magic.

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
 pretty.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/pretty.c b/pretty.c
index 230fe1c..7b4d098 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1018,6 +1018,7 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 				 void *context)
 {
 	int consumed;
+	int magic_len = 0;
 	size_t orig_len;
 	enum {
 		NO_MAGIC,
@@ -1039,13 +1040,13 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 	default:
 		break;
 	}
-	if (magic != NO_MAGIC)
+	if (magic != NO_MAGIC) {
+		magic_len++;
 		placeholder++;
+	}
 
 	orig_len = sb->len;
 	consumed = format_commit_one(sb, placeholder, context);
-	if (magic == NO_MAGIC)
-		return consumed;
 
 	if ((orig_len == sb->len) && magic == DEL_LF_BEFORE_EMPTY) {
 		while (sb->len && sb->buf[sb->len - 1] == '\n')
@@ -1056,7 +1057,7 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 		else if (magic == ADD_SP_BEFORE_NON_EMPTY)
 			strbuf_insert(sb, orig_len, " ", 1);
 	}
-	return consumed + 1;
+	return consumed + magic_len;
 }
 
 static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
-- 
1.7.8.1.3.gba11d

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