git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Klaus Ethgen <Klaus@Ethgen.ch>
Cc: git@vger.kernel.org
Subject: Re: [BUG] Colon in remote urls
Date: Fri, 9 Dec 2016 10:22:19 -0500	[thread overview]
Message-ID: <20161209152219.ehfk475vdg4levop@sigill.intra.peff.net> (raw)
In-Reply-To: <20161209140215.qlam6bexm5irpro2@ikki.ethgen.ch>

On Fri, Dec 09, 2016 at 03:02:15PM +0100, Klaus Ethgen wrote:

> I have some repositories where I have a colon in the (local) url for a
> remote. That was no problem until now but with 2.11.0, I see the
> following problem:
>    ~> git push
>    Counting objects: 11, done.
>    Delta compression using up to 8 threads.
>    Compressing objects: 100% (10/10), done.
>    Writing objects: 100% (11/11), 1.26 KiB | 0 bytes/s, done.
>    Total 11 (delta 7), reused 0 (delta 0)
>    remote: error: object directory /home/xxx does not exist; check .git/objects/info/alternates.
>    remote: error: object directory yyy.git/objects does not exist; check .git/objects/info/alternates.
>    remote: fatal: unresolved deltas left after unpacking

Hrm. The problem v2.11's new object-quarantine system. The receiving
side of a push will write into a new temporary object directory, and
refer to the original with the GIT_ALTERNATE_OBJECT_DIRECTORIES
environment variable. But that variable splits its entries on ":", and
has no way of representing a path that includes a ":".

So I think the solution would probably be to introduce some kind of
quoting mechanism to that variable, so that it can pass through
arbitrary paths. Or alternatively use a separate variable, but that does
nothing to help other cases where somebody wants to use xxx:yyy.git as
an alternate.

(One other option is to just declare that the quarantine feature doesn't
work with colons in the pathname, but stop turning it on by default. I'm
not sure I like that, though).

Here's a rough idea of what the quoting solution could look like. It
should make your case work, but I'm not sure what we want to do about
backwards-compatibility, if anything.

---
 sha1_file.c  | 41 ++++++++++++++++++++++++++++++-----------
 tmp-objdir.c | 18 ++++++++++++++++--
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 9c86d1924..a0b341b5a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -329,13 +329,35 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
 	return 0;
 }
 
+const char *parse_alt_odb_entry(const char *string, int sep,
+				struct strbuf *out)
+{
+	const char *p;
+	int literal = 0;
+
+	strbuf_reset(out);
+
+	for (p = string; *p; p++) {
+		if (literal) {
+			strbuf_addch(out, *p);
+			literal = 0;
+		} else {
+			if (*p == '\\')
+				literal = 1;
+			else if (*p == sep)
+				return p + 1;
+			else
+				strbuf_addch(out, *p);
+		}
+	}
+	return p;
+}
+
 static void link_alt_odb_entries(const char *alt, int len, int sep,
 				 const char *relative_base, int depth)
 {
-	struct string_list entries = STRING_LIST_INIT_NODUP;
-	char *alt_copy;
-	int i;
 	struct strbuf objdirbuf = STRBUF_INIT;
+	struct strbuf entry = STRBUF_INIT;
 
 	if (depth > 5) {
 		error("%s: ignoring alternate object stores, nesting too deep.",
@@ -348,16 +370,13 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
 		die("unable to normalize object directory: %s",
 		    objdirbuf.buf);
 
-	alt_copy = xmemdupz(alt, len);
-	string_list_split_in_place(&entries, alt_copy, sep, -1);
-	for (i = 0; i < entries.nr; i++) {
-		const char *entry = entries.items[i].string;
-		if (entry[0] == '\0' || entry[0] == '#')
+	while (*alt) {
+		alt = parse_alt_odb_entry(alt, sep, &entry);
+		if (!entry.len || entry.buf[0] == '#')
 			continue;
-		link_alt_odb_entry(entry, relative_base, depth, objdirbuf.buf);
+		link_alt_odb_entry(entry.buf, relative_base, depth, objdirbuf.buf);
 	}
-	string_list_clear(&entries, 0);
-	free(alt_copy);
+	strbuf_release(&entry);
 	strbuf_release(&objdirbuf);
 }
 
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 64435f23a..900e15af1 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -70,6 +70,17 @@ static void remove_tmp_objdir_on_signal(int signo)
 	raise(signo);
 }
 
+static char *backslash_quote(const char *s, int delim)
+{
+	struct strbuf buf = STRBUF_INIT;
+	while (*s) {
+		if (*s == '\\' || *s == delim)
+			strbuf_addch(&buf, '\\');
+		strbuf_addch(&buf, *s++);
+	}
+	return strbuf_detach(&buf, NULL);
+}
+
 /*
  * These env_* functions are for setting up the child environment; the
  * "replace" variant overrides the value of any existing variable with that
@@ -79,12 +90,15 @@ static void remove_tmp_objdir_on_signal(int signo)
  */
 static void env_append(struct argv_array *env, const char *key, const char *val)
 {
+	char *quoted = backslash_quote(val, PATH_SEP);
 	const char *old = getenv(key);
 
 	if (!old)
-		argv_array_pushf(env, "%s=%s", key, val);
+		argv_array_pushf(env, "%s=%s", key, quoted);
 	else
-		argv_array_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, val);
+		argv_array_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, quoted);
+
+	free(quoted);
 }
 
 static void env_replace(struct argv_array *env, const char *key, const char *val)
