Skip to content

Commit ac4b0cf

Browse files
author
Junio C Hamano
committed
[PATCH] Start adding the $GIT_DIR/remotes/ support.
All the necessary parsing code is in git-parse-remote-script; update git-push-script to use it. Signed-off-by: Junio C Hamano <[email protected]>
1 parent d998a08 commit ac4b0cf

File tree

3 files changed

+151
-23
lines changed

3 files changed

+151
-23
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ SCRIPTS=git git-apply-patch-script git-merge-one-file-script git-prune-script \
6464
git-reset-script git-add-script git-checkout-script git-clone-script \
6565
gitk git-cherry git-rebase-script git-relink-script git-repack-script \
6666
git-format-patch-script git-sh-setup-script git-push-script \
67-
git-branch-script git-parse-remote git-verify-tag-script \
67+
git-branch-script git-parse-remote git-parse-remote-script git-verify-tag-script \
6868
git-ls-remote-script git-clone-dumb-http git-rename-script \
6969
git-request-pull-script git-bisect-script
7070

git-parse-remote-script

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/bin/sh
2+
3+
. git-sh-setup-script || die "Not a git archive"
4+
5+
get_data_source () {
6+
case "$1" in
7+
*/*)
8+
# Not so fast. This could be the partial URL shorthand...
9+
token=$(expr "$1" : '\([^/]*\)/')
10+
remainder=$(expr "$1" : '[^/]*/\(.*\)')
11+
if test -f "$GIT_DIR/branches/$token"
12+
then
13+
echo branches-partial
14+
else
15+
echo ''
16+
fi
17+
;;
18+
*)
19+
if 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+
remotes)
37+
sed -ne '/^URL: */{
38+
s///p
39+
q
40+
}' "$GIT_DIR/remotes/$1" ;;
41+
branches)
42+
sed -e 's/#.*//' "$GIT_DIR/branches/$1" ;;
43+
branches-partial)
44+
token=$(expr "$1" : '\([^/]*\)/')
45+
remainder=$(expr "$1" : '[^/]*/\(.*\)')
46+
url=$(sed -e 's/#.*//' "$GIT_DIR/branches/$token")
47+
echo "$url/$remainder"
48+
;;
49+
*)
50+
die "internal error: get-remote-url $1" ;;
51+
esac
52+
}
53+
54+
get_remote_default_refs_for_push () {
55+
data_source=$(get_data_source "$1")
56+
case "$data_source" in
57+
'' | branches | branches-partial)
58+
;; # no default push mapping, just send matching refs.
59+
remotes)
60+
sed -ne '/^Push: */{
61+
s///p
62+
}' "$GIT_DIR/remotes/$1" ;;
63+
*)
64+
die "internal error: get-remote-default-ref-for-push $1" ;;
65+
esac
66+
}
67+
68+
# Subroutine to canonicalize remote:local notation
69+
canon_refs_list_for_fetch () {
70+
for ref
71+
do
72+
expr "$ref" : '.*:' >/dev/null || ref="${ref}:"
73+
remote=$(expr "$ref" : '\([^:]*\):')
74+
local=$(expr "$ref" : '[^:]*:\(.*\)')
75+
case "$remote" in
76+
'') remote=HEAD ;;
77+
*) remote="refs/heads/$remote" ;;
78+
esac
79+
case "$local" in
80+
'') local= ;;
81+
*) local="refs/heads/$local" ;;
82+
esac
83+
echo "${remote}:${local}"
84+
done
85+
}
86+
87+
# Returns list of src: (no store), or src:dst (store)
88+
get_remote_default_refs_for_fetch () {
89+
data_source=$(get_data_source "$1")
90+
case "$data_source" in
91+
'' | branches-partial)
92+
echo "HEAD:" ;;
93+
branches)
94+
remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
95+
case "$remote_branch" in '') remote_branch=master ;; esac
96+
echo "refs/heads/${remote_branch}:refs/heads/$1"
97+
;;
98+
remotes)
99+
canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
100+
s///p
101+
}' "$GIT_DIR/remotes/$1")
102+
;;
103+
*)
104+
die "internal error: get-remote-default-ref-for-push $1" ;;
105+
esac
106+
}
107+
108+
get_remote_refs_for_push () {
109+
case "$#" in
110+
0) die "internal error: get-remote-refs-for-push." ;;
111+
1) get_remote_default_refs_for_push "$@" ;;
112+
*) shift; echo "$@" ;;
113+
esac
114+
}
115+
116+
get_remote_refs_for_fetch () {
117+
case "$#" in
118+
0)
119+
die "internal error: get-remote-refs-for-fetch." ;;
120+
1)
121+
get_remote_default_refs_for_fetch "$@" ;;
122+
*)
123+
shift
124+
tag_just_seen=
125+
for ref
126+
do
127+
if test "$tag_just_seen"
128+
then
129+
echo "refs/tags/${ref}:refs/tags/${ref}"
130+
tag_just_seen=
131+
continue
132+
else
133+
case "$ref" in
134+
tag)
135+
tag_just_seen=yes
136+
continue
137+
;;
138+
esac
139+
fi
140+
canon_refs_list_for_fetch "$ref"
141+
done
142+
;;
143+
esac
144+
}

git-push-script

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,20 @@ do
2020
-*)
2121
die "Unknown parameter $1" ;;
2222
*)
23-
remote="$1"
24-
shift
2523
set x "$@"
2624
shift
2725
break ;;
2826
esac
2927
shift
3028
done
3129

32-
case "$remote" in
33-
*:* | /* | ../* | ./* )
34-
# An URL, host:/path/to/git, absolute and relative paths.
35-
;;
36-
* )
37-
# Shorthand
38-
if expr "$remote" : '..*/..*' >/dev/null
39-
then
40-
# a short-hand followed by a trailing path
41-
shorthand=$(expr "$remote" : '\([^/]*\)')
42-
remainder=$(expr "$remote" : '[^/]*\(/.*\)$')
43-
else
44-
shorthand="$remote"
45-
remainder=
46-
fi
47-
remote=$(sed -e 's/#.*//' "$GIT_DIR/branches/$remote") &&
48-
expr "$remote" : '..*:' >/dev/null &&
49-
remote="$remote$remainder" ||
50-
die "Cannot parse remote $remote"
51-
;;
30+
. git-parse-remote-script
31+
remote=$(get_remote_url "$@")
32+
case "$has_all" in
33+
--all) set x ;;
34+
'') set x $(get_remote_refs_for_push "$@") ;;
5235
esac
36+
shift
5337

5438
case "$remote" in
5539
http://* | https://* | git://* | rsync://* )

0 commit comments

Comments
 (0)