]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/all/git.subr
Merge branch 'master' into sev/xolonium
[xonotic/xonotic.git] / misc / tools / all / git.subr
index f210da95969eb7e12de4884ef97dbb04a1eae70a..b14a8b6f1acd8e0f67443f7a211fcdf3c80fa3af 100644 (file)
@@ -53,16 +53,18 @@ testrepoflag()
 
 mirrorspeed()
 {
 
 mirrorspeed()
 {
-       if ! { time -p true; } >/dev/null 2>&1; then
+       # first result is to be ignored, but we use it to check status
+       git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
+       # if we can't time, we only check availability
+       if ! $have_time; then
                echo 0
                return
        fi
                echo 0
                return
        fi
-       # first result is to be ignored, but we use it to check status
-       git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
        # now actually time it
        (
                set +x
        # now actually time it
        (
                set +x
-               { time -p git ls-remote "$1" refs/heads/master; } 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,' | grep . || echo 0
+               export REPO=$1 # so that the sh -c subshell can use it
+               { measure_time sh -c 'git ls-remote "$REPO" refs/heads/master >/dev/null 2>&1'; } 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,' | grep . || echo 0
                        # unit: clock ticks (depends on what "time" returns
        )
 }
                        # unit: clock ticks (depends on what "time" returns
        )
 }
@@ -103,7 +105,13 @@ bestmirror()
        bestcount=
        bestmirror_benchmark()
        {
        bestcount=
        bestmirror_benchmark()
        {
-               if [ -z "$2" ]; then
+               bmb_curloc=$1
+               bmb_proto=$2
+               bmb_loc=$3
+               bmb_url=$4
+               bmb_fudge=$5
+
+               if [ -z "$bmb_loc" ]; then
                        # empty location is not allowed
                        return
                fi
                        # empty location is not allowed
                        return
                fi
@@ -111,7 +119,7 @@ bestmirror()
                        *"  "*)
                                # no protocol requested? all match
                                ;;
                        *"  "*)
                                # no protocol requested? all match
                                ;;
-                       *" $1 "*)
+                       *" $bmb_proto "*)
                                ;;
                        *)
                                return
                                ;;
                        *)
                                return
@@ -120,9 +128,18 @@ bestmirror()
 
                # prefer location match
                case " $newlocation " in
 
                # prefer location match
                case " $newlocation " in
-                       *" $2 "*)
+                       *" $bmb_loc "*)
+                               # bmb_curloc is true in first run, false in second
+                               # so first run gets all matching locations
+                               # so second run gets all non-matching locations
+                               if ! $bmb_curloc; then
+                                       return
+                               fi
                                ;;
                        *)
                                ;;
                        *)
+                               if $bmb_curloc; then
+                                       return
+                               fi
                                case " $newlocation " in
                                        *" $bestlocation "*)
                                                # worse
                                case " $newlocation " in
                                        *" $bestlocation "*)
                                                # worse
@@ -133,7 +150,7 @@ bestmirror()
                esac
 
                case " $newlocation " in
                esac
 
                case " $newlocation " in
-                       *" $2 "*)
+                       *" $bmb_loc "*)
                                # see below
                                ;;
                        *)
                                # see below
                                ;;
                        *)
@@ -145,20 +162,20 @@ bestmirror()
                                esac
                                ;;
                esac
                                esac
                                ;;
                esac
-               msg "Testing speed of $3..."
+               msg "Testing speed of $bmb_url..."
 
                # only working mirrors
 
                # only working mirrors
-               if ! thistime=`mirrorspeed "$3$testrepo"`; then
+               if ! thistime=`mirrorspeed "$bmb_url$testrepo"`; then
                        msg "-> FAILED"
                        return
                fi
                        msg "-> FAILED"
                        return
                fi
-               thistime=$(($thistime $4))
+               thistime=$(($thistime $bmb_fudge))
                msg "-> $thistime"
 
                # anything is better than nothing
                if [ -z "$besttime" ]; then
                msg "-> $thistime"
 
                # anything is better than nothing
                if [ -z "$besttime" ]; then
-                       besturl=$3
-                       bestlocation=$2
+                       besturl=$bmb_url
+                       bestlocation=$bmb_loc
                        besttime=$thistime
                        bestcount=1
                        return
                        besttime=$thistime
                        bestcount=1
                        return
@@ -166,15 +183,15 @@ bestmirror()
 
                # prefer location match
                case " $newlocation " in
 
                # prefer location match
                case " $newlocation " in
