Can I use Regular expression in svndumpfilter include statement?

我的未来我决定 提交于 2020-01-15 05:23:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!