Strony

niedziela, 21 lutego 2010

Personas for Firefox

Want to be a better Atlas member? Want to be a cool cat in your office? Want to impress your friends around? Use
this! ;)

wtorek, 9 lutego 2010

reallocate your code from one repository to another

I'm a bit too much python fan, so once again it would be a python script. Sorry! ;)

Imagine you want to move your code from one Subversion repository to another with all history preserved, but under different directory. No problem at all.


  1. First you need to dump contents of, let's say, source repository to the dump file, probably filtering out someone else's stuff:


    $> svnadmin dump /path/to/src/repo | \
    svndumpfilter --drop-empty-revs --renumber-revs \
    --skip-missing-merge-sources include SRCDIR > SRCDIR.dump


  2. Now filtering script:


    ##
    # @file realloc.py
    # @author Krzysztof Daniel Ciba (Krzysztof.Ciba@NOSPAMgmail.com)
    #
    import sys, os
    import optparse
    ##
    # @class realloc
    # @author Krzysztof Daniel Ciba (Krzysztof.Ciba@NOSPAMgmail.com)
    # @brief reads stdin dump file, changes all paths from SRC to DEST and prints it out to stdout
    class realloc( object ):

    ## c'tor
    # @param self "Me, myself and Irene"
    # @param src source path in dump file
    # @param dest destination path on dump file
    def __init__( self, src, dest ):
    self.src = src
    self.dest = dest

    def run( self ):
    for line in sys.stdin:
    line = line.strip("\n")
    if ( "Node-path:" in line or
    "Node-copyfrom-path:" in line ):
    if self.src in line:
    line = line.replace( self.src, self.dest )
    print line

    def check( option, opt_str, value, parser ):
    if ( str(value).startswith("/") ):
    raise optparse.OptionValueError( "value of " + opt_str + " should be a relative path!" )
    setattr( parser.values, option.dest, value )

    ## trigger processing
    if __name__ == "__main__":
    version = "%prog $Revision: 8715 $ by Krzysztof Daniel Ciba (Krzysztof.Ciba@NOSPAMgmail.com)"
    usage = "%prog [opts] [< indumpfile > outdumpfile]"
    parser = optparse.OptionParser( usage=usage, version=version )
    parser.add_option("--src", type="string", action="callback", callback=check, dest="src", help="source directory" )
    parser.add_option("--dest", type="string", action="callback", callback=check, dest="dest", help="destination directory" )
    opts, args = parser.parse_args(sys.argv[1:])
    if ( not opts.src and opts.dest ):
    parser.error("option --dest present but --src is missing")
    elif ( opts.src and not opts.dest ):
    parser.error("option --src present but --dest is missing")
    elif ( not opts.dest and not opts.dest ):
    parser.error( "options --src and --dest are required" )
    else:
    theApp = realloc( opts.src, opts.dest )
    sys.exit( theApp.run() )


  3. and it's action


    $> realloc.py --src SRCPATH --dest DESTPATH < SRCPATH.dump > DESTPATH.dump


  4. and standard loading to new repository:


    $> svnadmin load /path/to/new/repo < DESTPATH.dump




Not so much work, especially it could be used in pipes, i.e. dumping, filtering, reallocating and loading in the same time:


$> svnadmin dump /path/to/src/repo | svndumpfilter \
--drop-empty-revs --renumber-revs --skip-missing-merge-sources \
include SRCDIR | realloc.py --src SRCDIR --dest DESTDIR | \
svnadmin load /path/to/dest/repo


Hmmm... Of course it could be made better in some simple way using sed. Yes, I'm using sed from time to time, but NOT this time. ;)