summaryrefslogtreecommitdiff
path: root/src/refdb_fs.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-10-18 09:24:14 +0200
committerPatrick Steinhardt <ps@pks.im>2019-10-18 11:30:13 +0200
commitd8233feb78d10ade39fd64b85044fea84f2fc293 (patch)
treed66ddab59619060290d1a89b06bdac524ad5aa3c /src/refdb_fs.c
parent284816093ee733490d2129031cb2634b0ac61f6d (diff)
downloadlibgit2-d8233feb78d10ade39fd64b85044fea84f2fc293.tar.gz
reflog: allow adding entries with newlines in their message
Currently, the reflog disallows any entries that have a message with newlines, as that would effectively break the reflog format, which may contain a single line per entry, only. Upstream git behaves a bit differently, though, especially when considering stashes: instead of rejecting any reflog entry with newlines, git will simply replace newlines with spaces. E.g. executing 'git stash push -m "foo\nbar"' will create a reflog entry with "foo bar" as entry message. This commit adjusts our own logic to stop rejecting commit messages with newlines. Previously, this logic was part of `git_reflog_append`, only. There is a second place though where we add reflog entries, which is the serialization code in the filesystem refdb. As it didn't contain any sanity checks whatsoever, the refdb would have been perfectly happy to write malformatted reflog entries to the disk. This is being fixed with the same logic as for the reflog itself.
Diffstat (limited to 'src/refdb_fs.c')
-rw-r--r--src/refdb_fs.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index c48afb94f..449dedfba 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1856,8 +1856,15 @@ static int serialize_reflog_entry(
git_buf_rtrim(buf);
if (msg) {
+ size_t i;
+
git_buf_putc(buf, '\t');
git_buf_puts(buf, msg);
+
+ for (i = 0; i < buf->size - 2; i++)
+ if (buf->ptr[i] == '\n')
+ buf->ptr[i] = ' ';
+ git_buf_rtrim(buf);
}
git_buf_putc(buf, '\n');