Merge branch 'jc/globfetch'
* jc/globfetch: fetch-pack: do not barf when duplicate re patterns are given git-fetch: allow forcing glob pattern in refspec git-fetch: allow glob pattern in refspec git-fetch: fix dumb protocol transport to fetch from pack-pruned ref git-fetch: reuse ls-remote result.
This commit is contained in:
commit
df6b7bfb71
25
fetch-pack.c
25
fetch-pack.c
@ -566,6 +566,29 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int remove_duplicates(int nr_heads, char **heads)
|
||||||
|
{
|
||||||
|
int src, dst;
|
||||||
|
|
||||||
|
for (src = dst = 0; src < nr_heads; src++) {
|
||||||
|
/* If heads[src] is different from any of
|
||||||
|
* heads[0..dst], push it in.
|
||||||
|
*/
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < dst; i++) {
|
||||||
|
if (!strcmp(heads[i], heads[src]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i < dst)
|
||||||
|
continue;
|
||||||
|
if (src != dst)
|
||||||
|
heads[dst] = heads[src];
|
||||||
|
dst++;
|
||||||
|
}
|
||||||
|
heads[dst] = 0;
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i, ret, nr_heads;
|
int i, ret, nr_heads;
|
||||||
@ -617,6 +640,8 @@ int main(int argc, char **argv)
|
|||||||
pid = git_connect(fd, dest, exec);
|
pid = git_connect(fd, dest, exec);
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
if (heads && nr_heads)
|
||||||
|
nr_heads = remove_duplicates(nr_heads, heads);
|
||||||
ret = fetch_pack(fd, nr_heads, heads);
|
ret = fetch_pack(fd, nr_heads, heads);
|
||||||
close(fd[0]);
|
close(fd[0]);
|
||||||
close(fd[1]);
|
close(fd[1]);
|
||||||
|
37
git-fetch.sh
37
git-fetch.sh
@ -88,6 +88,10 @@ then
|
|||||||
: >"$GIT_DIR/FETCH_HEAD"
|
: >"$GIT_DIR/FETCH_HEAD"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Global that is reused later
|
||||||
|
ls_remote_result=$(git ls-remote $upload_pack "$remote") ||
|
||||||
|
die "Cannot find the reflist at $remote"
|
||||||
|
|
||||||
append_fetch_head () {
|
append_fetch_head () {
|
||||||
head_="$1"
|
head_="$1"
|
||||||
remote_="$2"
|
remote_="$2"
|
||||||
@ -233,10 +237,7 @@ reflist=$(get_remote_refs_for_fetch "$@")
|
|||||||
if test "$tags"
|
if test "$tags"
|
||||||
then
|
then
|
||||||
taglist=`IFS=" " &&
|
taglist=`IFS=" " &&
|
||||||
(
|
echo "$ls_remote_result" |
|
||||||
git-ls-remote $upload_pack --tags "$remote" ||
|
|
||||||
echo fail ouch
|
|
||||||
) |
|
|
||||||
while read sha1 name
|
while read sha1 name
|
||||||
do
|
do
|
||||||
case "$sha1" in
|
case "$sha1" in
|
||||||
@ -245,6 +246,8 @@ then
|
|||||||
esac
|
esac
|
||||||
case "$name" in
|
case "$name" in
|
||||||
*^*) continue ;;
|
*^*) continue ;;
|
||||||
|
refs/tags/*) ;;
|
||||||
|
*) continue ;;
|
||||||
esac
|
esac
|
||||||
if git-check-ref-format "$name"
|
if git-check-ref-format "$name"
|
||||||
then
|
then
|
||||||
@ -304,22 +307,20 @@ fetch_main () {
|
|||||||
"`git-repo-config --bool http.noEPSV`" = true ]; then
|
"`git-repo-config --bool http.noEPSV`" = true ]; then
|
||||||
noepsv_opt="--disable-epsv"
|
noepsv_opt="--disable-epsv"
|
||||||
fi
|
fi
|
||||||
max_depth=5
|
|
||||||
depth=0
|
# Find $remote_name from ls-remote output.
|
||||||
head="ref: $remote_name"
|
head=$(
|
||||||
while (expr "z$head" : "zref:" && expr $depth \< $max_depth) >/dev/null
|
IFS=' '
|
||||||
|
echo "$ls_remote_result" |
|
||||||
|
while read sha1 name
|
||||||
do
|
do
|
||||||
remote_name_quoted=$(@@PERL@@ -e '
|
test "z$name" = "z$remote_name" || continue
|
||||||
my $u = $ARGV[0];
|
echo "$sha1"
|
||||||
$u =~ s/^ref:\s*//;
|
break
|
||||||
$u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg;
|
|
||||||
print "$u";
|
|
||||||
' "$head")
|
|
||||||
head=$(curl -nsfL $curl_extra_args $noepsv_opt "$remote/$remote_name_quoted")
|
|
||||||
depth=$( expr \( $depth + 1 \) )
|
|
||||||
done
|
done
|
||||||
|
)
|
||||||
expr "z$head" : "z$_x40\$" >/dev/null ||
|
expr "z$head" : "z$_x40\$" >/dev/null ||
|
||||||
die "Failed to fetch $remote_name from $remote"
|
die "No such ref $remote_name at $remote"
|
||||||
echo >&2 "Fetching $remote_name from $remote using $proto"
|
echo >&2 "Fetching $remote_name from $remote using $proto"
|
||||||
git-http-fetch -v -a "$head" "$remote/" || exit
|
git-http-fetch -v -a "$head" "$remote/" || exit
|
||||||
;;
|
;;
|
||||||
@ -432,7 +433,7 @@ case "$no_tags$tags" in
|
|||||||
# effective only when we are following remote branch
|
# effective only when we are following remote branch
|
||||||
# using local tracking branch.
|
# using local tracking branch.
|
||||||
taglist=$(IFS=" " &&
|
taglist=$(IFS=" " &&
|
||||||
git-ls-remote $upload_pack --tags "$remote" |
|
echo "$ls_remote_result" |
|
||||||
sed -n -e 's|^\('"$_x40"'\) \(refs/tags/.*\)^{}$|\1 \2|p' \
|
sed -n -e 's|^\('"$_x40"'\) \(refs/tags/.*\)^{}$|\1 \2|p' \
|
||||||
-e 's|^\('"$_x40"'\) \(refs/tags/.*\)$|\1 \2|p' |
|
-e 's|^\('"$_x40"'\) \(refs/tags/.*\)$|\1 \2|p' |
|
||||||
while read sha1 name
|
while read sha1 name
|
||||||
|
@ -90,6 +90,43 @@ get_remote_default_refs_for_push () {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Called from canon_refs_list_for_fetch -d "$remote", which
|
||||||
|
# is called from get_remote_default_refs_for_fetch to grok
|
||||||
|
# refspecs that are retrieved from the configuration, but not
|
||||||
|
# from get_remote_refs_for_fetch when it deals with refspecs
|
||||||
|
# supplied on the command line. $ls_remote_result has the list
|
||||||
|
# of refs available at remote.
|
||||||
|
expand_refs_wildcard () {
|
||||||
|
for ref
|
||||||
|
do
|
||||||
|
lref=${ref#'+'}
|
||||||
|
# a non glob pattern is given back as-is.
|
||||||
|
expr "z$lref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev/null || {
|
||||||
|
echo "$ref"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
from=`expr "z$lref" : 'z\(refs/.*/\)\*:refs/.*/\*$'`
|
||||||
|
to=`expr "z$lref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'`
|
||||||
|
local_force=
|
||||||
|
test "z$lref" = "z$ref" || local_force='+'
|
||||||
|
echo "$ls_remote_result" |
|
||||||
|
(
|
||||||
|
IFS=' '
|
||||||
|
while read sha1 name
|
||||||
|
do
|
||||||
|
mapped=${name#"$from"}
|
||||||
|
if test "z$name" != "z${name#'^{}'}" ||
|
||||||
|
test "z$name" = "z$mapped"
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "${local_force}${name}:${to}${mapped}"
|
||||||
|
done
|
||||||
|
)
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Subroutine to canonicalize remote:local notation.
|
# Subroutine to canonicalize remote:local notation.
|
||||||
canon_refs_list_for_fetch () {
|
canon_refs_list_for_fetch () {
|
||||||
# If called from get_remote_default_refs_for_fetch
|
# If called from get_remote_default_refs_for_fetch
|
||||||
@ -107,6 +144,8 @@ canon_refs_list_for_fetch () {
|
|||||||
merge_branches=$(git-repo-config \
|
merge_branches=$(git-repo-config \
|
||||||
--get-all "branch.${curr_branch}.merge")
|
--get-all "branch.${curr_branch}.merge")
|
||||||
fi
|
fi
|
||||||
|
set x $(expand_refs_wildcard "$@")
|
||||||
|
shift
|
||||||
fi
|
fi
|
||||||
for ref
|
for ref
|
||||||
do
|
do
|
||||||
|
Loading…
Reference in New Issue
Block a user