4 This Perl script copies one Subversion location or set of locations to another,
5 in the same way as svn copy. Using the script allows more advanced operations,
6 in particular allowing svn:externals to be dealt with properly for branching
12 Run the script with no command line arguments to see all the command
13 line options it takes.
18 This script depends on module File::Temp. This became part of the standard
19 Perl distribution in 5.8.0. If you have an earlier version of Perl, you can
20 download it from CPAN at http://search.cpan.org/search?module=File::Temp .
21 It works with Perl versions from 5.005 onwards.
26 This script performs an svn copy command. It allows extra processing to get
27 around the following limitations of svn copy:
29 svn:externals definitions are (in Subversion 1.0 and 1.1 at least) absolute
30 paths. This means that an svn copy used as a branch or tag operation on a
31 tree with embedded svn:externals will not do what is expected. The
32 svn:externals will still point at the original location and will not be
38 Rename svncopy.pl.in to svncopy.pl.
40 Locate the following lines in the script:
42 # Specify the location of the svn command.
43 my $svn = '@SVN_BINDIR@/svn';
45 Replace @SVN_BINDIR@ with the path to your svn executable. This should be the
46 command you have to type to use the svn command line. If svn is on the path,
47 you can just set this line to:
51 Alternatively, if you have to type /usr/local/bin/svn, you should set it to:
53 my $svn = '/usr/local/bin/svn';
58 svncopy --update-externals (or svncopy --branch) will update any unversioned
59 svn:externals in the destination tree which point at locations within one of
60 the source trees so that they point to the corresponding locations within the
61 destination tree instead. This effectively updates the reference to
62 point to the destination tree, and is the behaviour you want for branching.
67 svncopy --pin-externals (or svncopy --tag) will update any unversioned
68 svn:externals in the destination tree to contain the current version of the
69 directory listed in the svn:externals definition. This effectively pins
70 the reference to the current version, and is the behaviour you want for tagging.
72 Note: both forms of the command leave unchanged any svn:externals which
73 already contain a version number.
78 These examples assume the following repository layout:
80 Path Last mod or svn:externals target
81 ---- --------------------------------
92 X common -r 4997 http://svn/repos/trunk/common
93 X inc http://svn/repos/trunk/inc
98 X common http://svn/repos/trunk/common
99 X inc http://svn/repos/trunk/inc
100 X public http://someserver/repos/public
102 i.e. both proj_foo and proj_bar have svn:externals set to:
104 common http://svn/repos/trunk/common
105 inc http://svn/repos/trunk/inc
107 with proj_foo having pinned common to version 4997.
109 Example 1 - using svn copy to tag (what not to do)
110 --------------------------------------------------
112 This is the naive way of creating a tag.
114 $ svn copy http://svn/repos/trunk/proj_bar \
115 http://svn/repos/tags/proj_bar/release_3.2
127 X common http://svn/repos/trunk/common
128 X inc http://svn/repos/trunk/inc
129 X public http://someserver/repos/public
131 The svn:externals are still pointing to the head revisions in trunk. Any
132 changes in trunk/common, trunk/inc or trunk/project/inc will modify the
133 subdirectories in tags/proj_bar/release_3.2. This is not the desired effect.
135 Example 2 - using svn copy to branch (what not to do)
136 -----------------------------------------------------
138 This is the naive way of creating a branch.
140 $ svn copy http://svn/repos/trunk/proj_bar \
141 http://svn/repos/branches/proj_bar/3.2_bugfix
154 X common http://svn/repos/trunk/common
155 X inc http://svn/repos/trunk/inc
156 X public http://someserver/repos/public
158 The svn:externals are still pointing to the head revisions in trunk. Any
159 changes in trunk/common, trunk/inc or trunk/project/inc will modify the
160 subdirectories in branches/proj_bar/3.2_bugfix/proj_bar. Worse, any
161 changes in these subdirectories will get propagated back to trunk. Again,
162 this is not the desired effect.
164 Example 3 - tagging properly
165 ----------------------------
167 Using the script allows tags to be created which won't change.
169 $ perl svncopy.pl --tag http://svn/repos/trunk/proj_bar \
170 http://svn/repos/tags/proj_bar/release_3.2
183 X common -r 5192 http://svn/repos/trunk/common
184 X inc -r 4986 http://svn/repos/trunk/inc
185 X public -r 17753 http://someserver/repos/public
187 The svn:externals are pinned to the latest repository version containing a
188 modification to the corresponding directories. The contents of the externals
191 Example 4 - tagging retrospectively
192 -----------------------------------
194 If you want to create a tag, but changes have been made since the version you
195 want to tag, all is not lost. Pass the revision number and the tag will be
196 done from there. E.g. if proj_foo should have been tagged at version 5001
197 (when common was at 4997), the following command will do the trick:
199 $ perl svncopy.pl --tag --revision 5001 http://svn/repos/trunk/proj_foo \
200 http://svn/repos/tags/proj_foo/release_2.7
212 X common -r 4997 http://svn/repos/trunk/common
213 X inc -r 4986 http://svn/repos/trunk/inc
215 The svn:externals are pinned to the latest repository version containing a
216 modification to the corresponding directories prior to revision 5002.
217 The contents of the externals will not change.
219 Example 5 - branching properly
220 ------------------------------
222 Using the script allows branches to be created which are really independent.
224 $ perl svncopy.pl --branch http://svn/repos/trunk \
225 http://svn/repos/branches/3.2_bugfix
243 X common -r 4997 http://svn/repos/trunk/common
244 X inc http://svn/repos/branches/3.2_bugfix/trunk/inc
249 X common http://svn/repos/branches/3.2_bugfix/trunk/common
250 X inc http://svn/repos/branches/3.2_bugfix/trunk/inc
251 X public http://someserver/repos/public
253 The svn:externals are now pointing to the corresponding directories in the
254 branch. The subdirectories in the branch will be unaffected by changes
255 in trunk, and similarly trunk will not be affected by changes in the branch.
257 Note: proj_foo/common was pinned to revision 4997 in trunk. Because of this
258 the script has left it unchanged.
260 Example 6 - branching part of a tree
261 ------------------------------------
263 If you don't want to branch the whole tree, you can just branch the directories
264 which contain your project:
266 $ perl svncopy.pl --branch http://svn/repos/trunk/common \
267 http://svn/repos/trunk/inc \
268 http://svn/repos/trunk/proj_bar \
269 http://svn/repos/branches/3.2_bugfix
287 X common http://svn/repos/branches/3.2_bugfix/common
288 X inc http://svn/repos/branches/3.2_bugfix/inc
289 X public http://someserver/repos/public
291 The svn:externals are now pointing to the corresponding directories in
292 the branch, as in Example 4.
294 Note: you *must* branch all affected directories simultaneously. If you
295 branch them one at a time, the script will not know which externals refer
296 to other components of the same project, and will leave them unchanged.
301 svncopy.pl comes with a script to do some basic testing, called testsvncopy.pl.
302 Installation is similar to svncopy.pl - update @SVN_BINDIR@. You also have to
303 supply a scratch repository location for the test script to use. Either update
304 @SVN_TEST_REPOSITORY@ in testsvncopy.pl.in or pass in the location using the
305 --test-repository parameter when running the script.