summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8a8169c)
raw | patch | inline | side by side (parent: 8a8169c)
author | Junio C Hamano <junkio@cox.net> | |
Fri, 26 Jan 2007 10:26:04 +0000 (02:26 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 26 Jan 2007 10:26:04 +0000 (02:26 -0800) |
The file format dictates that entries are LF terminated so
the message cannot have one in it. Chomp the message to make
sure it only has a single line if necessary, while removing the
leading whitespace.
Signed-off-by: Junio C Hamano <junkio@cox.net>
the message cannot have one in it. Chomp the message to make
sure it only has a single line if necessary, while removing the
leading whitespace.
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-update-ref.c | patch | blob | history | |
refs.c | patch | blob | history |
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index b34e5987dd256e0b7d9fae46fe89f66dd18ad91f..f2506fa9762bd9d868076710f38dfc9137186828 100644 (file)
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
msg = argv[++i];
if (!*msg)
die("Refusing to perform update with empty message.");
- if (strchr(msg, '\n'))
- die("Refusing to perform update with \\n in message.");
continue;
}
if (!strcmp("-d", argv[i])) {
index 4323e9a41a6c2f4fe7f0dba4b53e083bd8576d50..0840b3bab8b404f9480df89447a497963b7117fb 100644 (file)
--- a/refs.c
+++ b/refs.c
{
int logfd, written, oflags = O_APPEND | O_WRONLY;
unsigned maxlen, len;
+ int msglen;
char *logrec;
const char *committer;
lock->log_file, strerror(errno));
}
- committer = git_committer_info(-1);
+ msglen = 0;
if (msg) {
- maxlen = strlen(committer) + strlen(msg) + 2*40 + 5;
- logrec = xmalloc(maxlen);
- len = snprintf(logrec, maxlen, "%s %s %s\t%s\n",
- sha1_to_hex(lock->old_sha1),
- sha1_to_hex(sha1),
- committer,
- msg);
- }
- else {
- maxlen = strlen(committer) + 2*40 + 4;
- logrec = xmalloc(maxlen);
- len = snprintf(logrec, maxlen, "%s %s %s\n",
- sha1_to_hex(lock->old_sha1),
- sha1_to_hex(sha1),
- committer);
+ /* 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);
+ }
}
+
+ committer = git_committer_info(-1);
+ maxlen = strlen(committer) + msglen + 100;
+ logrec = xmalloc(maxlen);
+ len = sprintf(logrec, "%s %s %s\n",
+ sha1_to_hex(lock->old_sha1),
+ sha1_to_hex(sha1),
+ committer);
+ if (msglen)
+ len += sprintf(logrec + len - 1, "\t%.*s\n", msglen, msg) - 1;
written = len <= maxlen ? write_in_full(logfd, logrec, len) : -1;
free(logrec);
close(logfd);