[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: parsing svn proplist -Rv

From: David Kastrup <dak_at_gnu.org>
Date: 2007-06-26 11:52:53 CEST

"Noam Tamim" <noamtm@gmail.com> writes:

> Has anyone here had success building a parser for "svn proplist -Rv"
> output? It seems hard to parse, especially considering the fact that
> property values can contain \n.

I use the following for transferring properties.

#!/usr/bin/awk -f
#
# call with a prefix and replacement, the replacement being suitable as a directory name:
# something like "file:///whatever/bla/branches/branch2007" "."

BEGIN {
    if (ARGC>=2) {
        keyword=""; prefix=ARGV[1]; replacement=ARGV[2];
        delete ARGV[1]; delete ARGV[2]
    } else {
        print "Usage: propimport.awk prefix replacement [file...]" >"/dev/stderr"
        print "Aus der Ausgabe von `svn pl -R -v' (in stdin oder file... als"
        print "input gegeben) wird durch Umschreiben des Repositories"
        print "prefix nach replacement (normalerweise ./) ein Shell-Skript"
        print "auf stdout generiert, das die Properties von prefix in"
        print "die Working Copy in replacement transferiert."
        print "Normalerweise wird man vorher alle properties in der"
        print "Working Copy mit `svn pd -R svn:...' löschen wollen."
        print "Macht man gleichzeitig ein svn add, so sollte das svn add"
        print "mit der Option --no-auto-props geschehen."
        exit 1
    }
}

function shellquote(arg)
{
    gsub(/["\`$]/,"\\\\\\0",arg)
    return "\"" arg "\""
}

function flushkeyword()
{
    if (keyword != "") {
        if (file != "")
            filelist[keyword,value,filecount[keyword,value]++]=shellquote(file)
        keyword=""
    }
}

/^Properties on '.*':/ { flushkeyword(); match($0,/'.*'/);
    result=substr($0,RSTART+1,RLENGTH-2)
    if (substr(result,1,length(prefix)) == prefix)
        file=replacement substr(result,length(prefix)+1)
    else
        file=""
    next
}

/^ svn:/ { flushkeyword(); keyword = $1; value=$0;
    gsub(/^ *[^ ]+ : /,"",value) ; next }

{
    if (keyword == "")
        print "Unexpected line " $0 >"/dev/stderr"
    else {
        value = value "\n" $0
    }
}

END{
    flushkeyword()
    for (combined in filecount) {
            split(combined,separate,SUBSEP)
            n=filecount[combined]
            if (n > 100) {
                printf("xargs svn propset -q %s %s <<\\\\EOF\n",
                       shellquote(separate[1]),shellquote(separate[2]))
                strend = "\n\\EOF"
            } else {
                printf("svn propset -q %s %s ",
                       shellquote(separate[1]),
                       shellquote(separate[2]))
                strend = ""
            }
            for (i=0; i<n; i++)
                printf(" %s", filelist[combined,i]);
            print strend;
    }
}

-- 
David Kastrup

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Tue Jun 26 12:10:56 2007

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.