]> git.ozlabs.org Git - next-scripts/blobdiff - fetch_trees
check_fixes: a few cleanups
[next-scripts] / fetch_trees
index 369787349627a7c077a94d40d80efb8349bf8077..3a43025550e5554ebd9fab941058824d0eac4091 100755 (executable)
 #!/bin/bash
 
-origwd=$(pwd)
+tools_dir=$(dirname "$0")
+# shellcheck source=/dev/null
+. "$tools_dir/common.sh" ''
+
+if [ "$1" = '-n' ]; then
+       shift
+       last=$(tail -n1 "$SHA1_FILE" | cut -f1 -d$'\t')
+       start_from=$(awk -F '\t' '/^[^#]/ && $3 == "'"$last"'" {
+               do
+                       getline;
+               while (/^#/ || $2 == "branch");
+               print $3;
+               exit 0;
+       }' "$CTRL_FILE")
+fi
+
+if [ "$1" = '-s' ]; then
+       shift
+       start_from="$1"
+       if [ -z "$start_from" ]; then
+               printf '-s requires a start tree\n' 1>&2
+               exit 1
+       fi
+       shift
+fi
 
 get_field()
 {
-       grep -v '^#' ../real_control |
-               awk -F '        ' '$3 == "'$1'" { print $'$2'; }'
+       awk -F '\t' '/^[^#]/ && $3 == "'"$1"'" { print $'"$2"'; }' "$CTRL_FILE"
 }
 
-trees=$(grep -v '^#' ../real_control | awk -F '        ' '{ print $3 }')
-
-for name in $trees; do
-       type=$(get_field "$name" 2)
+fetch_git()
+{
+       git fetch "$1"
+}
 
-       echo $name: $type
-       if [ "$type" = "git" ]; then
-               git fetch "$name"
-               continue
-       fi
+fetch_mmotm()
+{
+       (
+               if ! cd ../mmotm; then
+                       printf 'Cannot chdir to ../mmotm\n' 1>&2
+                       return
+               fi
+               if ! rsync -az --partial --exclude '.git*' \
+                               --exclude broken-out.tar.gz --delete \
+                               ozlabs.org::akpm/mmotm/. .; then
+                       git reset --hard
+                       printf 'Fetcing mmotm failed\n' 1>&2
+                       return
+               fi
+               git add -A .
+               if [ "$(git status --porcelain)" ]; then
+                       git commit -m "$(head -n 1 .DATE)"
+               fi
+       )
+}
 
-       if [ "$type" = "quilt" ]; then
-               url=$(get_field "$name" 4)
+fetch_quilt()
+{
+       (
+               url=$(get_field "$1" 4)
+               url=${url%/}    # strip trailing / if necessary
 
-               case "$url" in
-               http://kernel.org/*|http://www.kernel.org/*)
-                       use_rsync=true
-                       rurl=$(echo "$url" | sed -r 's,^http://(www\.)?kernel\.org,master.kernel.org:,')
-                       ;;
-               http://ozlabs.org/~*)
-                       use_rsync=true
-                       rurl=$(echo "$url" | sed -r 's,^http://ozlabs\.org/([^/]*),ozlabs.org:\1/public_html,')
-                       ;;
-               *)
-                       use_rsync=false
-                       ;;
-               esac
-               cd ../quilt || {
-                       echo "Cannot chdir to ../quilt" 1>&2
-                       continue
-               }
-               [ -d "$name" ] || mkdir "$name" || {
-                       echo "Cannot create quilt directory for $name" 1>&2
-                       cd "$origwd"
-                       continue
-               }
-               cd "$name" || {
-                       echo "Cannot chdir to quilt directory for $name" 1>&2
-                       cd "$origwd"
-                       continue
-               }
-               if $use_rsync; then
-                       rsync -avz "$rurl/series" series || {
-                               echo "rsync of $name series file failed" 1>&2
-                               cd ..
-                               rm -rf "$name"
-                               git checkout "$name"
-                               cd "$origwd"
-                               continue
-                       }
-               else
-                       wget -N -nv --no-cache "$url/series" || {
-                               echo "Wget of $name series file failed" 1>&2
-                               cd ..
-                               rm -rf "$name"
-                               git checkout "$name"
-                               cd "$origwd"
-                               continue
-                       }
+               if ! cd ../quilt; then
+                       printf 'Cannot chdir to ../quilt\n' 1>&2
+                       return
                fi
-               find * -type f | grep -v '^series$' | sort >.series.old
-               do_echo=echo
-               grep -q NEXT_PATCHES series &&
-                       do_echo=:
-               while read line; do
-                       case "$line" in
-                       *NEXT_PATCHES_START*)   do_echo=echo ;;
-                       *NEXT_PATCHES_END*)     do_echo=: ;;
-                       ''|\#*)                 : ;;
-                       *)                      $do_echo $line ;;
-                       esac
-               done <series |
-                       sed -e 's/[     ]*#.*$//' -e '/^[       ]*$/d' |
-                       sort >.series.next
-               if $use_rsync; then
-                       rsync -avz --files-from .series.next "$rurl" . || {
-                               echo "rsync of series '$name' failed" 1>&2
-                               cd ..
-                               rm -rf "$name"
-                               git checkout "$name"
-                               cd "$origwd"
-                               continue
-                       }
+               if ! [ -d "$1" ] && ! mkdir "$1"; then
+                       printf 'Cannot create quilt directory for %s\n' "$1" 1>&2
+                       return
+               fi
+               if ! cd "$1"; then
+                       printf 'Cannot chdir to quilt directory for %s\n' "$1" 1>&2
+                       return
+               fi
+               if ! wget -N -nv --no-cache --no-xattr "$url/series"; then
+                       printf 'Wget of %s series file failed\n' "$1" 1>&2
+                       cd ..
+                       rm -rf "$1"
+                       git checkout "$1"
+                       return
+               fi
+               find . -type f | sed 's,^./,,;/^series$/d' | sort >.series.old
+               if grep -q NEXT_PATCHES series; then
+                       sed -n '/NEXT_PATCHES_START/,/NEXT_PATCHES_END/p' series
                else
