git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats.
@ 2007-09-25 14:38 Michal Vitecek
  2007-09-25 14:47 ` Johannes Schindelin
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Vitecek @ 2007-09-25 14:38 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Junio C Hamano

---

 Sending the patch again in correct form (hopefully) as instructed by
 Johannes Schindelin. Sorry for the hassle.


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

diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 3894633..0b74eb3 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -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");
diff --git a/commit.c b/commit.c
index 99f65ce..c9a1818 100644
--- a/commit.c
+++ b/commit.c
@@ -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;
diff --git a/interpolate.c b/interpolate.c
index 0082677..2f727cd 100644
--- a/interpolate.c
+++ b/interpolate.c
@@ -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);
diff --git a/log-tree.c b/log-tree.c
index a642371..79502f4 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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);
 }
 
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index ad6d0b8..1e4541a 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -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
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index f11ada8..abbf54b 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -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
-- 
1.5.3.2

-- 
		fuf		(fuf@mageo.cz)

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

* Re: [PATCH] Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats.
  2007-09-25 14:38 [PATCH] Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats Michal Vitecek
@ 2007-09-25 14:47 ` Johannes Schindelin
  2007-09-26  0:43   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2007-09-25 14:47 UTC (permalink / raw)
  To: Michal Vitecek; +Cc: git, Junio C Hamano

Hi,

On Tue, 25 Sep 2007, Michal Vitecek wrote:

> ---
> 
>  Sending the patch again in correct form (hopefully) as instructed by
>  Johannes Schindelin. Sorry for the hassle.

Thanks.

> diff --git a/commit.c b/commit.c
> index 99f65ce..c9a1818 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -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>");

This may have warranted a description in the commit message a la

	Instead of setting unknown entries to "<unknown>" in the 
	interp_table, we teach interpolate() to replace entries with 
	NULL values by the empty string.

> diff --git a/log-tree.c b/log-tree.c
> index a642371..79502f4 100644
> --- a/log-tree.c
> +++ b/log-tree.c
> @@ -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.

Here are still spaces instead of tabs.

These are only minor details; I don't know if Junio wants to fix them 
himself.

Ciao,
Dscho

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

* Re: [PATCH] Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats.
  2007-09-25 14:47 ` Johannes Schindelin
@ 2007-09-26  0:43   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2007-09-26  0:43 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Michal Vitecek, git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> This may have warranted a description in the commit message a la
>
> 	Instead of setting unknown entries to "<unknown>" in the 
> 	interp_table, we teach interpolate() to replace entries with 
> 	NULL values by the empty string.

Indeed.

> Here are still spaces instead of tabs.
>
> These are only minor details; I don't know if Junio wants to fix them 
> himself.

Good eyes.

Also a sign-off is missing ;-)

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

end of thread, other threads:[~2007-09-26  0:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-25 14:38 [PATCH] Don't use "<unknown>" for unknown values of placeholders and suppress printing of empty user formats Michal Vitecek
2007-09-25 14:47 ` Johannes Schindelin
2007-09-26  0:43   ` Junio C Hamano

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