]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/globfetch'
authorJunio C Hamano <junkio@cox.net>
Wed, 29 Nov 2006 07:07:20 +0000 (23:07 -0800)
committerJunio C Hamano <junkio@cox.net>
Wed, 29 Nov 2006 07:07:20 +0000 (23:07 -0800)
* 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.

fetch-pack.c
git-fetch.sh
git-parse-remote.sh

index 0a169dce8574102a03c978bb24f8d0664f1fc9b6..743eab7efaa5b53a56d432bea268dda04350be7b 100644 (file)
@@ -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]);
index 44255620983fde6bdbcb7d75d8b1d10bf8db6583..4eecf148ea90c02bfe9f2aa018118ccbd26f8e97 100755 (executable)
@@ -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
index c325ef761e4c558ab5c7c560da942e127e1be040..19bc3857d17b74324edbad58156a3e3c85fe0497 100755 (executable)
@@ -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