问题
I need to export data from svn (server on Windows), but i don't want to include root directory. Example:
svn
-project1
--trunk
--branches
-project2
--trunk
--branches
--onemorefolder
I want to include to project1.dump folders: trunk and branches (not project1) I use:
svnadmin dump /svn/ | svndumpfilter include --drop-empty-revs --renumber-revs /project1/trunk /project1/branches | sed "s/Node-path:[ ]project1\//Node-path: /g" -b | sed "s/Node-copyfrom-path:[ ]project1\//Node-copyfrom-path: /g" -b > project1.dump
But I want to automate this process and created bat file:
call svnadmin dump /svn/iss/ -r %2:%3 | svndumpfilter include --drop-empty-revs --renumber-revs /%1/trunk /%1/branches | sed "s/Node-path:[ ]%1\//Node-path: /g" -b | sed "s/Node-copyfrom-path:[ ]%1\//Node-copyfrom-path: /g" -b > %4
But it works only with structure where are trunk and branches folders. How can i include all folders from my root folder and exclude this root folder? Can I use regex in include statement? Thanks.
回答1:
First you could do both the sed
commands as one:
Instead of
sed "s/Node-path:[ ]%1\//Node-path: /g" -b | \
sed "s/Node-copyfrom-path:[ ]%1\//Node-copyfrom-path: /g" -b
you could do
sed "s/Node-\(copyfrom-\|\)path:[ ]%1\//Node-\1path: /g" -b
which uses the backreference \1
in the pattern to match Node-path
or Node-copyfrom-path
.
For all subfolders of root, excluding the root folder itself, maybe you can try using find <ROOTFOLDER> -type d -mindepth 1 -maxdepth 1
which finds all subdirectories not including the root itself.
Perhaps something like (untested):
call svnadmin dump /svn/iss/ -r %2:%3 | \ # keep same
svndumpfilter include --drop-empty-revs --renumber-revs \
`find %1 -type d -maxdepth 1 -mindepth 1` | \ # used find
sed "s/Node-\(copyfrom-|\)path:[ ]%1\//Node-\1path: /g" -b \ # combined line
> %4
来源:https://stackoverflow.com/questions/8667116/can-i-use-regular-expression-in-svndumpfilter-include-statement