git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: git@vger.kernel.org
Cc: kernel@pengutronix.de
Subject: [PATCH] get_remote_url(): use the same data source as ls-remote to get remote urls
Date: Mon, 28 Feb 2011 10:36:19 +0100	[thread overview]
Message-ID: <1298885779-10045-1-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20110114090645.GA13060@pengutronix.de>

The formerly implemented algorithm behaved differently to
remote.c:remote_get() at least for remotes that contain a slash.  While the
former just assumes a/b is a path the latter checks the config for
remote."a/b" first which is more reasonable.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

with this patch git-request-pull.sh (== the only in-tree user of
git-parse-remote.sh:get_remote_url()) could directly use

	git ls-remote --get-url

.  I guess you wouldn't want to remove git-parse-remote.sh:get_remote_url()
though?!  Maybe add a deprecation warning to it?  The same applies to
git-parse-remote.sh:get_data_source() that isn't used anymore already with this
patch.

Best regards
Uwe

 builtin/ls-remote.c |   11 +++++++++++
 git-parse-remote.sh |   24 +-----------------------
 2 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 97eed40..1a1ff87 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -33,6 +33,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int i;
 	const char *dest = NULL;
 	unsigned flags = 0;
+	int get_url = 0;
 	int quiet = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
@@ -69,6 +70,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 				quiet = 1;
 				continue;
 			}
+			if (!strcmp("--get-url", arg)) {
+				get_url = 1;
+				continue;
+			}
 			usage(ls_remote_usage);
 		}
 		dest = arg;
@@ -94,6 +99,12 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	}
 	if (!remote->url_nr)
 		die("remote %s has no configured URL", dest);
+
+	if (get_url) {
+		printf("%s\n", *remote->url);
+		return 0;
+	}
+
 	transport = transport_get(remote, NULL);
 	if (uploadpack != NULL)
 		transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 1cc2ba6..4fb778e 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -29,29 +29,7 @@ get_data_source () {
 }
 
 get_remote_url () {
-	data_source=$(get_data_source "$1")
-	case "$data_source" in
-	'')
-		echo "$1"
-		;;
-	self)
-		echo "$1"
-		;;
-	config)
-		git config --get "remote.$1.url"
-		;;
-	remotes)
-		sed -ne '/^URL: */{
-			s///p
-			q
-		}' "$GIT_DIR/remotes/$1"
-		;;
-	branches)
-		sed -e 's/#.*//' "$GIT_DIR/branches/$1"
-		;;
-	*)
-		die "internal error: get-remote-url $1" ;;
-	esac
+	git ls-remote --get-url "$1"
 }
 
 get_default_remote () {
-- 
1.7.2.3

  parent reply	other threads:[~2011-02-28  9:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-14  9:06 bug: request-pull broken when remote name contains a slash Uwe Kleine-König
2011-01-14 11:36 ` [PATCH] fix git-parse-remote.sh for remotes that contain slashes Stefan Naewe
2011-01-14 19:55   ` Junio C Hamano
2011-02-28  9:36 ` Uwe Kleine-König [this message]
2011-02-28 23:38   ` [PATCH] get_remote_url(): use the same data source as ls-remote to get remote urls Junio C Hamano
2011-03-01  8:41     ` Uwe Kleine-König
2011-03-01  9:21       ` [PATCH 1/2] " Uwe Kleine-König
2011-03-01  9:21       ` [PATCH 2/2] git-request-pull: open-code the only invocation of get_remote_url Uwe Kleine-König

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=1298885779-10045-1-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=git@vger.kernel.org \
    --cc=kernel@pengutronix.de \
    /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).