@matheusbsbs / matheus-bagliano / commits / 45781adb9a
Fork 0

get_remote_url(): use the same data source as ls-remote to get remote urls

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Uwe Kleine-König committed Mar 1, 2011 at 10:21 UTC 45781adb9a89c0c47f61ccf8062be26b86a38a54
2 files changed +12 -47
builtin/ls-remote.c
+11
@@ -33,6 +33,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
33 int i;
34 const char *dest = NULL;
35 unsigned flags = 0;
36 + int get_url = 0;
37 int quiet = 0;
38 const char *uploadpack = NULL;
39 const char **pattern = NULL;
@@ -69,6 +70,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
70 quiet = 1;
71 continue;
72 }
73 + if (!strcmp("--get-url", arg)) {
74 + get_url = 1;
75 + continue;
76 + }
77 usage(ls_remote_usage);
78 }
79 dest = arg;
@@ -94,6 +99,12 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
99 }
100 if (!remote->url_nr)
101 die("remote %s has no configured URL", dest);
102 +
103 + if (get_url) {
104 + printf("%s\n", *remote->url);
105 + return 0;
106 + }
107 +
108 transport = transport_get(remote, NULL);
109 if (uploadpack != NULL)
110 transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
git-parse-remote.sh
+1 -47
@@ -4,54 +4,8 @@
4 # this would fail in that case and would issue an error message.
5 GIT_DIR=$(git rev-parse -q --git-dir) || :;
6
7 -get_data_source () {
8 - case "$1" in
9 - */*)
10 - echo ''
11 - ;;
12 - .)
13 - echo self
14 - ;;
15 - *)
16 - if test "$(git config --get "remote.$1.url")"
17 - then
18 - echo config
19 - elif test -f "$GIT_DIR/remotes/$1"
20 - then
21 - echo remotes
22 - elif test -f "$GIT_DIR/branches/$1"
23 - then
24 - echo branches
25 - else
26 - echo ''
27 - fi ;;
28 - esac
29 -}
30 -
7 get_remote_url () {
32 - data_source=$(get_data_source "$1")
33 - case "$data_source" in
34 - '')
35 - echo "$1"
36 - ;;
37 - self)
38 - echo "$1"
39 - ;;
40 - config)
41 - git config --get "remote.$1.url"
42 - ;;
43 - remotes)
44 - sed -ne '/^URL: */{
45 - s///p
46 - q
47 - }' "$GIT_DIR/remotes/$1"
48 - ;;
49 - branches)
50 - sed -e 's/#.*//' "$GIT_DIR/branches/$1"
51 - ;;
52 - *)
53 - die "internal error: get-remote-url $1" ;;
54 - esac
8 + git ls-remote --get-url "$1"
9 }
10
11 get_default_remote () {