Skip to contentSkip to conversation

Added a new placeholder '%cm' for full commit message

PATCH In review Michal Vitecek 3 participants 12 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Added a new placeholder '%cm' for full commit message

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

Signature · 1 line
		fuf		([email protected])
Quoted 1 line

From 5e22a989e6805d860b8477393fa8a6cc54f35193 Mon Sep 17 00:00:00 2001

From: Michal Vitecek <[email protected]>
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(-)
Documentation/pretty-formats.txt +1 -0
index 0193c3c..26c42d3 100644
@@ -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
commit.c +17 -1
index 99f65ce..1e24e21 100644
@@ -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>");
Signature · 1 line
1.5.3.1
#1 lore raw

Hi,

Quoted 1 line · Michal Vitecek

I have added a new placeholder '%cm' for a full commit message.

You mean the raw message, including the headers? Why not use "%r" for that?

Quoted 4 lines

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

Then you should fix %b not to show "<undefined>".

And please adher to the tips in Documentation/SubmittingPatches.

Thank you,
Dscho

#2 lore raw
Quoted 6 lines · Johannes Schindelin
Quoted 1 line · Michal Vitecek

I have added a new placeholder '%cm' for a full commit message.

You mean the raw message, including the headers? Why not use "%r" for that?

No, sorry for the incorrect term. I meant the whole commit message (subject + 2*\n + body).

Quoted 6 lines
Quoted 4 lines

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

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Quoted 1 line

And please adher to the tips in Documentation/SubmittingPatches.

Will do, sorry about the attachment - still learning :)

Thank you,
Michal

Signature · 1 line
		fuf		([email protected])
#3 lore raw

Hi,

Quoted 10 lines · Michal Vitecek
Quoted 6 lines · Johannes Schindelin
Quoted 1 line · Michal Vitecek

I have added a new placeholder '%cm' for a full commit message.

You mean the raw message, including the headers? Why not use "%r" for that?

No, sorry for the incorrect term. I meant the whole commit message (subject + 2*\n + body).

Ah, makes sense. In that case, "%M" maybe?

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

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

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Yeah. Don't know why I did it that way.

Quoted 3 lines
Quoted 1 line

And please adher to the tips in Documentation/SubmittingPatches.

Will do, sorry about the attachment - still learning :)

No problem. Thanks for contributing!

Ciao,
Dscho

#4 lore raw

PATCH 1/1 Use "" instead of "<unknown>" for placeholders [was Re: [PATCH] Added a new placeholder '%cm' for full commit message]

Quoted 6 lines · Johannes Schindelin
Quoted 5 lines · Michal Vitecek
Quoted 4 lines · Johannes Schindelin
Quoted 1 line · Michal Vitecek

I have added a new placeholder '%cm' for a full commit message.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

You mean the raw message, including the headers? Why not use "%r" for that?

No, sorry for the incorrect term. I meant the whole commit message (subject + 2*\n + body).

Ah, makes sense. In that case, "%M" maybe?

I think it's no longer needed if instead of "<undefined>" only "" will be substituted.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

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

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Yeah. Don't know why I did it that way.

Here comes the big patch :)

Quoted 1 line

From 2e4ba4e73bbcd19558039dd85fe45c7bbe7fd1c4 Mon Sep 17 00:00:00 2001

From: Michal Vitecek <[email protected]>
Date: Fri, 21 Sep 2007 14:40:37 +0200
Subject: [PATCH] Use "" instead of "<unknown>" for placeholders

---
 commit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
