]> git.ozlabs.org Git - next-scripts/blobdiff - fetch_trees
extract the check_dups function from common.sh
[next-scripts] / fetch_trees
index 74c75848344269c18f4dfcd2637d0bdf32ab8613..48599f81b8450b70004bc57e4f8c0010214a9be2 100755 (executable)
@@ -1,19 +1,16 @@
 #!/bin/bash
 
 tools_dir=$(dirname "$0")
-# shellcheck source=/dev/null
 . "$tools_dir/common.sh" ''
+. "$tools_dir/check_dups.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")
+       last=$(tail -n1 "$SHA1_FILE" | cut -f1 -d"$_TAB")
+       start_from=$(get_branches | sed -n '/^'"$last"'$/{n;p;}')
+       if [ -z "$start_from" ]; then
+               exit 0
+       fi
 fi
 
 if [ "$1" = '-s' ]; then
@@ -26,83 +23,32 @@ if [ "$1" = '-s' ]; then
        shift
 fi
 
-get_field()
-{
-       awk -F '\t' '/^[^#]/ && $3 == "'"$1"'" { print $'"$2"'; }' "$CTRL_FILE"
-}
-
+# shellcheck disable=SC2317
 fetch_git()
 {
-       git fetch "$1"
-}
-
-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
-)
-
-fetch_quilt()
-(
-       url=$(get_field "$1" 4)
-       url=${url%/}    # strip trailing / if necessary
+       local name="$1" branch="$2" old_sha="$3" new_sha
 
-       if ! cd ../quilt; then
-               printf 'Cannot chdir to ../quilt\n' 1>&2
+       if ! new_sha=$(git ls-remote "$name" "refs/heads/$branch") ||
+          [ -z "$new_sha" ]; then
+               printf '%s: Could not fetch %s branch %s\n' 'fetch_git' "$name" "$branch" >&2
+               printf '%s\n' "$old_sha"
                return
        fi
-       if ! [ -d "$1" ] && ! mkdir "$1"; then
-               printf 'Cannot create quilt directory for %s\n' "$1" 1>&2
+       new_sha="${new_sha%%"${_TAB}"*}"
+       if [ "$new_sha" = "$old_sha" ]; then
+               printf '%s\n' "$old_sha"
                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
+       if git fetch "$name"; then
+               git rev-parse --verify "$name/$branch"
        else
-               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 "$1"
-                       git checkout "$1"
-                       return
-               fi
+               printf '%s\n' "$old_sha"
        fi
-       comm -23 .series.old .series.next | xargs -r rm -f
-       rm -f .series.old .series.next
-)
+}
 
 trees="$*"
 if ! [ "$trees" ]; then
-       trees=$(awk -F '\t' '/^[^#]/ && $2 != "branch" { print $3 }' "$CTRL_FILE")
+       trees=$(get_branches)
 fi
 
 for name in $trees; do
@@ -114,27 +60,28 @@ for name in $trees; do
                fi
        fi
 
-       type=$(get_field "$name" 2)
+       type=$(get_type "$name")
        if ! [ "$type" ]; then
                printf '%s: unknown tree\n' "$name" 1>&2
                continue
        fi
 
+       if [ "$(get_url "$name")" = 'linux-next' ]; then
+               continue
+       fi
+
        printf '%s: %s\n' "$name" "$type"
        fun="fetch_$type"
        tfun=$(type -t "$fun")
        if [ "$tfun" = 'function' ]; then
-               "$fun" "$name"
+               branch=$(get_remote_branch "$name")
+               old_sha=$(git rev-parse --quiet --verify "$name/$branch")
+               new_sha=$("$fun" "$name" "$branch" "$old_sha")
+               check_dups "$name" origin/master "$new_sha"
+               if ! [ "$new_sha" = "$old_sha" ]; then
+                       "$tools_dir"/check_commits ^origin/master "$old_sha..$new_sha"
+               fi
        fi
 done
 
-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