]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/import.sh
Merge commit 'acb089b983171667467adc66f56a723b609ed22e' into kbsd/vis
[FreeBSD/FreeBSD.git] / contrib / bmake / import.sh
1 #!/bin/sh
2
3 # Import bmake
4
5 ECHO=
6 GIT=${GIT:-git}
7
8 # For consistency...
9 Error() {
10     echo ERROR: ${1+"$@"} >&2
11     exit 1
12 }
13
14 Cd() {
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
20 option_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         -d) RM=echo; shift;;
30         -n) ECHO=echo; shift;;
31         -P) PR=$2; shift 2;;
32         -r) REVIEWER=$2; shift 2;;
33         -u) url=$2; shift 2;;
34         -h) echo "Usage:";
35             echo "  "$0 '[-ahnPr] [TARBALL=] [PR=] [REVIEWER=]'
36             echo "  "$0 '-a <filename>    # (a)rchive'
37             echo "  "$0 '-h                       # print usage'
38             echo "  "$0 '-n                       # do not import, check only.'
39             echo "  "$0 '-P <PR Number>   # Use PR'
40             echo "  "$0 '-r <reviewer(s) list>  # (r)eviewed by'
41             echo "  "$0 'PR=<PR Number>'
42             echo "  "$0 'REVIEWER=<reviewer(s) list>'
43             exit 1;;
44         *) break;;
45         esac
46     done
47     return $(($_shift - $#))
48 }
49
50 ###
51
52 option_parsing "$@"
53 shift $?
54
55 TF=/tmp/.$USER.$$
56 Cd `dirname $0`
57 test -s ${TARBALL:-/dev/null} || Error need TARBALL
58 here=`pwd`
59 SB=${SB:-`dirname $here`}
60 # thing should match what the TARBALL contains
61 thing=`basename $here`
62
63 case "$thing" in
64 bmake) (cd .. && tar zxf $TARBALL);;
65 *) Error "we should be in bmake";;
66 esac
67
68 VERSION=`grep '^_MAKE_VERSION' VERSION | sed 's,.*=[[:space:]]*,,'`
69
70 rm -f *~
71 mkdir -p $SB/tmp
72
73 # new files are handled automatically
74 # but we need to rm if needed
75 # FILES are kept sorted so we can determine what was added and deleted
76 # but we need to take care dealing with re-ordering
77 (${GIT} diff FILES | sed -n '/^[+-][^+-]/p'; \
78  ${GIT} diff mk/FILES | sed -n '/^[+-][^+-]/s,.,&mk/,p' ) > $TF.diffs
79 grep '^+' $TF.diffs | sed 's,^.,,' | sort > $TF.adds
80 grep '^-' $TF.diffs | sed 's,^.,,' | sort > $TF.rms
81 comm -13 $TF.adds $TF.rms > $TF.rm
82
83 if [ -z "$ECHO" ]; then
84     test -s $TF.rm && xargs rm -f < $TF.rm
85     $GIT add -A
86     $GIT diff --staged | tee $SB/tmp/bmake-import.diff
87     { echo "$GIT tag -a -m \"Tag bmake/$VERSION\" vendor/NetBSD/bmake/$VERSION"
88       echo "echo \"When ready do: $GIT push --follow-tags\""
89     } > $SB/tmp/bmake-post.sh
90     echo "After you commit, run $SB/tmp/bmake-post.sh"
91 else
92     comm -23 $TF.adds $TF.rms > $TF.add
93     test -s $TF.rm && { echo Removing:; cat $TF.rm; }
94     test -s $TF.add && { echo Adding:; cat $TF.add; }
95     $GIT diff
96 fi
97 ${RM:-rm} -f $TF.*