-                       wget -N -nv --no-cache -B "$url" -i .series.next || {
-                               echo "Wget of series '$name' failed" 1>&2
+                       cat series
+               fi |
+                       sed -e 's/[ \t]*#.*$//' -e '/^[ \t]*$/d' |
+                       sort >.series.next
+               if [ -s .series.next ]; then
+                       if ! wget -N -nv --no-cache --no-xattr -B "$url/" -i .series.next; then
+                               printf 'Wget of series %s failed\n' "$1" 1>&2
                                cd ..
-                               rm -rf "$name"
-                               git checkout "$name"
-                               cd "$origwd"
-                               continue
-                       }
+                               rm -rf "$1"
+                               git checkout "$1"
+                               return
+                       fi
                fi
                comm -23 .series.old .series.next | xargs -r rm -f
                rm -f .series.old .series.next
-               cd "$origwd"
+       )
+}
+
+trees="$*"
+if ! [ "$trees" ]; then
+       trees=$(awk -F '\t' '/^[^#]/ && $2 != "branch" { print $3 }' "$CTRL_FILE")
+fi
+
+for name in $trees; do
+       if [ -n "$start_from" ]; then
+               if [ "$name" = "$start_from" ]; then
+                       start_from=''
+               else
+                       continue
+               fi
+       fi
+
+       type=$(get_field "$name" 2)
+       if ! [ "$type" ]; then
+               printf '%s: unknown tree\n' "$name" 1>&2
+               continue
+       fi
+
+       printf '%s: %s\n' "$name" "$type"
+       fun="fetch_$type"
+       tfun=$(type -t "$fun")
+       if [ "$tfun" = 'function' ]; then
+               "$fun" "$name"
        fi
 done
 
-cd ../quilt
-git add .
-git commit -v -a -m "$(date '+%F-%H:%M')" -e
+if ! cd ../quilt; then
+       printf 'hmmm, what happened to the quilt directory?\n' 1>&2
+       exit 1
+fi
+git add -A .
+if [ "$(git status --porcelain)" ]; then
+       git commit -v -a -m "$(date '+%F-%H:%M')" -e
+fi
 
 exit 0