Skip to contentSkip to conversation

for-each-ref: Fix --format=%(subject) for log message without newlines

PATCH New Johan Herland 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 for-each-ref: Fix --format=%(subject) for log message without newlines

'git for-each-ref --format=%(subject)' currently returns an empty string if the log message does not contain a newline.

This patch teaches 'git for-each-ref' to return the entire log message (instead of an empty string) if there is no newline in the log message.

---

Normally, log messages in git have trailing newlines. However, it seems the "tag fixup commits" manufactured by cvs2svn/cvs2git (via git-fast-import) have single-line log message without trailing newlines.

I have checked the other callers of copy_line(), and AFAICS they are not affected by this change, since that would violate the git object format.

Have fun! :)

...Johan

 builtin-for-each-ref.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
builtin-for-each-ref.c +2 -2
index 9b44092..e59bd80 100644
@@ -321,8 +321,8 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un
 static const char *copy_line(const char *buf)
 {
 	const char *eol = strchr(buf, '\n');
-	if (!eol)
-		return "";
+	if (!eol) // simulate strchrnul()
+		eol = buf + strlen(buf);
 	return xmemdupz(buf, eol - buf);
 }
 
Signature · 1 line
1.6.0.2.463.g7f0eb