All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Sean <seanlkml@sympatico.ca>
Cc: Benoit SIGOURE <tsuna@lrde.epita.fr>, git@vger.kernel.org
Subject: [PATCH 1/3] log_ref_write() -- do not chomp reflog message at the first LF
Date: Sat, 28 Jul 2007 18:10:23 -0700	[thread overview]
Message-ID: <7vvec4nhfk.fsf_-_@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vzm1gnhin.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sat, 28 Jul 2007 18:08:32 -0700")

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.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 refs.c |   44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/refs.c b/refs.c
index 2694e70..fac6548 100644
--- a/refs.c
+++ b/refs.c
@@ -1036,6 +1036,32 @@ void unlock_ref(struct ref_lock *lock)
 	free(lock);
 }
 
+/*
+ * copy the reflog message msg to buf, which has been allocated sufficiently
+ * large, while cleaning up the whitespaces.  Especially, convert LF to space,
+ * because reflog file is one line per entry.
+ */
+static int copy_msg(char *buf, const char *msg)
+{
+	char *cp = buf;
+	char c;
+	int wasspace = 1;
+
+	*cp++ = '\t';
+	while ((c = *msg++)) {
+		if (wasspace && isspace(c))
+			continue;
+		wasspace = isspace(c);
+		if (wasspace)
+			c = ' ';
+		*cp++ = c;
+	}
+	while (buf < cp && isspace(cp[-1]))
+		cp--;
+	*cp++ = '\n';
+	return cp - buf;
+}
+
 static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 			 const unsigned char *new_sha1, const char *msg)
 {
@@ -1080,21 +1106,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 
 	adjust_shared_perm(log_file);
 
-	msglen = 0;
-	if (msg) {
-		/* clean up the message and make sure it is a single line */
-		for ( ; *msg; msg++)
-			if (!isspace(*msg))
-				break;
-		if (*msg) {
-			const char *ep = strchr(msg, '\n');
-			if (ep)
-				msglen = ep - msg;
-			else
-				msglen = strlen(msg);
-		}
-	}
-
+	msglen = msg ? strlen(msg) : 0;
 	committer = git_committer_info(-1);
 	maxlen = strlen(committer) + msglen + 100;
 	logrec = xmalloc(maxlen);
@@ -1103,7 +1115,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 		      sha1_to_hex(new_sha1),
 		      committer);
 	if (msglen)
-		len += sprintf(logrec + len - 1, "\t%.*s\n", msglen, msg) - 1;
+		len += copy_msg(logrec + len - 1, msg) - 1;
 	written = len <= maxlen ? write_in_full(logfd, logrec, len) : -1;
 	free(logrec);
 	if (close(logfd) != 0 || written != len)
-- 
1.5.3.rc3.24.g83b3d

  reply	other threads:[~2007-07-29  1:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-28 10:07 git-svn rebase screwing up commit messages Benoit SIGOURE
2007-07-28 12:14 ` Junio C Hamano
2007-07-28 12:35   ` Sean
2007-07-28 13:10     ` Junio C Hamano
2007-07-28 13:29       ` Sean
2007-07-28 13:38         ` Junio C Hamano
2007-07-28 14:11           ` Sean
2007-07-28 20:41             ` Junio C Hamano
2007-07-29  1:08               ` Junio C Hamano
2007-07-29  1:10                 ` Junio C Hamano [this message]
2007-07-29 11:57                   ` [PATCH 1/3] log_ref_write() -- do not chomp reflog message at the first LF Johannes Schindelin
2007-07-29 18:47                     ` Junio C Hamano
2007-07-29 19:02                       ` Johannes Schindelin
2007-07-29  1:10                 ` [PATCH 2/3] symbolic-ref, update-ref: do not refuse reflog message with LF Junio C Hamano
2007-07-29  1:11                 ` [PATCH 3/3] rebase: try not to munge commit log message Junio C Hamano
2007-07-28 14:32           ` git-svn rebase screwing up commit messages Jakub Narebski
2007-07-28 19:48           ` Robin Rosenberg
2007-07-28 17:33       ` Benoit SIGOURE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vvec4nhfk.fsf_-_@assigned-by-dhcp.cox.net \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=seanlkml@sympatico.ca \
    --cc=tsuna@lrde.epita.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.