tags:

views:

1326

answers:

3

If I do an svn copy using two urls, I get a 'cheap' copy in the repository...

svn copy http://repo_url/trunk http://repo_url/tags/release_foo

But what if do the copy in the working directory and then commit it like this...

svn copy trunk tags/release_foo
svn commit tags/release_foo

The copy creates local copies of the files which are automatically svn added. They only go into the repository when committed.

The examples in the doco always seem to use the url to url copy for tagging or branching but I couldn't find anything that explicitly states that you should not use WC to WC followed by a commit.

So are these two methods the same? Do both create a cheap copy inside the repository?

+4  A: 

I believe that a url copy and a WC copy are pretty much the same thing when it comes to being "cheap". In your WC any copy that is made isn't a copy like copying a file on a file system.

svn is smart in that it basically creates some soft links from the origin to your new tag, branch or whatever.

hacintosh
Copying without making changes is always a cheap operation. (server/wc <-> server/wc). The changes take up the space.
Bert Huijben
What exactly does it mean if an action is 'cheap'? Is it a bad action to take? If so, what is the recommended way to tag and/or branch using SVN?
Dave
@Dave: in this case, the action is cheap in terms of processing power and storage space (i.e. it doesn't use much of each, which is a good thing). This is because SVN will store only the information indicating that a copy took place, not the actual copied files/folders.
rmeador
@meador thanks for the clarification! Though when I svn copy trunk as a tag or so, the files show up again there as separate files. So do you mean that he doesn't actually copy on the server side only?
Dave
+1  A: 

Don't do this:

svn merge <local copy>/branch <local copy>/trunk

Your commands like this, can be similarly troublesome:

svn copy trunk tags/release_foo
svn commit tags/release_foo

While copying in a local working copy is fine, but these commands make it look like you've checked out the entire repository into a single working copy. I had someone do this and we ended up having to delete trunk and copy it from a previous revision. Unforutnately, I don't remember the details of what boxed us into that corner. I do remember, things go south very quickly when you try to do merges between branches on "local" directories.

Always use repository URLs for creating/managing/merging tags and branches. It's safer. It guarantees your working copy isn't out-of-date for creating the tag/branch and also guarantees the creation is transactional.

I think the problem may have happened like this:

  1. Person A updates their mass everything working copy
  2. Person A makes some tags, does some branches, does some merges, but has not committed, yet.
  3. Person B commits some changes to the source of those tags, or the branch that was merged.
  4. Person A tries to commit and svn won't let them.

Again it was a number of years ago, so I don't remember the specifics, but there isn't really a good reason to set your working copy up like that.

Otto
It is perfectly fine to copy files/folders inside a working copy. If you had problems it is clearly a case of PIBCAC. Also, in SVN, you can only merge into a local working copy.
Peter Parker
I've edited to clarify what I mean.Yes it was PIBCAC. In this case the person had checked out the entire subversion tree, rather than trunk or the branch he wanted because "It was easier".It also really mucks things up.
Otto
"Also, in SVN, you can only merge into a local working copy." ... right, he was trying to merge /from/ a local working copy into the same local working copy.
Otto
+5  A: 

When you do the copy locally, you will of course incur a space and time cost from copying the files on your local machine (your local filesystem doesn't know about SVN deltas), but when you go to commit, you should see that only the root of the copied directory structure is listed as added (with history). It will thus create the "cheap" copy on the server when you commit.

That said, the URL copy method is generally preferred for branching or tagging because it doesn't require you to have checked out the repository root (including all branches and tags -- this would be huge!). The normal use case is to branch/tag server-side (using the URL copy), then check out the branches/tags on an as-needed basis for your work.

If you're just copying a file or folder within your working copy for some reason (say you're breaking one class file into two and you want to preserve the common history), then just use svn copy in your WC.

rmeador
This is the more concise version of the point I was trying to make, except "generally preferred" means "you really could hose things up". :)
Otto