commit.c +1 -1
index 99f65ce..7e90bc1 100644
@@ -919,7 +919,7 @@ long format_commit_message(const struct commit *commit, const void *format,
 		table[IBODY].value = xstrdup(msg + i);
 	for (i = 0; i < ARRAY_SIZE(table); i++)
 		if (!table[i].value)
-			interp_set_entry(table, i, "<unknown>");
+			interp_set_entry(table, i, "");
 
 	do {
 		char *buf = *buf_p;
Signature · 4 lines
1.5.3.1

-- 
		fuf		([email protected])
#5 lore raw

Re: [PATCH] Use "" instead of "<unknown>" for placeholders

Michal Vitecek <[email protected]> writes:

[jc: Added Dscho back on CC: list]

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

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

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Yeah. Don't know why I did it that way.

Here comes the big patch :)

Now, this breaks t6006 which needs this patch.

Looking at this patch, I am not sure if your change is really a desirable one --- shouldn't it be removing the line itself, not just <unknown> token?

---
 t/t6006-rev-list-format.sh |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
t/t6006-rev-list-format.sh +8 -8
index ad6d0b8..2be323c 100755
@@ -79,9 +79,9 @@ EOF
 
 test_format encoding %e <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
+
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
+
 EOF
 
 test_format subject %s <<'EOF'
@@ -93,9 +93,9 @@ EOF
 
 test_format body %b <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
+
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
+
 EOF
 
 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
@@ -121,9 +121,9 @@ test_format complex-encoding %e <<'EOF'
 commit f58db70b055c5718631e5c61528b28b12090cdea
 iso8859-1
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
+
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
+
 EOF
 
 test_format complex-subject %s <<'EOF'
@@ -142,9 +142,9 @@ and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: 臓bueno!
 
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
+
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
+
 EOF
 
 test_done
#6 lore raw

Re: [PATCH] Use "" instead of "<unknown>" for placeholders

Quoted 8 lines · Junio C Hamano
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

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

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Yeah. Don't know why I did it that way.

Here comes the big patch :)

Now, this breaks t6006 which needs this patch.

Oops - I'm sorry about that. I ran the test suite (1.5.3.1) but it failed in 2 tests before the patch and in 2 tests after it so I considered it okay.

Quoted 3 lines

Looking at this patch, I am not sure if your change is really a desirable one --- shouldn't it be removing the line itself, not just <unknown> token?

This sounds as the best solution. I'll look into it. Thanks for your time.

Signature · 1 line
		fuf					([email protected])
#7 lore raw

Re: [PATCH] Use "" instead of "<unknown>" for placeholders

Hello again,

Quoted 16 lines · Michal Vitecek
Quoted 10 lines · Junio C Hamano
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

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

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Yeah. Don't know why I did it that way.

Here comes the big patch :)

Now, this breaks t6006 which needs this patch.

Oops - I'm sorry about that. I ran the test suite (1.5.3.1) but it failed in 2 tests before the patch and in 2 tests after it so I considered it okay.

Quoted 5 lines
Quoted 3 lines

Looking at this patch, I am not sure if your change is really a desirable one --- shouldn't it be removing the line itself, not just <unknown> token?

This sounds as the best solution. I'll look into it. Thanks for your time.

Here comes the patch. I hope it will be ok this time :) Thanks.

Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats.

---
 builtin-rev-list.c         |    3 ++-
 commit.c                   |    3 ---
 interpolate.c              |    6 +++++-
 log-tree.c                 |   10 ++++++----
 t/t6006-rev-list-format.sh |    8 --------
 t/t7500-commit.sh          |    4 ++--
 6 files changed, 15 insertions(+), 19 deletions(-)
builtin-rev-list.c +2 -1
index 3894633..1de981d 100644
@@ -85,7 +85,8 @@ static void show_commit(struct commit *commit)
 		pretty_print_commit(revs.commit_format, commit, ~0,
 				    &buf, &buflen,
 				    revs.abbrev, NULL, NULL, revs.date_mode);
-		printf("%s%c", buf, hdr_termination);
+                if (strlen(buf))
+                    printf("%s%c", buf, hdr_termination);
 		free(buf);
 	}
 	maybe_flush_or_die(stdout, "stdout");
commit.c +0 -3
index 99f65ce..c9a1818 100644
@@ -917,9 +917,6 @@ long format_commit_message(const struct commit *commit, const void *format,
 	}
 	if (msg[i])
 		table[IBODY].value = xstrdup(msg + i);
