Code

make git clone -q suppress the noise with http fetch
[git.git] / git-clone.sh
index 1531da52cb5c390bc11a3a10ffc0075fa2b59b9c..6ba477d1f4ee16c20e3fee7dd881f1645bcb80f1 100755 (executable)
@@ -42,6 +42,7 @@ clone_dumb_http () {
        http_fetch "$1/info/refs" "$clone_tmp/refs" ||
                die "Cannot get remote repository information.
 Perhaps git-update-server-info needs to be run there?"
+       test "z$quiet" = z && v=-v || v=
        while read sha1 refname
        do
                name=`expr "z$refname" : 'zrefs/\(.*\)'` &&
@@ -59,55 +60,13 @@ Perhaps git-update-server-info needs to be run there?"
                else
                        tname=$name
                fi
-               git-http-fetch -v -a -w "$tname" "$name" "$1/" || exit 1
+               git-http-fetch $v -a -w "$tname" "$name" "$1/" || exit 1
        done <"$clone_tmp/refs"
        rm -fr "$clone_tmp"
        http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
        rm -f "$GIT_DIR/REMOTE_HEAD"
 }
 
-# Read git-fetch-pack -k output and store the remote branches.
-copy_refs='
-use File::Path qw(mkpath);
-use File::Basename qw(dirname);
-my $git_dir = $ARGV[0];
-my $use_separate_remote = $ARGV[1];
-my $origin = $ARGV[2];
-
-my $branch_top = ($use_separate_remote ? "remotes/$origin" : "heads");
-my $tag_top = "tags";
-
-sub store {
-       my ($sha1, $name, $top) = @_;
-       $name = "$git_dir/refs/$top/$name";
-       mkpath(dirname($name));
-       open O, ">", "$name";
-       print O "$sha1\n";
-       close O;
-}
-
-open FH, "<", "$git_dir/CLONE_HEAD";
-while (<FH>) {
-       my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
-       next if ($name =~ /\^\173/);
-       if ($name eq "HEAD") {
-               open O, ">", "$git_dir/REMOTE_HEAD";
-               print O "$sha1\n";
-               close O;
-               next;
-       }
-       if ($name =~ s/^refs\/heads\///) {
-               store($sha1, $name, $branch_top);
-               next;
-       }
-       if ($name =~ s/^refs\/tags\///) {
-               store($sha1, $name, $tag_top);
-               next;
-       }
-}
-close FH;
-'
-
 quiet=
 local=no
 use_local=no
@@ -121,6 +80,8 @@ origin=
 origin_override=
 use_separate_remote=t
 depth=
+no_progress=
+test -t 1 || no_progress=--no-progress
 while
        case "$#,$1" in
        0,*) break ;;
@@ -165,7 +126,7 @@ while
                shift
                upload_pack="--upload-pack=$1" ;;
        *,--upload-pack=*)
-               upload_pack=--upload-pack=$(expr "$1" : '-[^=]*=\(.*\)') ;;
+               upload_pack=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
        1,--depth) usage;;
        *,--depth)
                shift
@@ -220,19 +181,32 @@ esac && export GIT_DIR && git-init ${template+"$template"} || usage
 
 if test -n "$reference"
 then
+       ref_git=
        if test -d "$reference"
        then
                if test -d "$reference/.git/objects"
                then
-                       reference="$reference/.git"
+                       ref_git="$reference/.git"
+               elif test -d "$reference/objects"
+               then
+                       ref_git="$reference"
                fi
-               reference=$(cd "$reference" && pwd)
-               echo "$reference/objects" >"$GIT_DIR/objects/info/alternates"
-               (cd "$reference" && tar cf - refs) |
-               (cd "$GIT_DIR/refs" &&
-                mkdir reference-tmp &&
-                cd reference-tmp &&
-                tar xf -)
+       fi
+       if test -n "$ref_git"
+       then
+               ref_git=$(cd "$ref_git" && pwd)
+               echo "$ref_git/objects" >"$GIT_DIR/objects/info/alternates"
+               (
+                       GIT_DIR="$ref_git" git for-each-ref \
+                               --format='%(objectname) %(*objectname)'
+               ) |
+               while read a b
+               do
+                       test -z "$a" ||
+                       git update-ref "refs/reference-tmp/$a" "$a"
+                       test -z "$b" ||
+                       git update-ref "refs/reference-tmp/$b" "$b"
+               done
        else
                die "reference repository '$reference' is not a local directory."
        fi
@@ -319,8 +293,8 @@ yes,yes)
                ;;
        *)
                case "$upload_pack" in
-               '') git-fetch-pack --all -k $quiet $depth "$repo" ;;
-               *) git-fetch-pack --all -k $quiet "$upload_pack" $depth "$repo" ;;
+               '') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
+               *) git-fetch-pack --all -k $quiet "$upload_pack" $depth $no_progress "$repo" ;;
                esac >"$GIT_DIR/CLONE_HEAD" ||
                        die "fetch-pack from '$repo' failed."
                ;;
@@ -332,8 +306,29 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp"
 if test -f "$GIT_DIR/CLONE_HEAD"
 then
        # Read git-fetch-pack -k output and store the remote branches.
-       @@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" ||
-       exit
+       if [ -n "$use_separate_remote" ]
+       then
+               branch_top="remotes/$origin"
+       else
+               branch_top="heads"
+       fi
+       tag_top="tags"
+       while read sha1 name
+       do
+               case "$name" in
+               *'^{}')
+                       continue ;;
+               HEAD)
+                       destname="REMOTE_HEAD" ;;
+               refs/heads/*)
+                       destname="refs/$branch_top/${name#refs/heads/}" ;;
+               refs/tags/*)
+                       destname="refs/$tag_top/${name#refs/tags/}" ;;
+               *)
+                       continue ;;
+               esac
+               git-update-ref -m "clone: from $repo" "$destname" "$sha1" ""
+       done < "$GIT_DIR/CLONE_HEAD"
 fi
 
 cd "$D" || exit
@@ -401,7 +396,7 @@ then
 
        case "$no_checkout" in
        '')
-               test "z$quiet" = z && v=-v || v=
+               test "z$quiet" = z -a "z$no_progress" = z && v=-v || v=
                git-read-tree -m -u $v HEAD HEAD
        esac
 fi