I'd like to apply a filter (e.g. sed -e 's/OLD/NEW/g'
) to svn property values, recursively.
First, on a single target, I could do one of the following:
svn propget --strict PROPNAME TARGET | sed -e 's/OLD/NEW/g' | svn propset PROPNAME --file=- TARGET
svn propset PROPNAME --file=<(svn propget --strict PROPNAME TARGET | sed -e 's/OLD/NEW/g') TARGET
SVN_EDITOR="sed -i -e 's/OLD/NEW/g'" svn propedit PROPNAME TARGET
svn propedit --editor-cmd "sed -i -e 's/OLD/NEW/g'" PROPNAME TARGET
Which one would be the best?
What I don't like about 1 or 2 is that even if the svn propget ... | sed ...
pipeline fails, svn propset
is still executed, probably on an empty stdin, resetting the property.
On the other hand, what I don't like about 3 or 4 is that the whole filtering command line should be quoted and made into one string, which sometimes makes quoting and parameter expansion tricky. And note the option -i
— the filtering command should take a file parameter and edit it in place, which means these methods cannot be applied to commands that don't offer such in-place editing feature, such as tr
or even awk
.
Is there any better alternative, or any possible improvements to one of these?
Second, how do I do this recursively — i.e. on every target under the given TARGET that has the specified property PROPNAME? I cannot just add -R
to svn propget
as it will concatenate everything into one stream of text, and svn propedit
doesn't even have -R
. It seems that I have to do something like:
svn proplist -R --only-with PROPNAME TARGET | while read target
do
# do one of the above on "$target"
done
but svn proplist
doesn't have such a thing called --only-with
, and I cannot easily parse its output and grab the names of only those targets that have the property.
Is there any good way to do it?