Quote LF in urls git fetch saves in FETCH_HEAD
The fmt-merge-msg does a strong syntax checking of its input and fails with if it is incorrect. The LF character is the only character important for fmt-merge-msg. As the url in FETCH_HEAD plays only informational role, a quoted representation of the url should be good and true enough. The url often comes from either user-editable config or command line, so it is reasonable to expect all kinds of characters in it, including the characters which the format of FETCH_HEAD considers special (line separator in this case). Noticed and reported by Hugo Mildenberger. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alex Riesen committed
May 13, 2009 at 20:08 UTC
95405ba6cf7adeaa4a066e8a3a1b76b73f7b9341
1 file changed
+8
-2
builtin-fetch.c
+8
-2
@@ -353,12 +353,18 @@ static int store_updated_refs(const char *url, const char *remote_name,
353
kind);
354
note_len += sprintf(note + note_len, "'%s' of ", what);
355
}
356
- note_len += sprintf(note + note_len, "%.*s", url_len, url);
357
- fprintf(fp, "%s\t%s\t%s\n",
356
+ note[note_len] = '\0';
357
+ fprintf(fp, "%s\t%s\t%s",
358
sha1_to_hex(commit ? commit->object.sha1 :
359
rm->old_sha1),
360
rm->merge ? "" : "not-for-merge",
361
note);
362
+ for (i = 0; i < url_len; ++i)
363
+ if ('\n' == url[i])
364
+ fputs("\\n", fp);
365
+ else
366
+ fputc(url[i], fp);
367
+ fputc('\n', fp);
368
369
if (ref)
370
rc |= update_local_ref(ref, what, note);