xref: /freebsd/contrib/bmake/import.sh (revision c59c3bf3)
106b9b3e0SSimon J. Gerraty#!/bin/sh
206b9b3e0SSimon J. Gerraty
306b9b3e0SSimon J. Gerraty# Import bmake
406b9b3e0SSimon J. Gerraty
506b9b3e0SSimon J. GerratyECHO=
606b9b3e0SSimon J. GerratyGIT=${GIT:-git}
798875883SSimon J. GerratyPAGER=${PAGER:-${LESS:-${MORE:-more}}}
806b9b3e0SSimon J. Gerraty
906b9b3e0SSimon J. Gerraty# For consistency...
1006b9b3e0SSimon J. GerratyError() {
1106b9b3e0SSimon J. Gerraty    echo ERROR: ${1+"$@"} >&2
1206b9b3e0SSimon J. Gerraty    exit 1
1306b9b3e0SSimon J. Gerraty}
1406b9b3e0SSimon J. Gerraty
1506b9b3e0SSimon J. GerratyCd() {
1606b9b3e0SSimon J. Gerraty    [ $# -eq 1 ] || Error "Cd() takes a single parameter."
1706b9b3e0SSimon J. Gerraty    cd $1 || Error "cannot \"cd $1\" from $PWD"
1806b9b3e0SSimon J. Gerraty}
1906b9b3e0SSimon J. Gerraty
2006b9b3e0SSimon J. Gerraty# Call this function and then follow it by any specific import script additions
2106b9b3e0SSimon J. Gerratyoption_parsing() {
2206b9b3e0SSimon J. Gerraty    local _shift=$#
2306b9b3e0SSimon J. Gerraty    # Parse command line options
2406b9b3e0SSimon J. Gerraty    while :
2506b9b3e0SSimon J. Gerraty    do
2606b9b3e0SSimon J. Gerraty        case "$1" in
2706b9b3e0SSimon J. Gerraty	*=*) eval "$1"; shift;;
2806b9b3e0SSimon J. Gerraty	--) shift; break;;
2906b9b3e0SSimon J. Gerraty	-a) TARBALL=$2; shift 2;;
3012904384SSimon J. Gerraty	-d) RM=echo; shift;;
3106b9b3e0SSimon J. Gerraty	-n) ECHO=echo; shift;;
3206b9b3e0SSimon J. Gerraty	-P) PR=$2; shift 2;;
3306b9b3e0SSimon J. Gerraty	-r) REVIEWER=$2; shift 2;;
3406b9b3e0SSimon J. Gerraty	-u) url=$2; shift 2;;
3506b9b3e0SSimon J. Gerraty	-h) echo "Usage:";
3606b9b3e0SSimon J. Gerraty	    echo "  "$0 '[-ahnPr] [TARBALL=] [PR=] [REVIEWER=]'
3706b9b3e0SSimon J. Gerraty	    echo "  "$0 '-a <filename>	  # (a)rchive'
3806b9b3e0SSimon J. Gerraty	    echo "  "$0 '-h			  # print usage'
3906b9b3e0SSimon J. Gerraty	    echo "  "$0 '-n			  # do not import, check only.'
4006b9b3e0SSimon J. Gerraty	    echo "  "$0 '-P <PR Number>	  # Use PR'
4106b9b3e0SSimon J. Gerraty	    echo "  "$0 '-r <reviewer(s) list>  # (r)eviewed by'
4206b9b3e0SSimon J. Gerraty	    echo "  "$0 'PR=<PR Number>'
4306b9b3e0SSimon J. Gerraty	    echo "  "$0 'REVIEWER=<reviewer(s) list>'
4406b9b3e0SSimon J. Gerraty	    exit 1;;
4506b9b3e0SSimon J. Gerraty	*) break;;
4606b9b3e0SSimon J. Gerraty	esac
4706b9b3e0SSimon J. Gerraty    done
4806b9b3e0SSimon J. Gerraty    return $(($_shift - $#))
4906b9b3e0SSimon J. Gerraty}
5006b9b3e0SSimon J. Gerraty
5106b9b3e0SSimon J. Gerraty###
5206b9b3e0SSimon J. Gerraty
5306b9b3e0SSimon J. Gerratyoption_parsing "$@"
5406b9b3e0SSimon J. Gerratyshift $?
5506b9b3e0SSimon J. Gerraty
5606b9b3e0SSimon J. GerratyTF=/tmp/.$USER.$$
5706b9b3e0SSimon J. GerratyCd `dirname $0`
5806b9b3e0SSimon J. Gerratytest -s ${TARBALL:-/dev/null} || Error need TARBALL
5906b9b3e0SSimon J. Gerratyhere=`pwd`
6012904384SSimon J. GerratySB=${SB:-`dirname $here`}
6106b9b3e0SSimon J. Gerraty# thing should match what the TARBALL contains
6206b9b3e0SSimon J. Gerratything=`basename $here`
6306b9b3e0SSimon J. Gerraty
6406b9b3e0SSimon J. Gerratycase "$thing" in
6506b9b3e0SSimon J. Gerratybmake) (cd .. && tar zxf $TARBALL);;
6606b9b3e0SSimon J. Gerraty*) Error "we should be in bmake";;
6706b9b3e0SSimon J. Gerratyesac
6806b9b3e0SSimon J. Gerraty
6906b9b3e0SSimon J. GerratyVERSION=`grep '^_MAKE_VERSION' VERSION | sed 's,.*=[[:space:]]*,,'`
7006b9b3e0SSimon J. Gerraty
7106b9b3e0SSimon J. Gerratyrm -f *~
7212904384SSimon J. Gerratymkdir -p $SB/tmp
7306b9b3e0SSimon J. Gerraty
7406b9b3e0SSimon J. Gerraty# new files are handled automatically
7506b9b3e0SSimon J. Gerraty# but we need to rm if needed
76b0c40a00SSimon J. Gerraty# FILES are kept sorted so we can determine what was added and deleted
77b0c40a00SSimon J. Gerraty# but we need to take care dealing with re-ordering
78b0c40a00SSimon J. Gerraty(${GIT} diff FILES | sed -n '/^[+-][^+-]/p'; \
79b0c40a00SSimon J. Gerraty ${GIT} diff mk/FILES | sed -n '/^[+-][^+-]/s,.,&mk/,p' ) > $TF.diffs
80b0c40a00SSimon J. Gerratygrep '^+' $TF.diffs | sed 's,^.,,' | sort > $TF.adds
81b0c40a00SSimon J. Gerratygrep '^-' $TF.diffs | sed 's,^.,,' | sort > $TF.rms
82b0c40a00SSimon J. Gerratycomm -13 $TF.adds $TF.rms > $TF.rm
83b0c40a00SSimon J. Gerraty
8498875883SSimon J. Gerratypost=$SB/tmp/bmake-post.sh
8598875883SSimon J. Gerraty
8698875883SSimon J. Gerraty# this is similar to what generates the mail to bmake-announce
8798875883SSimon J. Gerratygen_import_F() {
8898875883SSimon J. Gerraty    echo Import bmake-$VERSION
89*c59c3bf3SSimon J. Gerraty    echo
9098875883SSimon J. Gerraty
9198875883SSimon J. Gerraty    if [ -s $post ]; then
9298875883SSimon J. Gerraty	last=`sed -n '/ tag/s,.*/,bmake-,p' $post`
9398875883SSimon J. Gerraty    else
9498875883SSimon J. Gerraty	last="last import"
9598875883SSimon J. Gerraty    fi
96*c59c3bf3SSimon J. Gerraty    echo Intersting/relevant changes since $last; echo
9798875883SSimon J. Gerraty    for C in ChangeLog */ChangeLog
9898875883SSimon J. Gerraty    do
9998875883SSimon J. Gerraty	$GIT diff --staged $C |
10098875883SSimon J. Gerraty	    sed -n '/^@@/d;/^\+\+\+/d;/^\+/s,^.,,p' > $TF.C
10198875883SSimon J. Gerraty	test -s $TF.C || continue
10298875883SSimon J. Gerraty	echo
10398875883SSimon J. Gerraty	echo $C since $last
10498875883SSimon J. Gerraty	echo
10598875883SSimon J. Gerraty	cat $TF.C
10698875883SSimon J. Gerraty    done
10798875883SSimon J. Gerraty}
10898875883SSimon J. Gerraty
109b0c40a00SSimon J. Gerratyif [ -z "$ECHO" ]; then
11006b9b3e0SSimon J. Gerraty    test -s $TF.rm && xargs rm -f < $TF.rm
11106b9b3e0SSimon J. Gerraty    $GIT add -A
11298875883SSimon J. Gerraty    gen_import_F > $SB/tmp/bmake-import.F
11398875883SSimon J. Gerraty    $GIT diff --staged > $SB/tmp/bmake-import.diff
11498875883SSimon J. Gerraty    $PAGER $SB/tmp/bmake-import.F $SB/tmp/bmake-import.diff
1152f2a5ecdSSimon J. Gerraty    { echo "$GIT tag -a -m \"Tag bmake/$VERSION\" vendor/NetBSD/bmake/$VERSION"
11612904384SSimon J. Gerraty      echo "echo \"When ready do: $GIT push --follow-tags\""
11798875883SSimon J. Gerraty    } > $post
11898875883SSimon J. Gerraty    echo "Edit $SB/tmp/bmake-import.F as needed, then:"
11998875883SSimon J. Gerraty    echo "$GIT commit -F $SB/tmp/bmake-import.F"
12098875883SSimon J. Gerraty    echo "After you commit, run $post"
12106b9b3e0SSimon J. Gerratyelse
122b0c40a00SSimon J. Gerraty    comm -23 $TF.adds $TF.rms > $TF.add
12306b9b3e0SSimon J. Gerraty    test -s $TF.rm && { echo Removing:; cat $TF.rm; }
12406b9b3e0SSimon J. Gerraty    test -s $TF.add && { echo Adding:; cat $TF.add; }
12506b9b3e0SSimon J. Gerraty    $GIT diff
12606b9b3e0SSimon J. Gerratyfi
12712904384SSimon J. Gerraty${RM:-rm} -f $TF.*
128