-                       *" $2 "*)
+                       *" $bmb_loc "*)
                                case " $newlocation " in
                                        *" $bestlocation "*)
                                                # equality
                                                ;;
                                        *)
                                                # better
                                case " $newlocation " in
                                        *" $bestlocation "*)
                                                # equality
                                                ;;
                                        *)
                                                # better
-                                               besturl=$3
-                                               bestlocation=$2
+                                               besturl=$bmb_url
+                                               bestlocation=$bmb_loc
                                                besttime=$thistime
                                                bestcount=1
                                                return
                                                besttime=$thistime
                                                bestcount=1
                                                return
@@ -190,7 +207,8 @@ bestmirror()
                if [ $thistime -gt $besttime ]; then
                        return
                elif [ $thistime -lt $besttime ]; then
                if [ $thistime -gt $besttime ]; then
                        return
                elif [ $thistime -lt $besttime ]; then
-                       besturl=$3
+                       besturl=$bmb_url
+                       bestlocation=$bmb_loc
                        besttime=$thistime
                        bestcount=1
                        return
                        besttime=$thistime
                        bestcount=1
                        return
@@ -198,10 +216,12 @@ bestmirror()
                # both location and time match. Random decision.
                bestcount=$(($bestcount + 1))
                if [ $((($RANDOM + 0) % $bestcount)) -eq 0 ]; then
                # both location and time match. Random decision.
                bestcount=$(($bestcount + 1))
                if [ $((($RANDOM + 0) % $bestcount)) -eq 0 ]; then
-                       besturl=$3
+                       besturl=$bmb_url
+                       bestlocation=$bmb_loc
                fi
        }
                fi
        }
-       allmirrors bestmirror_benchmark
+       allmirrors bestmirror_benchmark true
+       allmirrors bestmirror_benchmark false
        echo "$besturl"
 }
 
        echo "$besturl"
 }
 
@@ -439,9 +459,12 @@ case "$cmd" in
                        msg "can skip the following paragraph and already use the repository."
                        msg ""
                        msg "To get access, your key has to be approved first. For that, visit"
                        msg "can skip the following paragraph and already use the repository."
                        msg ""
                        msg "To get access, your key has to be approved first. For that, visit"
-                       msg "$devsite_url, then log in, create a \"New Issue\" on"
-                       msg "the \"Support\" tracker in the \"Repository\" category where you"
-                       msg "apply for access and paste the following output into the issue:"
+                       msg "$gitsite_url, then log in, enter the"
+                       msg "\"xonotic\" project, create an \"Issue\" tagged \"Repository Access\""
+                       msg "to apply for access and paste the following output into the issue:"
+                       msg ""
+                       msg "After that, go to your profile settings, \"SSH Keys\", \"Add SSH Key\""
+                       msg "and paste the following output:"
                        msg ""
                        msg "`cat ~/.ssh/id_rsa.pub`"
                elif [ -f ~/.ssh/id_dsa.pub ]; then
                        msg ""
                        msg "`cat ~/.ssh/id_rsa.pub`"
                elif [ -f ~/.ssh/id_dsa.pub ]; then
@@ -451,9 +474,12 @@ case "$cmd" in
                        msg "can skip the following paragraph and already use the repository."
                        msg ""
                        msg "To get access, your key has to be approved first. For that, visit"
                        msg "can skip the following paragraph and already use the repository."
                        msg ""
                        msg "To get access, your key has to be approved first. For that, visit"
-                       msg "$devsite_url, then log in, create a \"New Issue\" on"
-                       msg "the \"Support\" tracker in the \"Repository\" category where you"
-                       msg "apply for access and paste the following output into the issue:"
+                       msg "$gitsite_url, then log in, enter the"
+                       msg "\"xonotic\" project, create an \"Issue\" tagged \"Repository Access\""
+                       msg "to apply for access and paste the following output into the issue:"
+                       msg ""
+                       msg "After that, go to your profile settings, \"SSH Keys\", \"Add SSH Key\""
+                       msg "and paste the following output:"
                        msg ""
                        msg "`cat ~/.ssh/id_dsa.pub`"
                else
                        msg ""
                        msg "`cat ~/.ssh/id_dsa.pub`"
                else
@@ -466,9 +492,12 @@ case "$cmd" in
                        ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
                        msg ""
                        msg "To get access, your key has to be approved first. For that, visit"
                        ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
                        msg ""
                        msg "To get access, your key has to be approved first. For that, visit"
