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

Re: [PATCH 1/3] log_ref_write() -- do not chomp reflog message at the first LF

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 29, 2007, 11:57 UTC
Message-ID
<Pine.LNX.4.64.0707291248560.14781@racer.site>
In-Reply-To
<7vvec4nhfk.fsf_-_@assigned-by-dhcp.cox.net>
Hi,
On Sat, 28 Jul 2007, Junio C Hamano wrote:
> A reflog file is organized as one-line-per-entry records, and we
> enforced the file format integrity by chomping the given message
> at the first LF.  This changes it to convert them to SP, which
> is more in line with the --pretty=oneline format.

Would it not be better to chop off before the first "\n", and just append "..."? IOW something like

-- snip --
 refs.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/refs.c b/refs.c
index 2694e70..554436b 100644
--- a/refs.c
+++ b/refs.c
@@ -1043,7 +1043,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 	unsigned maxlen, len;
 	int msglen;
 	char *log_file, *logrec;
-	const char *committer;
+	const char *committer, *postmsg;
 
 	if (log_all_ref_updates < 0)
 		log_all_ref_updates = !is_bare_repository();
@@ -1088,15 +1088,16 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 				break;
 		if (*msg) {
 			const char *ep = strchr(msg, '\n');
-			if (ep)
+			if (ep) {
 				msglen = ep - msg;
-			else
+				postmsg = (ep[1] && !isspace(ep[1])) ? "..." : NULL;
+			} else
 				msglen = strlen(msg);
 		}
 	}
 
 	committer = git_committer_info(-1);
-	maxlen = strlen(committer) + msglen + 100;
+	maxlen = strlen(committer) + msglen + 100 + 3;
 	logrec = xmalloc(maxlen);
 	len = sprintf(logrec, "%s %s %s\n",
 		      sha1_to_hex(old_sha1),
@@ -1104,6 +1105,10 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 		      committer);
 	if (msglen)
 		len += sprintf(logrec + len - 1, "\t%.*s\n", msglen, msg) - 1;
+	if (postmsg) {
+		len += strlen(postmsg);
+		strcat(logrec + len - 1, postmsg);
+	}
 	written = len <= maxlen ? write_in_full(logfd, logrec, len) : -1;
 	free(logrec);
 	if (close(logfd) != 0 || written != len)
-- snap --

It is not like the reflog messages have to be very verbose; they only have 
to give a hint what the commit was about, and the commit name is the 
important information.

What do you think?

Ciao,
Dscho
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 18 in “git-svn rebase screwing up commit messages”
  1. Benoit SIGOUREJul 28, 2007
  2. Junio C HamanoJul 28, 2007
  3. SeanJul 28, 2007
  4. Junio C HamanoJul 28, 2007
  5. SeanJul 28, 2007
  6. Junio C HamanoJul 28, 2007
  7. SeanJul 28, 2007
  8. Junio C HamanoJul 28, 2007
  9. Junio C HamanoJul 29, 2007
  10. 1/3 log_ref_write() -- do not chomp reflog message at the first LFJunio C Hamano, Jul 29, 2007
  11. Johannes SchindelinJul 29, 2007
  12. Junio C HamanoJul 29, 2007
  13. Johannes SchindelinJul 29, 2007
  14. 2/3 symbolic-ref, update-ref: do not refuse reflog message with LFJunio C Hamano, Jul 29, 2007
  15. 3/3 rebase: try not to munge commit log messageJunio C Hamano, Jul 29, 2007
  16. Jakub NarebskiJul 28, 2007
  17. Robin RosenbergJul 28, 2007
  18. Benoit SIGOUREJul 28, 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.