-	for (i = 0; i < ARRAY_SIZE(table); i++)
-		if (!table[i].value)
-			interp_set_entry(table, i, "<unknown>");
 
 	do {
 		char *buf = *buf_p;
interpolate.c +5 -1
index 0082677..58fd055 100644
@@ -76,8 +76,12 @@ unsigned long interpolate(char *result, unsigned long reslen,
 			/* Check for valid interpolation. */
 			if (i < ninterps) {
 				value = interps[i].value;
-				valuelen = strlen(value);
+                                if (value == NULL) {
+                                    src += namelen;
+                                    continue;
+                                }
 
+				valuelen = strlen(value);
 				if (newlen + valuelen + 1 < reslen) {
 					/* Substitute. */
 					strncpy(dest, value, valuelen);
log-tree.c +6 -4
index a642371..5653332 100644
@@ -175,14 +175,15 @@ void show_log(struct rev_info *opt, const char *sep)
 	 *  - The pretty-printed commit lacks a newline at the end
 	 *    of the buffer, but we do want to make sure that we
 	 *    have a newline there. If the separator isn't already
-	 *    a newline, add an extra one.
+         *    a newline, add an extra one and do the same for the
+         *    user format as well.
 	 *  - unlike other log messages, the one-line format does
 	 *    not have an empty line between entries.
 	 */
 	extra = "";
-	if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
+	if (*sep != '\n' && (opt->commit_format == CMIT_FMT_ONELINE || opt->commit_format == CMIT_FMT_USERFORMAT))
 		extra = "\n";
-	if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
+	if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE && opt->commit_format != CMIT_FMT_USERFORMAT)
 		putchar(opt->diffopt.line_termination);
 	opt->shown_one = 1;
 
@@ -298,7 +299,8 @@ void show_log(struct rev_info *opt, const char *sep)
 	if (opt->show_log_size)
 		printf("log size %i\n", len);
 
-	printf("%s%s%s", msgbuf, extra, sep);
+        if (strlen(msgbuf))
+            printf("%s%s%s", msgbuf, extra, sep);
 	free(msgbuf);
 }
 
t/t6006-rev-list-format.sh +0 -8
index ad6d0b8..1e4541a 100755
@@ -79,9 +79,7 @@ EOF
 
 test_format encoding %e <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_format subject %s <<'EOF'
@@ -93,9 +91,7 @@ EOF
 
 test_format body %b <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
@@ -121,9 +117,7 @@ test_format complex-encoding %e <<'EOF'
 commit f58db70b055c5718631e5c61528b28b12090cdea
 iso8859-1
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_format complex-subject %s <<'EOF'
@@ -142,9 +136,7 @@ and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: ÂĄbueno!
 
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_done
t/t7500-commit.sh +2 -2
index f11ada8..abbf54b 100755
@@ -81,7 +81,7 @@ test_expect_success 'explicit commit message should override template' '
 	git add foo &&
 	GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" \
 		-m "command line msg" &&
-	commit_msg_is "command line msg<unknown>"
+	commit_msg_is "command line msg"
 '
 
 test_expect_success 'commit message from file should override template' '
@@ -90,7 +90,7 @@ test_expect_success 'commit message from file should override template' '
 	echo "standard input msg" |
 		GIT_EDITOR=../t7500/add-content git commit \
 			--template "$TEMPLATE" --file - &&
-	commit_msg_is "standard input msg<unknown>"
+	commit_msg_is "standard input msg"
 '
 
 test_done
Signature · 5 lines
1.5.3.1


-- 
		fuf		([email protected])
#8 lore raw

Re: [PATCH] Use "" instead of "<unknown>" for placeholders

Hi,

Quoted 23 lines · Michal Vitecek

Hello again,

Quoted 20 lines · Michal Vitecek
Quoted 10 lines · Junio C Hamano
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

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

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Yeah. Don't know why I did it that way.

Here comes the big patch :)

Now, this breaks t6006 which needs this patch.

Oops - I'm sorry about that. I ran the test suite (1.5.3.1) but it failed in 2 tests before the patch and in 2 tests after it so I considered it okay.

Quoted 3 lines

Looking at this patch, I am not sure if your change is really a desirable one --- shouldn't it be removing the line itself, not just <unknown> token?

Quoted 8 lines
Quoted 1 line

This sounds as the best solution. I'll look into it. Thanks for your time.

Here comes the patch. I hope it will be ok this time :) Thanks.

Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats.

