From: Jeff King <peff@peff.net>
To: Matthieu Moy <Matthieu.Moy@imag.fr>
Cc: git@vger.kernel.org
Subject: [PATCH 3/4] credential: convert "url" attribute into its parsed subparts
Date: Wed, 18 Jul 2012 08:06:26 -0400 [thread overview]
Message-ID: <20120718120626.GC6726@sigill.intra.peff.net> (raw)
In-Reply-To: <20120718120307.GA6399@sigill.intra.peff.net>
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>
---
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://user@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
next prev parent reply other threads:[~2012-07-18 12:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 12:03 [PATCH 0/4] mediawiki/credential cleanups Jeff King
2012-07-18 12:04 ` [PATCH 1/4] docs/credential: minor clarity fixups Jeff King
2012-07-18 12:04 ` [PATCH 2/4] mw-to-git: check blank credential attributes via length Jeff King
2012-07-18 12:06 ` Jeff King [this message]
2012-07-18 12:24 ` [PATCH 3/4] credential: convert "url" attribute into its parsed subparts Matthieu Moy
2012-07-18 12:25 ` Jeff King
2012-07-18 12:06 ` [PATCH 4/4] mw-to-git: use git-credential's URL parser Jeff King
2012-07-18 12:24 ` Matthieu Moy
2012-07-18 12:28 ` Jeff King
2012-07-18 12:37 ` Matthieu Moy
2012-07-18 12:57 ` Jeff King
2012-07-18 13:03 ` [PATCHv2 " Jeff King
2012-07-18 13:06 ` Matthieu Moy
2012-07-18 13:05 ` [PATCH " Matthieu Moy
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120718120626.GC6726@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Matthieu.Moy@imag.fr \
--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.
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 NNTP newsgroup(s).