xref: /freebsd/contrib/bmake/import.sh (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1#!/bin/sh
2
3# Import bmake
4
5ECHO=
6GIT=${GIT:-git}
7
8# For consistency...
9Error() {
10    echo ERROR: ${1+"$@"} >&2
11    exit 1
12}
13
14Cd() {
15    [ $# -eq 1 ] || Error "Cd() takes a single parameter."
16    cd $1 || Error "cannot \"cd $1\" from $PWD"
17}
18
19# Call this function and then follow it by any specific import script additions
20option_parsing() {
21    local _shift=$#
22    # Parse command line options
23    while :
24    do
25        case "$1" in
26	*=*) eval "$1"; shift;;
27	--) shift; break;;
28	-a) TARBALL=$2; shift 2;;
29	-n) ECHO=echo; shift;;
30	-P) PR=$2; shift 2;;
31	-r) REVIEWER=$2; shift 2;;
32	-u) url=$2; shift 2;;
33	-h) echo "Usage:";
34	    echo "  "$0 '[-ahnPr] [TARBALL=] [PR=] [REVIEWER=]'
35	    echo "  "$0 '-a <filename>	  # (a)rchive'
36	    echo "  "$0 '-h			  # print usage'
37	    echo "  "$0 '-n			  # do not import, check only.'
38	    echo "  "$0 '-P <PR Number>	  # Use PR'
39	    echo "  "$0 '-r <reviewer(s) list>  # (r)eviewed by'
40	    echo "  "$0 'PR=<PR Number>'
41	    echo "  "$0 'REVIEWER=<reviewer(s) list>'
42	    exit 1;;
43	*) break;;
44	esac
45    done
46    return $(($_shift - $#))
47}
48
49###
50
51option_parsing "$@"
52shift $?
53
54TF=/tmp/.$USER.$$
55Cd `dirname $0`
56test -s ${TARBALL:-/dev/null} || Error need TARBALL
57here=`pwd`
58# thing should match what the TARBALL contains
59thing=`basename $here`
60
61case "$thing" in
62bmake) (cd .. && tar zxf $TARBALL);;
63*) Error "we should be in bmake";;
64esac
65
66VERSION=`grep '^_MAKE_VERSION' VERSION | sed 's,.*=[[:space:]]*,,'`
67
68rm -f *~
69mkdir -p ../tmp
70
71if [ -z "$ECHO" ]; then
72    # new files are handled automatically
73    # but we need to rm if needed
74    $GIT diff FILES | sed -n '/^-[^-]/s,^-,,p'  > $TF.rm
75    test -s $TF.rm && xargs rm -f < $TF.rm
76    $GIT add -A
77    $GIT diff --staged | tee ../tmp/bmake-import.diff
78    echo "$GIT tag -a vendor/NetBSD/bmake/$VERSION" > ../tmp/bmake-post.sh
79    echo "After you commit, run $here/../tmp/bmake-post.sh"
80else
81    # FILES is kept sorted so we can determine what was added and deleted
82    $GIT diff FILES | sed -n '/^+[^+]/s,^+,,p'  > $TF.add
83    $GIT diff FILES | sed -n '/^-[^-]/s,^-,,p'  > $TF.rm
84    test -s $TF.rm && { echo Removing:; cat $TF.rm; }
85    test -s $TF.add && { echo Adding:; cat $TF.add; }
86    $GIT diff
87fi
88