Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an applicable patch after doing svn remove and svn rename

Tags:

diff

svn

patch

  1. I have deleted some textual files using svn remove. But svn diff shows as removal of all content in the file. Applying a patch of that diff only modifies the content, does not remove the file.

  2. I renamed a directory which contains binary files using svn rename. A patch file from a normal svn diff does nothing.

How to make svn diff produce file that patch would apply, when svn cp or svn mv was used?

subversion diff including new files

Both the methods in above links does only modifications to the files. They do not get removed/renamed after applying a patch. Is it possible to get a working patch for the above changes?

like image 913
Nufail Avatar asked Sep 01 '11 09:09

Nufail


People also ask

How do I create a patch in svn?

Creating a Patch File First you need to make and test your changes. Then instead of using TortoiseSVN → Commit... on the parent folder, you select TortoiseSVN → Create Patch... you can now select the files you want included in the patch, just as you would with a full commit.

What is patch in svn?

A patch file is a Subversion unified diff file, which contains the information required to apply changes to a set of files. The patch may have been supplied by another developer so that you can see changes he has made and possibly commit them to the repository.

How to rename svn repository folder?

To rename a repository, just rename the directory where your repo relies: eg if your repo lies in /opt/svn/my_old_name just apply: mv /opt/svn/my_old_name /opt/svn/new_name No need for dump/reload!


3 Answers

From the patchman page:

-E or --remove-empty-files Remove output files that are empty after the patches have been applied. Normally this option is unnecessary, since patch can examine the time stamps on the header to deter‐ mine whether a file should exist after patching. However, if the input is not a context diff or if patch is conform‐ ing to POSIX, patch does not remove empty patched files unless this option is given. When patch removes a file, it also attempts to remove any empty ancestor directories.

like image 98
Diego Fernández Durán Avatar answered Sep 17 '22 23:09

Diego Fernández Durán


Try this:

patch -p0 -E < 1.patch && svn rm `svn st -q | grep ^! | cut -c 9-`
like image 29
Andrey Starodubtsev Avatar answered Sep 20 '22 23:09

Andrey Starodubtsev


I think the OP's second issue is caused by an SVN bug that was fixed in SVN 1.7. You change a directory structure (move, rename, delete) and commit it, but when using svn diff, the patch seems to "do nothing".

I had this problem when deleting directories and the symptoms are the same so I'm assuming we are experiencing the same "root bug". For me, updating to svn 1.7 solved it, because svn 1.7 generates diffs (patches) differently.

Some versions of svn diff don't put the moved/renamed/deleted files in the diff at all!

See: http://svn.haxx.se/dev/archive-2004-03/0333.shtml. This archived email from the SVN DEV list shows the devs themselves identified this problem, sometime before 1.0.1 was released, over a decade ago. If you follow the thread, they seemed quite determined to fix it then, but even 1.6 was also leaving stuff out of the diff. I had to update to 1.7.

Basically, if svn < 1.7 detected that a directory was svn delete'd, it would not recurse and process the children, it would just stop there and not put anything under that tree in the diff. This is not what we want, we want explicit removes for ALL of the children, so that patch can, as mentioned in other answer, remove empty files and directories via -E. Patch can't do anything if the file isn't in the patch.

Using svn 1.7 I did an identical diff as I did before but every file under a deleted directory was explicitly in the patch as having all lines removed (emptying), and then patch/quilt successfully removed the files and folders. I'm assuming something similar needs to happen in your case with moving or renaming.

GOTCHAS: Upgrading to 1.7 will leave your working copies useless. Make sure you commit your changes before updating. Then you have to checkout everything again. Edit: The SVN 1.7 client might be able to repair your working directories but if it can't you might need to checkout again. Just be aware so you don't lose work.

like image 33
Wilbur Whateley Avatar answered Sep 18 '22 23:09

Wilbur Whateley