Skip to content

Commit 32b31ab

Browse files
committed
Merge branch 'uk/ls-remote-in-get-remote-url'
* uk/ls-remote-in-get-remote-url: git-request-pull: open-code the only invocation of get_remote_url get_remote_url(): use the same data source as ls-remote to get remote urls
2 parents 9d59e66 + 1a92777 commit 32b31ab

File tree

3 files changed

+12
-52
lines changed

3 files changed

+12
-52
lines changed

builtin/ls-remote.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
3333
int i;
3434
const char *dest = NULL;
3535
unsigned flags = 0;
36+
int get_url = 0;
3637
int quiet = 0;
3738
const char *uploadpack = NULL;
3839
const char **pattern = NULL;
@@ -69,6 +70,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
6970
quiet = 1;
7071
continue;
7172
}
73+
if (!strcmp("--get-url", arg)) {
74+
get_url = 1;
75+
continue;
76+
}
7277
usage(ls_remote_usage);
7378
}
7479
dest = arg;
@@ -94,6 +99,12 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
9499
}
95100
if (!remote->url_nr)
96101
die("remote %s has no configured URL", dest);
102+
103+
if (get_url) {
104+
printf("%s\n", *remote->url);
105+
return 0;
106+
}
107+
97108
transport = transport_get(remote, NULL);
98109
if (uploadpack != NULL)
99110
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);

git-parse-remote.sh

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,6 @@
44
# this would fail in that case and would issue an error message.
55
GIT_DIR=$(git rev-parse -q --git-dir) || :;
66

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-
31-
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
55-
}
56-
577
get_default_remote () {
588
curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
599
origin=$(git config --get "branch.$curr_branch.remote")

git-request-pull.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ p show patch text as well
1515
'
1616

1717
. git-sh-setup
18-
. git-parse-remote
1918

2019
GIT_PAGER=
2120
export GIT_PAGER
@@ -55,7 +54,7 @@ branch=$(git ls-remote "$url" \
5554
p
5655
q
5756
}")
58-
url=$(get_remote_url "$url")
57+
url=$(git ls-remote --get-url "$url")
5958
if [ -z "$branch" ]; then
6059
echo "warn: No branch of $url is at:" >&2
6160
git log --max-count=1 --pretty='tformat:warn: %h: %s' $headrev >&2

0 commit comments

Comments
 (0)