---

Please move the discussion which should not be in the commit message _after_ the "---".

builtin-rev-list.c static void show_commit(struct commit *commit) · line 89

Quoted 11 lines
builtin-rev-list.c +2 -1
index 3894633..1de981d 100644
@@ -85,7 +85,8 @@ static void show_commit(struct commit *commit)
 		pretty_print_commit(revs.commit_format, commit, ~0,
 				    &buf, &buflen,
 				    revs.abbrev, NULL, NULL, revs.date_mode);
-		printf("%s%c", buf, hdr_termination);
+                if (strlen(buf))
+                    printf("%s%c", buf, hdr_termination);

We use tabs for indentation, not spaces.

Also, instead of the expensive "strlen(buf)", you rather want to check "if (*buf)".

log-tree.c void show_log(struct rev_info *opt, const char *sep) · line 303

Quoted 11 lines
log-tree.c +2 -1
index a642371..5653332 100644
@@ -298,7 +299,8 @@ void show_log(struct rev_info *opt, const char *sep)
 	if (opt->show_log_size)
 		printf("log size %i\n", len);
 
-	printf("%s%s%s", msgbuf, extra, sep);
+        if (strlen(msgbuf))
+            printf("%s%s%s", msgbuf, extra, sep);

Again, "if (*msgbuf)" is way more efficient.

Ciao,
Dscho

#9 lore raw

Re: [PATCH] Use "" instead of "<unknown>" for placeholders

Hi,

Quoted 26 lines · Johannes Schindelin
Quoted 26 lines
Quoted 15 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

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

Then you should fix %b not to show "<undefined>".

I'll do it if it is okay. Shall I do the same for the other placeholders as well?

Yeah. Don't know why I did it that way.

Here comes the big patch :)

Now, this breaks t6006 which needs this patch.

Oops - I'm sorry about that. I ran the test suite (1.5.3.1) but it failed in 2 tests before the patch and in 2 tests after it so I considered it okay.

Quoted 5 lines
Quoted 3 lines

Looking at this patch, I am not sure if your change is really a desirable one --- shouldn't it be removing the line itself, not just <unknown> token?

This sounds as the best solution. I'll look into it. Thanks for your time.

Here comes the patch. I hope it will be ok this time :) Thanks.

Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats.

Quoted 6 lines
Quoted 1 line

---

We use tabs for indentation, not spaces.

Also, instead of the expensive "strlen(buf)", you rather want to check "if (*buf)".

---

Thanks for the notes - here comes the patch with the above fixes.

 builtin-rev-list.c         |    3 ++-
 commit.c                   |    3 ---
 interpolate.c              |    6 +++++-
 log-tree.c                 |   10 ++++++----
 t/t6006-rev-list-format.sh |    8 --------
 t/t7500-commit.sh          |    4 ++--
 6 files changed, 15 insertions(+), 19 deletions(-)
builtin-rev-list.c +2 -1
index 3894633..0b74eb3 100644
@@ -85,7 +85,8 @@ static void show_commit(struct commit *commit)
 		pretty_print_commit(revs.commit_format, commit, ~0,
 				    &buf, &buflen,
 				    revs.abbrev, NULL, NULL, revs.date_mode);
-		printf("%s%c", buf, hdr_termination);
+		if (*buf)
+			printf("%s%c", buf, hdr_termination);
 		free(buf);
 	}
 	maybe_flush_or_die(stdout, "stdout");
commit.c +0 -3
index 99f65ce..c9a1818 100644
@@ -917,9 +917,6 @@ long format_commit_message(const struct commit *commit, const void *format,
 	}
 	if (msg[i])
 		table[IBODY].value = xstrdup(msg + i);