-                       msg "$devsite_url, then log in, create a \"New Issue\" on"
-                       msg "the \"Support\" tracker in the \"Repository\" category where you"
-                       msg "apply for access and paste the following output into the issue:"
+                       msg "$gitsite_url, then log in, enter the"
+                       msg "\"xonotic\" project, create an \"Issue\" tagged \"Repository Access\""
+                       msg "to apply for access and paste the following output into the issue:"
+                       msg ""
+                       msg "After that, go to your profile settings, \"SSH Keys\", \"Add SSH Key\""
+                       msg "and paste the following output:"
                        msg ""
                        msg "`cat ~/.ssh/id_rsa.pub`"
                fi
                        msg ""
                        msg "`cat ~/.ssh/id_rsa.pub`"
                fi
@@ -600,10 +629,11 @@ case "$cmd" in
                                                o=`( cd "$d0" && git config xonotic.all.mirrorselection 2>/dev/null || true )`
                                                ( cd "$d0" && git config xonotic.all.mirrorselection try_same )
                                                if ! verbose git pull; then
                                                o=`( cd "$d0" && git config xonotic.all.mirrorselection 2>/dev/null || true )`
                                                ( cd "$d0" && git config xonotic.all.mirrorselection try_same )
                                                if ! verbose git pull; then
-                                                       fix_upstream_rebase_mergefail || true
-                                                       check_mergeconflict "$d"
-                                                       $ECHO "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
-                                                       read -r DUMMY
+                                                       if fix_upstream_rebase_mergefail; then
+                                                               check_mergeconflict "$d"
+                                                               $ECHO "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
+                                                               read -r DUMMY
+                                                       fi
                                                else
                                                        ( cd "$d0" && git config xonotic.all.mirrorselection "$o" )
                                                        fix_upstream_rebase_mergeok || true
                                                else
                                                        ( cd "$d0" && git config xonotic.all.mirrorselection "$o" )
                                                        fix_upstream_rebase_mergeok || true
@@ -627,13 +657,10 @@ case "$cmd" in
                                fi
                                o=`git config xonotic.all.mirrorselection 2>/dev/null || true`
                                git config xonotic.all.mirrorselection try_same
                                fi
                                o=`git config xonotic.all.mirrorselection 2>/dev/null || true`
                                git config xonotic.all.mirrorselection try_same
-                               verbose git clone "$url" "$d0/$d"
+                               verbose git clone --branch "$branch" "$url" "$d0/$d"
                                git config xonotic.all.mirrorselection "$o"
                                enter "$d0/$d" verbose
                                fix_git_config "$url" "$pushurl"
                                git config xonotic.all.mirrorselection "$o"
                                enter "$d0/$d" verbose
                                fix_git_config "$url" "$pushurl"
-                               if [ "$branch" != "master" ]; then
-                                       verbose git checkout --track -b "$branch" origin/"$branch"
-                               fi
                                cd "$d0"
                        fi
                }
                                cd "$d0"
                        fi
                }
@@ -677,8 +704,10 @@ case "$cmd" in
                        else
                                b=$branch
                                if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
                        else
                                b=$branch
                                if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
+                                       [ -n "$b" ] || exists=true
                                        verbose git checkout $checkoutflags "$b"
                                elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
                                        verbose git checkout $checkoutflags "$b"
                                elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
+                                       [ -n "$b" ] || exists=true
                                        verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
                                else
                                        $ECHO "WTF? Not even branch $b doesn't exist in $d"
                                        verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
                                else
                                        $ECHO "WTF? Not even branch $b doesn't exist in $d"
@@ -937,8 +966,17 @@ case "$cmd" in
                $ECHO "  $SELF keygen"
                $ECHO "  $SELF push|commit [-s]"
                $ECHO "  $SELF update|pull [-N] [-s | -h [-p] | -g [-p]] [-l de|nl|default]"
                $ECHO "  $SELF keygen"
                $ECHO "  $SELF push|commit [-s]"
                $ECHO "  $SELF update|pull [-N] [-s | -h [-p] | -g [-p]] [-l de|nl|default]"
+               $ECHO "  $SELF grep \"<regex>\""
                handled=false
                ;;
                handled=false
                ;;
+       grep)
+               for d in $repos; do
+                       if verbose cd "$d0/$d"; then
+                               git grep -In "$@" || true
+                               cd "$d0"
+                       fi
+               done
+               ;;
        *)
                handled=false
                ;;
        *)
                handled=false
                ;;