[PATCH 3/4] credential: convert url attribute into its parsed subparts

2012-07-18 Thread Jeff King
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 p...@peff.net
---
The implementation turned out to be delightfully simple. I stopped short
of adding an ident command to git-credential where you could do
something like:

  $ echo https://u...@example.com | git credential ident
  protocol=https
  host=example.com
  username=user

since I had no use for it, but it would obviously be an easy one-liner
to write (it's just fill without the actual fill call).

 Documentation/git-credential.txt | 12 
 credential.c |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/Documentation/git-credential.txt b/Documentation/git-credential.txt
index afd5365..53adee3 100644
--- a/Documentation/git-credential.txt
+++ b/Documentation/git-credential.txt
@@ -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.
diff --git a/credential.c b/credential.c
index 2c40007..e54753c 100644
--- a/credential.c
+++ b/credential.c
@@ -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
-- 
1.7.10.5.40.g059818d

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/4] credential: convert url attribute into its parsed subparts

2012-07-18 Thread Matthieu Moy
Jeff King p...@peff.net writes:

   $ echo https://u...@example.com | git credential ident
   protocol=https
   host=example.com
   username=user

 since I had no use for it, but it would obviously be an easy one-liner
 to write (it's just fill without the actual fill call).

I was thinking the same, except I would have spelled it git credential
parse (but ident is fine too). On the perl side, that would allow
getting a credential hash very simply (but it was already simple in
perl, and made useless by your code).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/4] credential: convert url attribute into its parsed subparts

2012-07-18 Thread Jeff King
On Wed, Jul 18, 2012 at 02:24:01PM +0200, Matthieu Moy wrote:

 Jeff King p...@peff.net writes:
 
$ echo https://u...@example.com | git credential ident
protocol=https
host=example.com
username=user
 
  since I had no use for it, but it would obviously be an easy one-liner
  to write (it's just fill without the actual fill call).
 
 I was thinking the same, except I would have spelled it git credential
 parse (but ident is fine too). On the perl side, that would allow
 getting a credential hash very simply (but it was already simple in
 perl, and made useless by your code).

I wanted to give it some name that meant pass-through rather than just
parse, in case we add more magic attributes later. I meant ident to be
like mathematical identity, but in the context of a credential tool,
it is probably somewhat ambiguous. :)

Anyway, the fact that we can just do the parsing as part of the fill
means we don't need it for now, so I'll leave it until somebody really
cares.

-Peff
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html