-	for (i = 0; i < ARRAY_SIZE(table); i++)
-		if (!table[i].value)
-			interp_set_entry(table, i, "<unknown>");
 
 	do {
 		char *buf = *buf_p;
interpolate.c +5 -1
index 0082677..2f727cd 100644
@@ -76,8 +76,12 @@ unsigned long interpolate(char *result, unsigned long reslen,
 			/* Check for valid interpolation. */
 			if (i < ninterps) {
 				value = interps[i].value;
-				valuelen = strlen(value);
+				if (!value) {
+					src += namelen;
+					continue;
+				}
 
+				valuelen = strlen(value);
 				if (newlen + valuelen + 1 < reslen) {
 					/* Substitute. */
 					strncpy(dest, value, valuelen);
log-tree.c +6 -4
index a642371..79502f4 100644
@@ -175,14 +175,15 @@ void show_log(struct rev_info *opt, const char *sep)
 	 *  - The pretty-printed commit lacks a newline at the end
 	 *    of the buffer, but we do want to make sure that we
 	 *    have a newline there. If the separator isn't already
-	 *    a newline, add an extra one.
+         *    a newline, add an extra one and do the same for the
+         *    user format as well.
 	 *  - unlike other log messages, the one-line format does
 	 *    not have an empty line between entries.
 	 */
 	extra = "";
-	if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
+	if (*sep != '\n' && (opt->commit_format == CMIT_FMT_ONELINE || opt->commit_format == CMIT_FMT_USERFORMAT))
 		extra = "\n";
-	if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
+	if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE && opt->commit_format != CMIT_FMT_USERFORMAT)
 		putchar(opt->diffopt.line_termination);
 	opt->shown_one = 1;
 
@@ -298,7 +299,8 @@ void show_log(struct rev_info *opt, const char *sep)
 	if (opt->show_log_size)
 		printf("log size %i\n", len);
 
-	printf("%s%s%s", msgbuf, extra, sep);
+	if (*msgbuf)
+		printf("%s%s%s", msgbuf, extra, sep);
 	free(msgbuf);
 }
 
t/t6006-rev-list-format.sh +0 -8
index ad6d0b8..1e4541a 100755
@@ -79,9 +79,7 @@ EOF
 
 test_format encoding %e <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_format subject %s <<'EOF'
@@ -93,9 +91,7 @@ EOF
 
 test_format body %b <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
@@ -121,9 +117,7 @@ test_format complex-encoding %e <<'EOF'
 commit f58db70b055c5718631e5c61528b28b12090cdea
 iso8859-1
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_format complex-subject %s <<'EOF'
@@ -142,9 +136,7 @@ and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: ÂĄbueno!
 
 commit 131a310eb913d107dd3c09a65d1651175898735d
-<unknown>
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-<unknown>
 EOF
 
 test_done
t/t7500-commit.sh +2 -2
index f11ada8..abbf54b 100755
@@ -81,7 +81,7 @@ test_expect_success 'explicit commit message should override template' '
 	git add foo &&
 	GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" \
 		-m "command line msg" &&
-	commit_msg_is "command line msg<unknown>"
+	commit_msg_is "command line msg"
 '
 
 test_expect_success 'commit message from file should override template' '
@@ -90,7 +90,7 @@ test_expect_success 'commit message from file should override template' '
 	echo "standard input msg" |
 		GIT_EDITOR=../t7500/add-content git commit \
 			--template "$TEMPLATE" --file - &&
-	commit_msg_is "standard input msg<unknown>"
+	commit_msg_is "standard input msg"
 '
 
 test_done
Signature · 5 lines
1.5.3.2


-- 
		fuf		([email protected])
#10 lore raw

Re: [PATCH] Use "" instead of "<unknown>" for placeholders

In reply to Johannes Schindelin

Hi,

Quoted 6 lines · Johannes Schindelin
Quoted 4 lines · Michal Vitecek

[lots of quoted mails]

Here comes the patch. I hope it will be ok this time :) Thanks.

Quoted 7 lines
Quoted 4 lines

Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats.

---

Please move the discussion which should not be in the commit message _after_ the "---".

What about this comment?

Ciao,
Dscho