git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Added a new placeholder '%cm' for full commit message
@ 2007-09-21 10:14 Michal Vitecek
  2007-09-21 10:47 ` Johannes Schindelin
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Vitecek @ 2007-09-21 10:14 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 377 bytes --]

 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@mageo.cz)

[-- Attachment #2: 0001-Added-a-new-placeholder-cm-for-full-commit-messag.patch --]
[-- Type: text/plain, Size: 2764 bytes --]

>From 5e22a989e6805d860b8477393fa8a6cc54f35193 Mon Sep 17 00:00:00 2001
From: Michal Vitecek <fuf@mageo.cz>
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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-09-25 12:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-21 10:14 [PATCH] Added a new placeholder '%cm' for full commit message Michal Vitecek
2007-09-21 10:47 ` Johannes Schindelin
2007-09-21 11:06   ` Michal Vitecek
2007-09-21 11:08     ` Johannes Schindelin
2007-09-21 14:05       ` [PATCH] Use "" instead of "<unknown>" for placeholders [was Re: [PATCH] Added a new placeholder '%cm' for full commit message] Michal Vitecek
2007-09-21 20:12         ` [PATCH] Use "" instead of "<unknown>" for placeholders Junio C Hamano
2007-09-21 20:41           ` Johannes Schindelin
2007-09-22  8:53           ` Michal Vitecek
2007-09-25  9:43             ` Michal Vitecek
2007-09-25 10:25               ` Johannes Schindelin
2007-09-25 10:52                 ` Michal Vitecek
2007-09-25 12:46                 ` Johannes Schindelin

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).