summaryrefslogtreecommitdiffstats
path: root/bin/ae-cvs-ci
blob: 3dcc2870aad2564b6337aeab67c3d086b19e99e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
#	aegis - project change supervisor
#	Copyright (C) 2004 Peter Miller;
#	All rights reserved.
#
#	As a specific exception to the GPL, you are allowed to copy
#	this source file into your own project and modify it, without
#	releasing your project under the GPL, unless there is some other
#	file or condition which would require it.
#
# MANIFEST: shell script to commit changes to CVS
#
# It is assumed that your CVSROOT and CVS_RSH environment variables have
# already been set appropriately.
#
# This script is expected to be run as by integrate_pass_notify_command
# and as such the baseline has already assumed the shape asked for by
# the change.
#
#	integrate_pass_notify_command =
#    	    "$bin/ae-cvs-ci $project $change";
#
# Alternatively, you may wish to tailor this script to the individual
# needs of your project.  Make it a source file, e.g. "etc/ae-cvs-ci.sh"
# and then use the following:
#
#	integrate_pass_notify_command =
#    	    "$sh ${s etc/ae-cvs-ci} $project $change";
#

USAGE="Usage: $0 <project> <change>"

PRINT="echo"
EXECUTE="eval"

while getopts "hnq" FLAG
do
    case ${FLAG} in
    h )
        echo "${USAGE}"
        exit 0
        ;;
    n )
        EXECUTE=":"
        ;;
    q )
        PRINT=":"
        ;;
    * )
        echo "$0: unknown option ${FLAG}" >&2
        exit 1
        ;;
    esac
done

shift `expr ${OPTIND} - 1`

case $# in
2)
    project=$1
    change=$2
    ;;
*)
    echo "${USAGE}" 1>&2
    exit 1
    ;;
esac

here=`pwd`

AEGIS_PROJECT=$project
export AEGIS_PROJECT
AEGIS_CHANGE=$change
export AEGIS_CHANGE

module=`echo $project | sed 's|[.].*||'`

baseline=`aegis -cd -bl`

if test X${TMPDIR} = X; then TMPDIR=/var/tmp; fi

TMP=${TMPDIR}/ae-cvs-ci.$$
mkdir ${TMP}
cd ${TMP}

PWD=`pwd`
if test X${PWD} != X${TMP}; then
    echo "$0: ended up in ${PWD}, not ${TMP}" >&2
    exit 1
fi

fail()
{
    set +x
    cd $here
    rm -rf ${TMP}
    echo "FAILED" 1>&2
    exit 1
}
trap "fail" 1 2 3 15

Command()
{
    ${PRINT} "$*"
    ${EXECUTE} "$*"
}

#
# Create a new CVS work area.
#
# Note: this assumes the module is checked-out into a directory of the
# same name.  Is there a way to ask CVS where is is going to put a
# modules, so we can always get the "cd" right?
#
${PRINT} cvs co $module
${EXECUTE} cvs co $module > LOG 2>&1
if test $? -ne 0; then cat LOG; fail; fi
${EXECUTE} cd $module

#
# Now we need to extract the sources from Aegis and drop them into the
# CVS work area.  There are two ways to do this.
#
# The first way is to use the generated tarball.
# This has the advantage that it has the Makefile.in file in it, and
# will work immediately.
#
# The second way is to use aetar, which will give exact sources, and
# omit all derived files.  This will *not* include the Makefile.in,
# and so will not be readily compilable.
#
# gunzip < $baseline/export/${project}.tar.gz | tardy -rp ${project} | tar xf -
aetar -send -o - | tar xzf -

#
# If any new directories have been created we will need to add them
# to CVS before we can add the new files which we know are in them,
# or they would not have been created.  Do this only if the -n option
# isn't used, because if it is, we won't have actually checked out the
# source and we'd erroneously report that all of them need to be added.
#
if test "X${EXECUTE}" != "X:"
then
    find . \( -name CVS -o -name Attic \) -prune -o -type d -print |
    xargs --max-args=1 |
    while read dir
    do
        if [ ! -d $dir/CVS ]
        then
	    Command cvs add $dir
        fi
    done
fi

#
# Use the Aegis meta-data to perform some CVS commands that CVS can't
# figure out for itself.
#
aegis -l cf -unf | sed 's| -> [0-9][0-9.]*||' |
while read usage action rev filename
do
    if test "x$filename" = "x"
    then
        filename="$rev"
    fi
    case $action in
    create)
	Command cvs add $filename
	;;
    remove)
	Command rm -f $filename
	Command cvs remove $filename
	;;
    *)
	;;
    esac
done

#
# Now commit all the changes.
#
message=`aesub '${version} - ${change description}'`
Command cvs -q commit -m \"$message\"

#
# All done.  Clean up and go home.
#
cd $here
rm -rf ${TMP}
exit 0