[PATCH] Added a new placeholder '%cm' for full commit message

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

 



 Hello,

 I have added a new placeholder '%cm' for a full commit message. I made
 it because I want to use my own pretty format which currently only
 allows '%s' for subject and '%b' for body. But '%b' is substituted with
 <undefined> if the body is "missing" which I obviously don't like :)

 Thanks for consideration,
                        Michal
-- 
		fuf		(fuf@xxxxxxxx)
>From 5e22a989e6805d860b8477393fa8a6cc54f35193 Mon Sep 17 00:00:00 2001
From: Michal Vitecek <fuf@xxxxxxxx>
Date: Fri, 21 Sep 2007 12:02:57 +0200
Subject: [PATCH] Added a new placeholder '%cm' for full commit message

---
 Documentation/pretty-formats.txt |    1 +
 commit.c                         |   18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 0193c3c..26c42d3 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -117,6 +117,7 @@ The placeholders are:
 - '%e': encoding
 - '%s': subject
 - '%b': body
+- '%cm': commit message
 - '%Cred': switch color to red
 - '%Cgreen': switch color to green
 - '%Cblue': switch color to blue
diff --git a/commit.c b/commit.c
index 99f65ce..1e24e21 100644
--- a/commit.c
+++ b/commit.c
@@ -814,6 +814,7 @@ long format_commit_message(const struct commit *commit, const void *format,
 		{ "%e" },	/* encoding */
 		{ "%s" },	/* subject */
 		{ "%b" },	/* body */
+                { "%cm" },      /* commit message (subject and body) */
 		{ "%Cred" },	/* red */
 		{ "%Cgreen" },	/* green */
 		{ "%Cblue" },	/* blue */
@@ -835,12 +836,14 @@ long format_commit_message(const struct commit *commit, const void *format,
 		IENCODING,
 		ISUBJECT,
 		IBODY,
+                ICOMMIT_MESSAGE,
 		IRED, IGREEN, IBLUE, IRESET_COLOR,
 		INEWLINE,
 		ILEFT_RIGHT,
 	};
 	struct commit_list *p;
 	char parents[1024];
+        int cm_len = 0;
 	int i;
 	enum { HEADER, SUBJECT, BODY } state;
 	const char *msg = commit->buffer;
@@ -897,6 +900,7 @@ long format_commit_message(const struct commit *commit, const void *format,
 
 		if (state == SUBJECT) {
 			table[ISUBJECT].value = xstrndup(msg + i, eol - i);
+                        cm_len = eol - i + 2; /* + 2 for 2 newlines */
 			i = eol;
 		}
 		if (i == eol) {
@@ -915,8 +919,20 @@ long format_commit_message(const struct commit *commit, const void *format,
 				xstrndup(msg + i + 9, eol - i - 9);
 		i = eol;
 	}
-	if (msg[i])
+	if (msg[i]) {
 		table[IBODY].value = xstrdup(msg + i);
+                cm_len += strlen(msg + i);
+        }
+        if (cm_len) {
+            table[ICOMMIT_MESSAGE].value = xmalloc(cm_len + 1);
+            table[ICOMMIT_MESSAGE].value[0] = '\0';
+            if (table[ISUBJECT].value) {
+                strcpy(table[ICOMMIT_MESSAGE].value, table[ISUBJECT].value);
+                strcat(table[ICOMMIT_MESSAGE].value, "\n\n");
+            }
+            if (table[IBODY].value)
+                strcat(table[ICOMMIT_MESSAGE].value, table[IBODY].value);
+        }
 	for (i = 0; i < ARRAY_SIZE(table); i++)
 		if (!table[i].value)
 			interp_set_entry(table, i, "<unknown>");
-- 
1.5.3.1


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

  Powered by Linux