git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Quote LF in urls git fetch saves in FETCH_HEAD

From
Alex Riesen <raa.lkml@gmail.com>
Date
May 12, 2009, 17:24 UTC
Message-ID
<20090512172452.GA32594@blimp.localdomain>
In-Reply-To
<81b0412b0905121018lbccda1fvf6c4c19417cdde00@mail.gmail.com>

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>
---
Alex Riesen, Tue, May 12, 2009 19:18:33 +0200:
Show 5 quoted lines
> 2009/5/12 Hugo Mildenberger <Hugo.Mildenberger@namir.de>:
> > hm@localhost /var/tmp/bluetooth-testing.git $ git pull
> > fatal: Error in line 2:
> 
> That's already fixed. Will send the fix in a minute.
Here
 builtin-fetch.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 3c998ea..eef7091 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -353,12 +353,17 @@ static int store_updated_refs(const char *url, const char *remote_name,
 						    kind);
 			note_len += sprintf(note + note_len, "'%s' of ", what);
 		}
-		note_len += sprintf(note + note_len, "%.*s", url_len, url);
-		fprintf(fp, "%s\t%s\t%s\n",
+		fprintf(fp, "%s\t%s\t%s",
 			sha1_to_hex(commit ? commit->object.sha1 :
 				    rm->old_sha1),
 			rm->merge ? "" : "not-for-merge",
 			note);
+		for (i = 0; i < url_len; ++i)
+			if ('\n' == url[i])
+				fputs("\\n", fp);
+			else
+				fputc(url[i], fp);
+		fputc('\n', fp);
 
 		if (ref)
 			rc |= update_local_ref(ref, what, note);
-- 
1.6.3.28.ga852b
Previous: Alex RiesenNext: Junio C Hamano
Message 9 of 30 in “git fails with control characters in trunk directory name”
  1. Hugo MildenbergerMay 11, 2009
  2. Alex RiesenMay 12, 2009
  3. Hugo MildenbergerMay 12, 2009
  4. Alex RiesenMay 12, 2009
  5. Hugo MildenbergerMay 12, 2009
  6. Alex RiesenMay 12, 2009
  7. Hugo MildenbergerMay 12, 2009
  8. Alex RiesenMay 12, 2009
  9. Quote LF in urls git fetch saves in FETCH_HEADAlex Riesen, May 12, 2009
  10. Junio C HamanoMay 12, 2009
  11. Alex RiesenMay 13, 2009
  12. Hugo MildenbergerMay 13, 2009
  13. Daniel BarkalowMay 13, 2009
  14. Alex RiesenMay 13, 2009
  15. Alex RiesenMay 13, 2009
  16. Daniel BarkalowMay 13, 2009
  17. Alex RiesenMay 13, 2009
  18. Junio C HamanoMay 13, 2009
  19. 1/2 Quote LF in urls git fetch saves in FETCH_HEADAlex Riesen, May 13, 2009
  20. 2/2 Improve the naming of guessed target repository for git cloneAlex Riesen, May 13, 2009
  21. Junio C HamanoMay 14, 2009
  22. Alex RiesenMay 14, 2009
  23. Junio C HamanoMay 14, 2009
  24. Alex RiesenMay 14, 2009
  25. Hugo MildenbergerMay 14, 2009
  26. Alex RiesenMay 14, 2009
  27. Junio C HamanoMay 16, 2009
  28. Alex RiesenMay 12, 2009
  29. Alex RiesenMay 13, 2009
  30. Hugo MildenbergerMay 13, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.