credential: convert "url" attribute into its parsed subparts
authorJeff King <peff@peff.net>
Wed, 18 Jul 2012 12:06:26 +0000 (08:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Jul 2012 20:26:58 +0000 (13:26 -0700)
The git-credential command requires that you feed it a
broken-down credential, which means that the client needs to
parse a URL itself. Since we have our own URL-parsing
routines, we can easily allow the caller to just give us the
URL as-is, saving them some code.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-credential.txt
credential.c

index afd53652556e9822533500bd7d5599beeacce177..53adee320361085a0f9bbc9f9da17f0d3db60d20 100644 (file)
@@ -140,3 +140,15 @@ Git understands the following attributes:
 `password`::
 
        The credential's password, if we are asking it to be stored.
+
+`url`::
+
+       When this special attribute is read by `git credential`, the
+       value is parsed as a URL and treated as if its constituent parts
+       were read (e.g., `url=https://example.com` would behave as if
+       `protocol=https` and `host=example.com` had been provided). This
+       can help callers avoid parsing URLs themselves.  Note that any
+       components which are missing from the URL (e.g., there is no
+       username in the example above) will be set to empty; if you want
+       to provide a URL and override some attributes, provide the URL
+       attribute first, followed by any overrides.
index 2c400073fac4dac5ba3a1e053733671659e039aa..e54753c75d1c2abf7916f1aa7075d4ada3cfc61f 100644 (file)
@@ -172,6 +172,8 @@ int credential_read(struct credential *c, FILE *fp)
                } else if (!strcmp(key, "path")) {
                        free(c->path);
                        c->path = xstrdup(value);
+               } else if (!strcmp(key, "url")) {
+                       credential_from_url(c, value);
                }
                /*
                 * Ignore other lines; we don't know what they mean, but