git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] get_remote_url(): use the same data source as ls-remote to get remote urls

From
Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date
Mar 1, 2011, 09:21 UTC
Message-ID
<1298971297-20326-1-git-send-email-u.kleine-koenig@pengutronix.de>
In-Reply-To
<20110301084110.GT22310@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.

This removes the last user of git-parse-remote.sh:get_data_source(), so this function is removed.

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

compared with the previous patch this patch removes get_data_source which is unused now. The second patch also gets rid of get_remote_url.

 builtin/ls-remote.c |   11 +++++++++++
 git-parse-remote.sh |   48 +-----------------------------------------------
 2 files changed, 12 insertions(+), 47 deletions(-)
The changes in this series are also available in the git repository at:
  git.pengutronix.de:/git/ukl/git.git ls-remote-in-get-remote-url
basing on commit 7ed863a85a6ce2c4ac4476848310b8f917ab41f9:
  Git 1.7.4 (2011-01-30 19:02:37 -0800)
Uwe Kleine-König (2):
      get_remote_url(): use the same data source as ls-remote to get remote urls
      git-request-pull: open-code the only invocation of get_remote_url

(Note: this pull request was generated using the new git-request-pull and using a remote with a slash \o/)

 builtin/ls-remote.c |   11 +++++++++++
 git-parse-remote.sh |   50 --------------------------------------------------
 git-request-pull.sh |    3 +--
 3 files changed, 12 insertions(+), 52 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..0ab1192 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -4,54 +4,8 @@
 # this would fail in that case and would issue an error message.
 GIT_DIR=$(git rev-parse -q --git-dir) || :;
 
-get_data_source () {
-	case "$1" in
-	*/*)
-		echo ''
-		;;
-	.)
-		echo self
-		;;
-	*)
-		if test "$(git config --get "remote.$1.url")"
-		then
-			echo config
-		elif test -f "$GIT_DIR/remotes/$1"
-		then
-			echo remotes
-		elif test -f "$GIT_DIR/branches/$1"
-		then
-			echo branches
-		else
-			echo ''
-		fi ;;
-	esac
-}
-
 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
Previous: Uwe Kleine-KönigNext: Uwe Kleine-König
Message 7 of 8 in “bug: request-pull broken when remote name contains a slash”
  1. Uwe Kleine-KönigJan 14, 2011
  2. fix git-parse-remote.sh for remotes that contain slashesStefan Naewe, Jan 14, 2011
  3. Junio C HamanoJan 14, 2011
  4. get_remote_url(): use the same data source as ls-remote to get remote urlsUwe Kleine-König, Feb 28, 2011
  5. Junio C HamanoFeb 28, 2011
  6. Uwe Kleine-KönigMar 1, 2011
  7. 1/2 get_remote_url(): use the same data source as ls-remote to get remote urlsUwe Kleine-König, Mar 1, 2011
  8. 2/2 git-request-pull: open-code the only invocation of get_remote_urlUwe Kleine-König, Mar 1, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.