summaryrefslogtreecommitdiff
path: root/Master/Tools/p4changelog
blob: 96f1c2b29a08aa35ea830e27fceb46a85b086a09 (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
#!/bin/sh
# $Id: //depot/Master/Tools/p4changelog#7 $  $Date: 2005/05/29 $  $Author: karl $
# Public domain.  Originally written 2004, Karl Berry.
# Get change info from p4 describe and p4 changes.

umask 0

debug=${OVERRIDE_DEBUG-false}

mydir=`dirname $0`  # Master/Tools
outdir=`cd $mydir/../../Build/cdbuild/logs && pwd`
outfile=$outdir/log

line=`grep '^Change' $outfile | head -1`
lastlogged=`echo "$line" | awk '{print $2}'`
echo "$lastlogged" | egrep '^[0-9]+$' >/dev/null \
|| { echo "$0: no change number in Change line of $outfile: $line"; 
     exit 1; }
nextneeded=`expr $lastlogged + 1`
lastchange=`p4 changes -m 1 -s submitted | awk '{print $2}'`

echo "lastlogged=$lastlogged, nextneeded=$nextneeded, lastchange=$lastchange"

# nothing submitted since last change?
test $lastchange -lt $nextneeded && exit 0

rotate=false
for c in `seq $lastchange -1 $nextneeded`; do
  echo " getting change $c"
  # rotate if crossed a 500-change mark.
  echo $c | grep '[05]00$' >/dev/null && rotate=true

  p4 describe -ds $c 2>&1 \
  | sed -e 's,^\.\.\. //depot/, ,' -e '/^Differences/,$d' \
  | awk '/^Affected files/ { printf "%s", $0; next }  {print}' \
  >>$outfile.temp
done

# we'll update $outfile.
echo "p4 edit $outfile..."
$debug || p4 edit $outfile

if $rotate; then
  echo "rotating $lastlogged..."
  mv $outfile $outfile.$lastlogged
  gzip $outfile.$lastlogged
  chmod 444 $outfile.$lastlogged.gz
  ls -l $outfile.$lastlogged.gz
  $debug || p4 add $outfile.$lastlogged.gz
  cp /dev/null $outfile
fi

# prepend new changes to current log, put into p4.
cat $outfile.temp $outfile >$outfile.temp2

if $debug; then
  for f in $outfile $outfile.temp $outfile.temp2; do
    echo
    (cd `dirname $f` && ls -l `basename $f`)
    head -1 $f
    grep '^Change' $f | tail -1
  done

  exit 0
fi

mv $outfile.temp2 $outfile
echo "p4 submit..."
p4 change -o \
| sed "s!<enter description here>!regenerated by $0!" \
| p4 submit -i

cat $outfile.temp  # show it to me
rm -f $outfile.temp

exit 0

# this was how we grabbed all the old entries to get things started.
for c in `seq 5150 -1 1`; do
  expr $c % 500 >/dev/null \
  || { outfile=$outdir/out.$c; cp /dev/null $outfile; }

  # minimal diff, remove even that (hunk counts) with sed,
  # remove newline from "Affected files" line.
  p4 describe -ds $c 2>&1 \
  | sed -e 's,^\.\.\. //depot/, ,' -e '/^Differences/,$d' \
  | awk '/^Affected files/ { printf "%s", $0; next }  {print}' \
  >>$outfile
done