P. 1
svn-book

svn-book

|Views: 31|Likes:
Published by anandkumarshah

More info:

Published by: anandkumarshah on Sep 23, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

04/01/2014

pdf

text

original

Creating a branch is very simple—you make a copy of the project in the repository using the svn copy command. Subversion is
able to copy not only single files, but whole directories as well. In this case, you want to make a copy of the /calc/trunk dir-
ectory. Where should the new copy live? Wherever you wish—it's a matter of project policy. Let's say that your team has a policy
of creating branches in the /calc/branches area of the repository, and you want to name your branch my-calc-branch.
You'll want to create a new directory, /calc/branches/my-calc-branch, which begins its life as a copy of /
calc/trunk.

You may already have seen svn copy used to copy one file to another within a working copy. But it can also be used to do a
“remote” copy entirely within the repository. Just copy one URL to another:

$ svn copy http://svn.example.com/repos/calc/trunk \
http://svn.example.com/repos/calc/branches/my-calc-branch \
-m "Creating a private branch of /calc/trunk."

Committed revision 341.

This command causes a near-instantaneous commit in the repository, creating a new directory in revision 341. The new directory is
a copy of /calc/trunk. This is shown in Figure 4.3, “Repository with new copy”. 1

While it's also possible to create a branch
by using svn copy to duplicate a directory within the working copy, this technique isn't recommended. It can be quite slow, in fact!
Copying a directory on the client side is a linear-time operation, in that it actually has to duplicate every file and subdirectory on
the local disk. Copying a directory on the server, however, is a constant-time operation, and it's the way most people create
branches.

Figure 4.3. Repository with new copy

Branching and Merging

85

Cheap Copies

Subversion's repository has a special design. When you copy a directory, you don't need to worry about the repository grow-
ing huge—Subversion doesn't actually duplicate any data. Instead, it creates a new directory entry that points to an existing
tree. If you're an experienced Unix user, you'll recognize this as the same concept behind a hard link. As further changes are
made to files and directories beneath the copied directory, Subversion continues to employ this hard link concept where it
can. It duplicates data only when it is necessary to disambiguate different versions of objects.

This is why you'll often hear Subversion users talk about “cheap copies.” It doesn't matter how large the directory is—it
takes a very tiny, constant amount of time and space to make a copy of it. In fact, this feature is the basis of how commits
work in Subversion: each revision is a “cheap copy” of the previous revision, with a few items lazily changed within. (To
read more about this, visit Subversion's web site and read about the “bubble up” method in Subversion's design documents.)

Of course, these internal mechanics of copying and sharing data are hidden from the user, who simply sees copies of trees.
The main point here is that copies are cheap, both in time and in space. If you create a branch entirely within the repository
(by running svn copy URL1 URL2), it's a quick, constant-time operation. Make branches as often as you want.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->