Whamcloud - gitweb
b=22990 Script to update copyright on recently modified source files
[fs/lustre-release.git] / build / replace1.sh
1 #!/bin/bash -e 
2
3 progname=${0##*/}
4
5 CONFLICTS=cvs-merge-conflicts
6 CVS=cvs
7
8 if [ -f .mergeinfo ] ; then
9     echo ".mergeinfo exists - clean up first"
10     exit 
11 fi
12
13 if [ -f $CONFLICTS ] ; then
14     echo "$CONFLICTS exists - clean up first"
15     exit 
16 fi
17
18 if [ $# -lt 2 -o $# -gt 3 ]; then
19     echo "This is phase 1 of replacing branches. Run this in the PARENT tree. Usage: $0 parent(will be replaced) child(will become the new parent) [dir]"
20     exit
21 fi
22
23 parent=$1
24 PARENT=`echo $parent | sed -e "s/^b_//" | tr "[a-z]" "[A-Z]"`
25 child=$2
26 CHILD=`echo $child | sed -e "s/^b_//" | tr "[a-z]" "[A-Z]"`
27 date=`date +%Y%m%d_%H%M`
28
29 dir=${3:-.}
30 module=$(basename $(<$dir/CVS/Repository))
31
32 if [ "$module" = "lustre" ] ; then
33     echo >&2 "${progname}: You probably want to land lustre or lnet, not the whole tree."
34     echo >&2 "${progname}: Try using ${0} $parent $child lustre"
35     exit 1
36 fi
37
38 case $parent in
39   HEAD) : ;;
40   b_*|b[1-4]*) : ;;
41   *) parent="b_$parent" ;;
42 esac
43 case $child in
44   HEAD) : ;;
45   b_*|b[1-4]*) : ;;
46   *) child="b_$child"
47 esac
48
49 if [ "$parent" != "HEAD" -a "`cat $dir/CVS/Tag 2> /dev/null`" != "T$parent" ]; then
50         echo "${progname}: this script must be run within the $parent branch"
51         exit 1
52 fi
53
54 TEST_FILE=${TEST_FILE:-ChangeLog} # does this need to be smarter?
55 check_tag() {
56         [ -z "$1" ] && echo "check_tag() missing arg" && exit3
57         [ "$1" = "HEAD" ] && return
58         $CVS log ${dir%%/*}/$TEST_FILE 2> /dev/null | grep -q " $1: " && return
59         echo "${progname}: tag $1 not found in $dir/$TEST_FILE"
60         exit 2
61 }
62
63 check_tag $child
64 check_tag ${CHILD}_BASE
65
66 cat << EOF > ".mergeinfo"
67 parent=$parent
68 PARENT=$PARENT
69 child=$child
70 CHILD=$CHILD
71 date=$date
72 module=$module
73 dir=$dir
74 CONFLICTS=$CONFLICTS
75 OPERATION=Replace
76 OPERWHERE=onto
77 EOF
78
79 echo PARENT $PARENT parent $parent CHILD $CHILD child $child date $date
80
81 # Update your tree to the PARENT branch; HEAD is not really a branch, so you
82 # need to update -A instead of update -r HEAD, or the commit will fail. -p
83 echo -n "Updating to $parent ...."
84 if [ $parent == "HEAD" ]; then
85   $CVS update -AdP $dir
86 else
87   $CVS update -r $parent -dP $dir
88 fi
89 echo "done"
90
91 # Tag parent before merge
92 echo -n "Create land-to point on $parent as ${PARENT}_${CHILD}_REPLACE_PARENT_$date ..."
93 $CVS rtag -r $parent ${PARENT}_${CHILD}_REPLACE_PARENT_$date $module
94 echo "done"
95
96 # Tag child before merge
97 echo -n "Create land-from point on ${child} ${PARENT}_${CHILD}_REPLACE_CHILD_$date ..."
98 $CVS rtag -r ${child} ${PARENT}_${CHILD}_REPLACE_CHILD_$date $module
99 echo "done"
100
101 # In case someone tries to re-land later
102 echo -n "Preserve old base tag on $parent ${CHILD}_BASE as ${CHILD}_BASE_PREV ..."
103 $CVS rtag -F -r ${CHILD}_BASE ${CHILD}_BASE_PREV $module
104 echo "done"
105
106 # Apply all of the changes to your local tree:
107 echo -n "Updating as -j $parent -j $child ..."
108 $CVS update -j $parent -j $child -dP $dir
109 echo "done"
110
111 echo -n "Recording conflicts in $CONFLICTS ..."
112 $CVS update $dir | awk '/^C/ { print $2 }' > $CONFLICTS
113 if [ -s $CONFLICTS ] ; then
114     echo "Conflicts found, fix before committing."
115     cat $CONFLICTS
116 fi
117 echo "done"
118
119 echo -n "Verifying that there are no diffs from $child ..."
120 $CVS diff --brief -r $child $dir >> $CONFLICTS  
121 if [ -s $CONFLICTS ] ; then
122     echo "Danger! The child branch $CHILD differs from the updated branch $dir"
123     cat $CONFLICTS
124 else 
125     echo "No conflicts found"
126     rm -f $CONFLICTS
127 fi
128 echo "done"
129
130 echo "Build, test, commit and then run replace2.sh (no arguments)"