1 #!/bin/bash
2 # $Id: //open/util/bin/packChange#7 $
3 #
4 # Pack a perforce changelist into a compressed TAR file
5 #
6 # Copyright (C) 2004-2004 The Eigenbase Project
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 usage() {
23 echo "Usage: packChange <change-list-number>"
24 }
25
26 cygwin=false;
27 case "`uname`" in
28 CYGWIN*) cygwin=true ;;
29 esac
30
31 if [ "$1" = -h -o "$1" = --help ]; then
32 usage
33 exit 0
34 fi
35
36 set -e
37
38 changeno=$1
39 if [ ! "$changeno" ]; then
40 echo "Error: you must specify a change number"
41 exit 1
42 fi
43 if [ $changeno == DEFAULT ]; then changeno=default; fi
44
45 if (p4 opened -c $changeno | egrep -i -q 'not opened on this client') ; then
46 "Error: File(s) not opened on this client."
47 exit 1
48 fi
49
50 # get the Perforce client name (compensate for case problems)
51 upper_client_name=`p4 info | grep "Client name" | cut -f 3 -d " " | tr "[:lower:]" "[:upper:]"`
52 lower_client_name=`p4 info | grep "Client name" | cut -f 3 -d " " | tr "[:upper:]" "[:lower:]"`
53
54 if [ $changeno == default ]; then
55 changefile=changelist.default.$lower_client_name
56 else
57 changefile=changelist${changeno}
58 fi
59 tarfile=${changefile}.tar.gz
60
61 touch changelist.desc
62 if [ $changeno != default ] ; then
63 # get the description of the specified changelist
64 p4 change -o $changeno | sed -e '
65 s/Change:.*/Change: new/;
66 s/Date:.*//;
67 s/Client:.*//;
68 s/User:.*//;
69 s/Status:.*//;
70 ' > changelist.desc
71 fi
72
73 # get all the files in the changelist (strip off the version numbers)
74 p4 opened -c $changeno | cut -f 1 -d "#" > changelist.nover
75
76 rm -f changelist.txt
77 while read file; do
78 line=`p4 opened "$file"`
79 line=${line//default change/change default};
80 case "$line" in
81 *\ \-\ edit\ change\ * ) ;;
82 *\ \-\ add\ change\ * ) ;;
83 *\ \-\ delete\ change\ * ) ;;
84 *\ \-\ branch\ change\ * )
85 lfile=`p4 where "$file" | sed -e 's/^.* \(.:.*\)/\1/g'`;
86 branchfrom=`p4 resolved "$lfile" | sed -e 's/^.* - branch from //g'`;
87 line=`echo "$line" | sed -e "s;#1;#$branchfrom;"`;
88 ;;
89 * ) echo "ERROR: don't know how to handle this file: '$line'"; exit 1;;
90
91 esac
92 echo "$line" | sed -e "s/ change $changeno .*//g" >> changelist.txt
93 done < changelist.nover
94
95 # get all the files in the changelist EXCEPT the deleted ones and branched ones
96 p4 opened -c $changeno |
97 grep -v ' - delete change ' |
98 grep -v ' - branch change ' |
99 cut -f 1 -d "#" > changelist.nover
100
101 # translate the depot file names to client file names and save them in
102 # a compressed tarfile
103 if $cygwin; then
104 pwddot=` cygpath -a -w $(pwd) | sed -e s'/././g'`;
105 while read file; do
106 # convert the path into an absolute windows path, for example
107 # 'c:\open\foo\bar.xml'; todo: handle spaces in file names
108 winpath=$(p4 where "$file" | awk '{print $3}')
109 cygpath -a -m $winpath
110 done < changelist.nover |
111 sed -e "s/^$pwddot/./g" > changelist.totar
112 else
113 pwddot=` if "$cygwin"; then cygpath $(pwd); else pwd; fi |
114 sed -e s'/././g'`;
115 while read file; do
116 p4 where "$file" | sed -e 's?^.* //.* \(/.*\)?\1?g'
117 done < changelist.nover |
118 sed -e "s/^$pwddot/./g" > changelist.totar
119 fi
120 tar -czf $tarfile --files-from changelist.totar changelist.txt changelist.desc
121
122 # clean up
123 rm changelist.txt changelist.desc changelist.nover changelist.totar
124
125 echo Successfully created $tarfile
126 tar tvzf $tarfile
127
128 # end packChange
2 # $Id: //open/util/bin/packChange#7 $
3 #
4 # Pack a perforce changelist into a compressed TAR file
5 #
6 # Copyright (C) 2004-2004 The Eigenbase Project
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 usage() {
23 echo "Usage: packChange <change-list-number>"
24 }
25
26 cygwin=false;
27 case "`uname`" in
28 CYGWIN*) cygwin=true ;;
29 esac
30
31 if [ "$1" = -h -o "$1" = --help ]; then
32 usage
33 exit 0
34 fi
35
36 set -e
37
38 changeno=$1
39 if [ ! "$changeno" ]; then
40 echo "Error: you must specify a change number"
41 exit 1
42 fi
43 if [ $changeno == DEFAULT ]; then changeno=default; fi
44
45 if (p4 opened -c $changeno | egrep -i -q 'not opened on this client') ; then
46 "Error: File(s) not opened on this client."
47 exit 1
48 fi
49
50 # get the Perforce client name (compensate for case problems)
51 upper_client_name=`p4 info | grep "Client name" | cut -f 3 -d " " | tr "[:lower:]" "[:upper:]"`
52 lower_client_name=`p4 info | grep "Client name" | cut -f 3 -d " " | tr "[:upper:]" "[:lower:]"`
53
54 if [ $changeno == default ]; then
55 changefile=changelist.default.$lower_client_name
56 else
57 changefile=changelist${changeno}
58 fi
59 tarfile=${changefile}.tar.gz
60
61 touch changelist.desc
62 if [ $changeno != default ] ; then
63 # get the description of the specified changelist
64 p4 change -o $changeno | sed -e '
65 s/Change:.*/Change: new/;
66 s/Date:.*//;
67 s/Client:.*//;
68 s/User:.*//;
69 s/Status:.*//;
70 ' > changelist.desc
71 fi
72
73 # get all the files in the changelist (strip off the version numbers)
74 p4 opened -c $changeno | cut -f 1 -d "#" > changelist.nover
75
76 rm -f changelist.txt
77 while read file; do
78 line=`p4 opened "$file"`
79 line=${line//default change/change default};
80 case "$line" in
81 *\ \-\ edit\ change\ * ) ;;
82 *\ \-\ add\ change\ * ) ;;
83 *\ \-\ delete\ change\ * ) ;;
84 *\ \-\ branch\ change\ * )
85 lfile=`p4 where "$file" | sed -e 's/^.* \(.:.*\)/\1/g'`;
86 branchfrom=`p4 resolved "$lfile" | sed -e 's/^.* - branch from //g'`;
87 line=`echo "$line" | sed -e "s;#1;#$branchfrom;"`;
88 ;;
89 * ) echo "ERROR: don't know how to handle this file: '$line'"; exit 1;;
90
91 esac
92 echo "$line" | sed -e "s/ change $changeno .*//g" >> changelist.txt
93 done < changelist.nover
94
95 # get all the files in the changelist EXCEPT the deleted ones and branched ones
96 p4 opened -c $changeno |
97 grep -v ' - delete change ' |
98 grep -v ' - branch change ' |
99 cut -f 1 -d "#" > changelist.nover
100
101 # translate the depot file names to client file names and save them in
102 # a compressed tarfile
103 if $cygwin; then
104 pwddot=` cygpath -a -w $(pwd) | sed -e s'/././g'`;
105 while read file; do
106 # convert the path into an absolute windows path, for example
107 # 'c:\open\foo\bar.xml'; todo: handle spaces in file names
108 winpath=$(p4 where "$file" | awk '{print $3}')
109 cygpath -a -m $winpath
110 done < changelist.nover |
111 sed -e "s/^$pwddot/./g" > changelist.totar
112 else
113 pwddot=` if "$cygwin"; then cygpath $(pwd); else pwd; fi |
114 sed -e s'/././g'`;
115 while read file; do
116 p4 where "$file" | sed -e 's?^.* //.* \(/.*\)?\1?g'
117 done < changelist.nover |
118 sed -e "s/^$pwddot/./g" > changelist.totar
119 fi
120 tar -czf $tarfile --files-from changelist.totar changelist.txt changelist.desc
121
122 # clean up
123 rm changelist.txt changelist.desc changelist.nover changelist.totar
124
125 echo Successfully created $tarfile
126 tar tvzf $tarfile
127
128 # end packChange