From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 2/5] Teach 'git config' to rewrite URLs according to current url.*.insteadOf rules
Date: Mon, 04 Aug 2008 01:01:01 +0200 [thread overview]
Message-ID: <200808040101.01082.johan@herland.net> (raw)
In-Reply-To: <200808040057.00221.johan@herland.net>
This patch adds the --rewrite-url option to 'git config'. The option takes
exactly one argument; a URL that is to be rewritten according to the longest
matching url.*.insteadOf rule in the current config. The resulting URL is
printed on stdout, and 0 is returned.
The rationale for this patch is to enable access to Git's URL rewriting
functionality from shell scripts.
The URL rewriting functionality is implemented by piggybacking on the
existing URL rewriting code in remote.c.
Signed-off-by: Johan Herland <johan@herland.net>
---
builtin-config.c | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index 91fdc49..977e6cb 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -1,9 +1,10 @@
#include "builtin.h"
#include "cache.h"
#include "color.h"
+#include "remote.h"
static const char git_config_set_usage[] =
-"git config [ --global | --system | [ -f | --file ] config-file ] [ --bool | --int | --bool-or-int ] [ -z | --null ]
[--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list | --get-color
var [default] | --get-colorbool name [stdout-is-tty]";
+"git config [ --global | --system | [ -f | --file ] config-file ] [ --bool | --int | --bool-or-int ] [ -z | --null ]
[--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list | --get-color
var [default] | --get-colorbool name [stdout-is-tty] | --rewrite-url url";
static char *key;
static regex_t *key_regexp;
@@ -281,6 +282,24 @@ static int get_colorbool(int argc, const char **argv)
}
}
+static int rewrite_url(int argc, const char **argv)
+{
+ /*
+ * git config --rewrite_url <url>
+ *
+ * returns <url> after rewriting it according to url.*.insteadOf rules.
+ */
+
+ if (argc > 1)
+ usage(git_config_set_usage);
+
+ struct remote *remote = remote_get(argv[0]);
+ if (remote->url_nr != 1)
+ die("Expected exactly one URL from remote_get()!");
+ printf("%s\n", remote->url[0]);
+ return 0;
+}
+
int cmd_config(int argc, const char **argv, const char *prefix)
{
int nongit;
@@ -362,6 +381,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
return get_color(argc-2, argv+2);
} else if (!strcmp(argv[1], "--get-colorbool")) {
return get_colorbool(argc-2, argv+2);
+ } else if (!strcmp(argv[1], "--rewrite-url")) {
+ return rewrite_url(argc-2, argv+2);
} else
break;
argc--;
--
1.6.0.rc1.34.g0fe8c
next prev parent reply other threads:[~2008-08-03 23:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-03 22:57 [PATCH 0/5] Fix 'url.*.insteadOf' for submodule URLs Johan Herland
2008-08-03 23:00 ` [PATCH 1/5] Add testcase for 'git submodule' with url.*.insteadOf set in the super-repo Johan Herland
2008-08-03 23:04 ` [PATCH 1/5 v2] " Johan Herland
2008-08-03 23:01 ` Johan Herland [this message]
2008-08-03 23:02 ` [PATCH 3/5] Add selftest for new option '--rewrite-url' to 'git config' Johan Herland
2008-08-03 23:02 ` [PATCH 4/5] Add documentation on the new --rewrite-url option " Johan Herland
2008-08-03 23:02 ` [PATCH 5/5] Teach 'git submodule' to rewrite submodule URLs according to super-repo's rules Johan Herland
2008-08-03 23:27 ` [PATCH 0/5] Fix 'url.*.insteadOf' for submodule URLs Johannes Schindelin
2008-08-03 23:47 ` Johan Herland
2008-08-04 2:06 ` Junio C Hamano
2008-08-04 7:52 ` Johan Herland
2008-08-03 23:57 ` Junio C Hamano
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=200808040101.01082.johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.