summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <junkio@cox.net>2006-11-28 23:07:20 -0800
committerLibravatar Junio C Hamano <junkio@cox.net>2006-11-28 23:07:20 -0800
commitdf6b7bfb719622af05f62656ea25435538c82e19 (patch)
tree316193a74e1c1e4aa9410747c21938bf8fee763d
parentMerge branch 'maint' (diff)
parentfetch-pack: do not barf when duplicate re patterns are given (diff)
downloadtgif-df6b7bfb719622af05f62656ea25435538c82e19.tar.xz
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.
-rw-r--r--fetch-pack.c25
-rwxr-xr-xgit-fetch.sh41
-rwxr-xr-xgit-parse-remote.sh39
3 files changed, 85 insertions, 20 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index 0a169dce85..743eab7efa 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -566,6 +566,29 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
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 i, ret, nr_heads;
@@ -617,6 +640,8 @@ int main(int argc, char **argv)
pid = git_connect(fd, dest, exec);
if (pid < 0)
return 1;
+ if (heads && nr_heads)
+ nr_heads = remove_duplicates(nr_heads, heads);
ret = fetch_pack(fd, nr_heads, heads);
close(fd[0]);
close(fd[1]);
diff --git a/git-fetch.sh b/git-fetch.sh
index 4425562098..4eecf148ea 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -88,6 +88,10 @@ then
: >"$GIT_DIR/FETCH_HEAD"
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 () {
head_="$1"
remote_="$2"
@@ -233,10 +237,7 @@ reflist=$(get_remote_refs_for_fetch "$@")
if test "$tags"
then
taglist=`IFS=" " &&
- (
- git-ls-remote $upload_pack --tags "$remote" ||
- echo fail ouch
- ) |
+ echo "$ls_remote_result" |
while read sha1 name
do
case "$sha1" in
@@ -245,6 +246,8 @@ then
esac
case "$name" in
*^*) continue ;;
+ refs/tags/*) ;;
+ *) continue ;;
esac
if git-check-ref-format "$name"
then
@@ -304,22 +307,20 @@ fetch_main () {
"`git-repo-config --bool http.noEPSV`" = true ]; then
noepsv_opt="--disable-epsv"
fi
- max_depth=5
- depth=0
- head="ref: $remote_name"
- while (expr "z$head" : "zref:" && expr $depth \< $max_depth) >/dev/null
- do
- remote_name_quoted=$(@@PERL@@ -e '
- my $u = $ARGV[0];
- $u =~ s/^ref:\s*//;
- $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
+
+ # Find $remote_name from ls-remote output.
+ head=$(
+ IFS=' '
+ echo "$ls_remote_result" |
+ while read sha1 name
+ do
+ test "z$name" = "z$remote_name" || continue
+ echo "$sha1"
+ break
+ done
+ )
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"
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
# using local tracking branch.
taglist=$(IFS=" " &&
- git-ls-remote $upload_pack --tags "$remote" |
+ echo "$ls_remote_result" |
sed -n -e 's|^\('"$_x40"'\) \(refs/tags/.*\)^{}$|\1 \2|p' \
-e 's|^\('"$_x40"'\) \(refs/tags/.*\)$|\1 \2|p' |
while read sha1 name
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index c325ef761e..19bc3857d1 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -90,6 +90,43 @@ get_remote_default_refs_for_push () {
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.
canon_refs_list_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 \
--get-all "branch.${curr_branch}.merge")
fi
+ set x $(expand_refs_wildcard "$@")
+ shift
fi
for ref
do