-- 
2.11.0.201.g51bd297


  reply	other threads:[~2016-12-09 15:22 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-09 14:02 [BUG] Colon in remote urls Klaus Ethgen
2016-12-09 15:22 ` Jeff King [this message]
2016-12-09 19:07   ` Junio C Hamano
2016-12-10  8:51     ` Jeff King
2016-12-12 19:49       ` [PATCH 0/2] handling alternates paths with colons Jeff King
2016-12-12 19:52         ` [PATCH 1/2] alternates: accept double-quoted paths Jeff King
2016-12-13 11:30           ` Duy Nguyen
2016-12-13 11:52             ` Jeff King
2016-12-13 18:08             ` Junio C Hamano
2016-12-17  7:56               ` Duy Nguyen
2016-12-12 19:53         ` [PATCH 2/2] tmp-objdir: quote paths we add to alternates Jeff King
2016-12-12 20:53           ` Johannes Sixt
2016-12-13 11:44             ` Jeff King
2016-12-13 18:10               ` Junio C Hamano
2016-12-13 18:15                 ` Jeff King
2016-12-13 20:10                   ` Junio C Hamano
2016-12-13 19:09           ` [PATCH 3/2] t5547-push-quarantine: run the path separator test on Windows, too Johannes Sixt
2016-12-13 19:12             ` Jeff King
2016-12-13 19:23             ` Junio C Hamano
2016-12-21 21:33             ` [PATCH 4/2] t5615-alternate-env: double-quotes in file names do not work on Windows Johannes Sixt
2016-12-21 22:42               ` Jeff King
2016-12-22  6:13                 ` Johannes Sixt
2016-12-22 19:06                   ` Johannes Sixt
2016-12-22 21:38                     ` Johannes Schindelin
2016-12-22 22:19                     ` Jeff King
2016-12-12 22:37         ` [PATCH 0/2] handling alternates paths with colons Junio C Hamano
2016-12-13 11:50           ` Jeff King
2016-12-13 18:10             ` Junio C Hamano
2016-12-13 18:17               ` Jeff King
2016-12-13 18:42                 ` Junio C Hamano
2016-12-13 18:47                   ` Jeff King
2016-12-10  9:29     ` [BUG] Colon in remote urls Klaus Ethgen
2016-12-10 10:24       ` Jeff King
2016-12-10 10:46         ` Klaus Ethgen
2016-12-09 21:32   ` Johannes Sixt
2016-12-10  8:26     ` Jeff King
2016-12-10  9:41       ` Klaus Ethgen
2016-12-10 10:26         ` Jeff King
2016-12-10 10:51           ` Klaus Ethgen
2016-12-10  9:32     ` Klaus Ethgen
2016-12-10 18:18       ` Johannes Schindelin
2016-12-11 11:02         ` Klaus Ethgen
2016-12-11 14:51           ` Philip Oakley
2016-12-12 11:03           ` Johannes Schindelin
2016-12-12 11:50             ` Klaus Ethgen
2016-12-12 14:05               ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161209152219.ehfk475vdg4levop@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Klaus@Ethgen.ch \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).