~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fai/aba/aba-lib

  • Committer: Robert Collins
  • Date: 2005-09-08 11:21:38 UTC
  • mto: (147.2.6) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20050908112138-033369d3cacacb55
test and deliver basic pending-merges into bzr so that merging is recorded

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Copyright (C) 2004 Aaron Bentley
 
3
#
 
4
# See the file "COPYING" for further information about
 
5
# the copyright and warranty status of this work.
 
6
 
 
7
# Runs a standard aba command
 
8
aba_run()
 
9
{
 
10
if [ -z "$abaname" ]; then
 
11
  aba "$(basename $0)" "$@"
 
12
  exit
 
13
fi
 
14
 
 
15
case "$1" in
 
16
  "exec" )
 
17
  shift
 
18
  if [ "$1" = "-h" ] ; then
 
19
    cmd_help
 
20
  elif [ "$1" = "--help" ] ; then
 
21
    cmd_help
 
22
  elif [ "$1" = "-H" ] ; then
 
23
    cmd_help
 
24
    cmd_ext_help
 
25
  else
 
26
    if [ -n "$ABAFILTER" ]; then
 
27
      cmd_exec "$@" | $ABAFILTER
 
28
    else 
 
29
      cmd_exec "$@"
 
30
    fi
 
31
  fi
 
32
  ;;
 
33
  "desc" )
 
34
  cmd_desc
 
35
  ;;
 
36
esac
 
37
}
 
38
 
 
39
# Runs a command that functions as a tla wrapper
 
40
# The difference from aba_run is the handling of extended help
 
41
aba_run_tlawrap()
 
42
{
 
43
if [ -z "$abaname" ]; then
 
44
  aba "$(basename $0)" "$@"
 
45
  exit
 
46
fi
 
47
 
 
48
case "$1" in
 
49
  "exec" )
 
50
  shift
 
51
  if [ "$1" = "-h" ] ; then
 
52
    cmd_help
 
53
  elif [ "$1" = "--help" ] ; then
 
54
    cmd_help
 
55
  elif [ "$1" = "-H" ] ; then
 
56
    cmd_ext_help
 
57
  else
 
58
    if [ -n "$ABAFILTER" ]; then
 
59
      cmd_exec "$@" | $ABAFILTER
 
60
    else 
 
61
      cmd_exec "$@"
 
62
    fi
 
63
  fi
 
64
  ;;
 
65
  "desc" )
 
66
  cmd_desc
 
67
  ;;
 
68
esac
 
69
}
 
70
 
 
71
# Outputs the tag source of the current tree, according to patch-logs
 
72
# May be wrong under certain contrived circumstances
 
73
aba_tree_source()
 
