git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] builtin-commit: fix --signoff

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 11, 2007, 17:35 UTC
Message-ID
<Pine.LNX.4.64.0711111735470.4362@racer.site>
In-Reply-To
<Pine.LNX.4.64.0711111730580.4362@racer.site>

The Signed-off-by: line contained a spurious timestamp. The reason was a call to git_committer_info(1), which automatically added the timestamp.

Instead, fmt_ident() was taught to interpret an empty string for the date (as opposed to NULL, which still triggers the default behavior) as "do not bother with the timestamp", and builtin-commit.c uses it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-commit.c  |   29 ++++++++++++++++++-----------
 ident.c           |   10 +++++++---
 t/t7500-commit.sh |   13 +++++++++++++
 3 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 5c7d4df..6b1507d 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -183,21 +183,28 @@ static int prepare_log_message(const char *index_file, const char *prefix)
 		die("could not open %s\n", git_path(commit_editmsg));
 
 	stripspace(&sb, 0);
-	if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
-		die("could not write commit template: %s\n",
-		    strerror(errno));
 
 	if (signoff) {
-		const char *info, *bol;
-
-		info = git_committer_info(1);
-		strbuf_addch(&sb, '\0');
-		bol = strrchr(sb.buf + sb.len - 1, '\n');
-		if (!bol || prefixcmp(bol, sign_off_header))
-			fprintf(fp, "\n");
-		fprintf(fp, "%s%s\n", sign_off_header, git_committer_info(1));
+		struct strbuf sob;
+		int i;
+
+		strbuf_init(&sob, 0);
+		strbuf_addstr(&sob, sign_off_header);
+		strbuf_addstr(&sob, fmt_ident(getenv("GIT_COMMITTER_NAME"),
+                         getenv("GIT_COMMITTER_EMAIL"), "", 1));
+		strbuf_addch(&sob, '\n');
+
+		for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
+			; /* do nothing */
+		if (prefixcmp(sb.buf + i, sob.buf))
+			strbuf_addbuf(&sb, &sob);
+		strbuf_release(&sob);
 	}
 
+	if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
+		die("could not write commit template: %s\n",
+		    strerror(errno));
+
 	strbuf_release(&sb);
 
 	if (in_merge && !no_edit)
diff --git a/ident.c b/ident.c
index 9b2a852..5be7533 100644
--- a/ident.c
+++ b/ident.c
@@ -224,13 +224,17 @@ const char *fmt_ident(const char *name, const char *email,
 	}
 
 	strcpy(date, git_default_date);
-	if (date_str)
-		parse_date(date_str, date, sizeof(date));
+	if (date_str) {
+		if (*date_str)
+			parse_date(date_str, date, sizeof(date));
+		else
+			date[0] = '\0';
+	}
 
 	i = copy(buffer, sizeof(buffer), 0, name);
 	i = add_raw(buffer, sizeof(buffer), i, " <");
 	i = copy(buffer, sizeof(buffer), i, email);
-	i = add_raw(buffer, sizeof(buffer), i, "> ");
+	i = add_raw(buffer, sizeof(buffer), i, date[0] ? "> " : ">");
 	i = copy(buffer, sizeof(buffer), i, date);
 	if (i >= sizeof(buffer))
 		die("Impossibly long personal identifier");
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index abbf54b..13d5a0c 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -93,4 +93,17 @@ test_expect_success 'commit message from file should override template' '
 	commit_msg_is "standard input msg"
 '
 
+cat > expect << EOF
+zort
+Signed-off-by: C O Mitter <committer@example.com>
+EOF
+
+test_expect_success '--signoff' '
+	echo "yet another content *narf*" >> foo &&
+	echo "zort" |
+		GIT_EDITOR=../t7500/add-content git commit -s -F - foo &&
+	git cat-file commit HEAD | sed "1,/^$/d" > output &&
+	git diff expect output
+'
+
 test_done
-- 
1.5.3.5.1693.g26ed
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 7 of 24 in “Various (replacement) patches to builtin-commit”
  1. 0/6 Various (replacement) patches to builtin-commitJohannes Schindelin, Nov 11, 2007
  2. 1/6 builtin-commit: fix author date with --amend --author=<author>Johannes Schindelin, Nov 11, 2007
  3. Kristian HøgsbergNov 12, 2007
  4. Johannes SchindelinNov 12, 2007
  5. Junio C HamanoNov 13, 2007
  6. 2/6 git status: show relative paths when run in a subdirectoryJohannes Schindelin, Nov 11, 2007
  7. 3/6 builtin-commit: fix --signoffJohannes Schindelin, Nov 11, 2007
  8. 4/6 builtin-commit --s: add a newline if the last line was no S-O-BJohannes Schindelin, Nov 11, 2007
  9. 5/6 builtin-commit: resurrect behavior for multiple -m optionsJohannes Schindelin, Nov 11, 2007
  10. Pierre HabouzitNov 11, 2007
  11. Johannes SchindelinNov 11, 2007
  12. Pierre HabouzitNov 11, 2007
  13. Pierre HabouzitNov 11, 2007
  14. 6/6 builtin-commit: Add newline when showing which commit was createdJohannes Schindelin, Nov 11, 2007
  15. Jeff KingDec 1, 2007
  16. Johannes SchindelinDec 1, 2007
  17. Jeff KingDec 2, 2007
  18. Johannes SchindelinDec 2, 2007
  19. Jeff KingDec 2, 2007
  20. Johannes SchindelinDec 2, 2007
  21. Junio C HamanoDec 2, 2007
  22. Johannes SchindelinDec 2, 2007
  23. Junio C HamanoDec 3, 2007
  24. Jeff KingDec 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.