74
{
 
75
  logs=$(tla logs 2>/dev/null)
 
76
  if [ $? -ne 0 ]; then
 
77
    return 2
 
78
  fi
 
79
 
 
80
  tagsource=$(for r in $logs; do tla cat-log $r;done|grep "Continuation-of: "|head -n 1|sed s/"Continuation-of: "//)
 
81
  if [ -z "$tagsource" ]; then
 
82
    return 1
 
83
  fi
 
84
  echo $tagsource
 
85
}
 
86
 
 
87
#Converts a fully-qualified revision to a fully-qualified version
 
88
aba_fqversion()
 
89
{
 
90
  echo $(tla parse-package-name -a $1)/$(tla parse-package-name --package-version $1)
 
91
}
 
92
 
 
93
# Outputs a full revision name; input may be either
 
94
# a full revision name
 
95
# a patchlevel refering to the current tree version
 
96
aba_revision_or_version()
 
97
{
 
98
  name=$(aba_full_revision $@)
 
99
  if [ -z "$name" ]; then
 
100
    if tla valid-package-name -p -v $1; then
 
101
      name=$1
 
102
    fi
 
103
  fi
 
104
  echo $name
 
105
}
 
106
 
 
107
# Outputs a full revision name; input may be either
 
108
# a full revision name
 
109
# a patchlevel refering to the current tree version
 
110
aba_full_revision()
 
111
{
 
112
  if [ -z "$1" ]; then
 
113
    aba_tree_revision
 
114
    return $?
 
115
  fi
 
116
  if tla valid-package-name -p -v --lvl $1; then
 
117
    echo $1
 
118
  else
 
119
    newname=`tla tree-version 2> /dev/null`--$1
 
120
    if tla valid-package-name -p -v --lvl $newname; then
 
121
      echo $newname
 
122
    fi
 
123
  fi
 
124
}
 
125
 
 
126
# Executes the given command, omitting the last $1 lines
 
127
# $1 is the number of lines
 
128
#
 
129
aba_omit_last()
 
130
{
 
131
  n=$1;
 
132
  shift;
 
133
  my_local_lines="$(expr $("$@" | wc -l) - $n)"
 
134
  "$@" | head  -n $my_local_lines
 
135
  unset my_local_lines
 
136
}
 
137
 
 
138
# Outputs a tla-style command description 
 
139
aba_desc()
 
140
{
 
141
  cmd=$1;
 
142
  shift;
 
143
  printf "%28s : %s\n" $cmd "$*"
 
144
}
 
145
 
 
146
# Creates a temporary directory and outputs its filename
 
147
aba_mktempdir()
 
148
{
 
149
  if [ -z "$TMPDIR" ]; then
 
150
    TMPDIR="/tmp"
 
151
  fi
 
152
  mktemp -d "$TMPDIR/aba.XXXXXX"
 
153
  if [ $? -ne 0 ] ; then
 
154
    echo "panic: Could not create temporary directory!"
 
155
    exit 2
 
156
  fi
 
157
}
 
158
 
 
159
# Outputs a temporary filename
 
160
aba_mktemp()
 
161
{
 
162
  if [ -z "$TMPDIR" ]; then
 
163
    TMPDIR="/tmp"
 
164
  fi
 
165
  mktemp "$TMPDIR/aba.XXXXXX"
 
166
  if [ $? -ne 0 ] ; then
 
167
    echo "panic: Could not create temporary file!"
 
168
    exit 2
 
169
  fi
 
170
}
 
171
 
 
172
# Attempts to execute a command, panics if returns non-zero
 
173
aba_try()
 
174
{
 
175
  "$@"
 
176
  if [ $? -ne 0 ] ; then
 
177
    echo PANIC: failed to execute $@ >&2
 
178
    exit 2
 
179
  fi
 
180
}
 
181
 
 
182
# Undoes a star-merge
 
183
# Takes the same parameters as star-merge (except --changes)
 
184
aba_star_merge_undo()
 
185
{
 
186
  tmp=$(aba_mktempdir)
 
187
  treeroot=$(tla tree-root)
 
188
  echo "* undoing current changes"
 
189
  aba_try tla undo > /dev/null
 
190
  echo "* generating star-merge changeset"
 
191
  aba_try tla star-merge --changes $tmp/merge-undo "$@" > /dev/null
 
192
  echo "* redoing changes"
 
193
  aba_try tla redo > /dev/null
 
194
  echo "* reverse-applying star-merge changeset"
 
195
  tla dopatch --reverse $tmp/merge-undo $treeroot
 
196
  status=$?
 
197
  if [ $status -gt 1 ]; then 
 
198
    echo Failed to execute tla dopatch --reverse $tmp/merge-undo . >&2
 
199
    return $status
 
200
  fi
 
201
  aba_try rm -Rf $tmp
 
202
  return $status
 
203
}
 
204
 
 
205
# Outputs the project tree revision
 
206
aba_tree_revision()
 
207
{
 
208
  tla logs -d "${1:-.}" -r -f | head -n 1
 
209
}
 
210
 
 
211
# Break any links that the given file may have
 
212
aba_break_link()
 
213
{
 
214
   cp -p $1 '++brokelink' && mv '++brokelink' $1
 
215
   if [ $? -ne 0 ]; then
 
216
     echo "Can't break link for $1"
 
217
     exit 2
 
218
   fi
 
219
}
 
220
 
 
221
# Ensure that the project tree has no uncommitted changes
 
222
aba_no_changes ()
 
223
{
 
224
  tla changes > /dev/null
 
225
  status=$?
 
226
  if [ $status -eq 1 ]; then 
 
227
    echo Project tree has uncommitted changes.  Aborting. 2>&2
 
228
    exit 1;
 
229
  fi
 
230
  if [ $status -gt 1 ]; then
 
231
    exit $status;
 
232
  fi
 
233
}
 
234
 
 
235
# Determine whether a command supports a given option (long form required)
 
236
aba_supports_option()
 
237
{
 
238
  tla $1 -h | grep -- "--$2" >/dev/null
 
239
  return $?
 
240
}
 
241
 
 
242
# Echoes message to stderr, exits with status 2
 
243
aba_panic()
 
244
{
 
245
  echo $@ >&2
 
246
  exit 2
 
247
}
 
248
 
 
249
aba_merge_source()
 
250
{
 
251
  tree_root=`tla tree-root 2> /dev/null`
 
252
  if [ $? -ne 0 ]; then
 
253
      echo "not in project tree ($(pwd))" >&2
 
254
      exit 2;
 
255
    exit 1
 
256
  fi
 
257
  if [ -f $tree_root/{arch}/+partner-versions ]; then
 
258
    partnerfile=$tree_root/{arch}/+partner-versions 
 
259
  else 
 
260
    partnerfile=$tree_root/{arch}/=partner-versions
 
261
  fi
 
262
  mergefile=$tree_root/++merge-source 
 
263
  if [ -n "$1" ]; then
 
264
    sourcever=$1;
 
265
    sourcetype="[supplied]"
 
266
  elif [ -f $partnerfile ] ; then
 
267
    sourcever=$(cat $partnerfile)
 
268
    sourcetype="[from partner-versions]"
 
269
  elif [ -f $mergefile ] ; then
 
270
    sourcever=$(cat $mergefile)
 
271
    sourcetype="[from ++merge-source]"
 
272
  else
 
273
    treesource=$(aba_tree_source)
 
274
    status=$?;
 
275
    # always false
 
276
    if [ $status -eq 2 ]; then
 
277
      echo "merge: not in project tree ($(pwd))" >&2
 
278
      exit 2;
 
279
    fi
 
280
    if [ $status -ne 0 ]; then
 
281
      echo "aba merge: Unable to find $sourcefile" or tag source >&2
 
282
      exit 1;
 
283
    fi
 
284
    sourcever="$(tla parse-package-name -a $treesource)/$(tla parse-package-name --package-version $treesource)"
 
285
    sourcetype="[from tag-source]"
 
286
  fi
 
287
}
 
288
aba_tag_this()
 
289
{
 
290
  tla tag -S `aba_tree_revision` $1 
 
291
}
 
292
aba_change_version()
 
293
{
 
294
  root=$(tla tree-root)
 
295
  if [ $? -ne 0 ]; then
 
296
    aba_panic "Unable to determine tree root"
 
297
  fi
 
298
  from=$(aba_tree_revision)
 
299
  if [ $? -ne 0 ]; then
 
300
    aba_panic "Unable to determine tree revision"
 
301
  fi
 
302
  to=$(tla revisions -f $1|tail -n 1)
 
303
  if [ $? -ne 0 ]; then
 
304
    aba_panic "Unable to determine target revision"
 
305
  fi
 
306
  if [ -z "$to" ]; then
 
307
    aba_panic "Unable to determine target revision"
 
308
  fi
 
309
  aba_try tla apply-delta --dir $root $from $to
 
310
  aba_try tla set-tree-version $1
 
311
}
 
312
# arch-tag: runner by Aaron Bentley (07:50 Jan 19, 2004)