def list_authors( srcfile, git_fmt ):
    """
    List all the authors from the dump file.

    @type srcfile: string
    @param srcfile: Source filename.
    @type git_fmt: boolean
    @param rev_prop: Whether or not to output in git author file format
    """

    # SvnDumpFile classes for reading/writing dumps
    srcdmp = SvnDumpFile()
    # open source file
    authors=[]
    srcdmp.open( srcfile )
    hasrev = srcdmp.read_next_rev()
    if hasrev:
        while hasrev:
            if srcdmp.has_rev_prop( "svn:author" ):
                author=srcdmp.get_rev_prop_value("svn:author")
                if author not in authors:
                    authors.append(author)
            hasrev = srcdmp.read_next_rev()
    else:
        print "no revisions in the source dump '%s' ???" % srcfile

    authors.sort()
    fmt="%s"
    if git_fmt:
        fmt = "%s = RealName <email>"
    for author in authors:
        print fmt % author
    # cleanup
    srcdmp.close()
Beispiel #2
0
def list_files(srcfile, lister):
    """
    List the largest files from the dump file.

    @type srcfile: string
    @param srcfile: Source filename.
    @type dstfile: string
    @param dstfile: Destination filename.
    """

    # SvnDumpFile classes for reading/writing dumps
    srcdmp = SvnDumpFile()
    # open source file
    srcdmp.open(srcfile)
    hasrev = srcdmp.read_next_rev()
    if hasrev:
        while hasrev:
            if srcdmp.get_node_count() > 0:
                for node in srcdmp.get_nodes_iter():
                    lister.process_node(srcdmp, node)
            hasrev = srcdmp.read_next_rev()
    else:
        print("no revisions in the source dump '%s' ???" % srcfile)
    lister.done(srcdmp)

    # cleanup
    srcdmp.close()
Beispiel #3
0
def copy_adding_git_ignore(srcfile, dstfile):
    """
    Copy a dump file adding .gitignore files in all directories that have
    an svn:ignore property.

    @type srcfile: string
    @param srcfile: Source filename.
    @type dstfile: string
    @param dstfile: Destination filename.
    """

    # SvnDumpFile classes for reading/writing dumps
    srcdmp = SvnDumpFile()
    dstdmp = SvnDumpFile()

    # open source file
    srcdmp.open(srcfile)
    gitignores = {}
    # used to ensure that copyfrom-revs are correct after the copy.  If
    # there are any empty revision in the source dump file, the copyfrom-revs
    # could be affected.
    revmap = {}

    hasrev = srcdmp.read_next_rev()
    if hasrev:
        # create the dump file
        dstdmp.create_like(dstfile, srcdmp)
        # now copy all the revisions
        while hasrev:
            dstdmp.add_rev(srcdmp.get_rev_props())
            for node in srcdmp.get_nodes_iter():
                if node.has_copy_from():
                    node.set_copy_from(node.get_copy_from_path(), revmap[node.get_copy_from_rev()])
                # add the original node
                dstdmp.add_node(node)
                if node.get_property("svn:ignore") is not None:
                    # find out what the change is and act on it appropriately
                    path = node.get_path() + "/.gitignore"
                    action = node.get_action()
                    if action == "change" or action == "add":
                        if path in gitignores:
                            # already saw this one - it is a change to the .gitignore file
                            newnode = SvnDumpNode(path, "change", "file")
                        else:
                            # haven't seen this one yet
                            newnode = SvnDumpNode(path, "add", "file")
                            gitignores[path] = True
                        f = open("gitignore", "wb")
                        f.write(node.get_property("svn:ignore"))
                        f.close()
                        newnode.set_text_file("gitignore")
                        dstdmp.add_node(newnode)
                        os.remove("gitignore")
                    elif action == "delete":
                        newnode = SvnDumpNode(path, "delete", "file")
                        dstdmp.add_node(newnode)
                        del gitignores[path]
                    else:
                        print("Unhandled action: '%s'" % action)
            revmap[srcdmp.get_rev_nr()] = dstdmp.get_rev_nr()
            hasrev = srcdmp.read_next_rev()
    else:
        print("no revisions in the source dump '%s' ???" % srcfile)

    # cleanup
    srcdmp.close()
    dstdmp.close()
Beispiel #4
0
def copy_remove_prop(propname, regex, srcfile, dstfile):
    """
    Copy a dump file while removing all properties with values matching a given regex.

    @type srcfile: string
    @param srcfile: Source filename.
    @type dstfile: string
    @param dstfile: Destination filename.
    """

    _regex = re.compile(regex, re.M)

    # SvnDumpFile classes for reading/writing dumps
    srcdmp = SvnDumpFile()
    dstdmp = SvnDumpFile()

    # open source file
    srcdmp.open(srcfile)

    # used to ensure that copyfrom-revs are correct after the copy.  If
    # there are any empty revision in the source dump file, the copyfrom-revs
    # could be affected.
    revmap = {}

    hasrev = srcdmp.read_next_rev()
    if hasrev:
        # create the dump file
        dstdmp.create_like(dstfile, srcdmp)
        # now copy all the revisions
        while hasrev:
            dstdmp.add_rev(srcdmp.get_rev_props())
            for node in srcdmp.get_nodes_iter():
                if node.has_copy_from():
                    node.set_copy_from(node.get_copy_from_path(), revmap[node.get_copy_from_rev()])

                propvalue = node.get_property(propname)
                if propvalue is not None and _regex.match(propvalue):
                    print "removing property " + propname + " with value " + propvalue.strip()
                    node.del_property(propname)
                dstdmp.add_node(node)

            revmap[srcdmp.get_rev_nr()] = dstdmp.get_rev_nr()
            hasrev = srcdmp.read_next_rev()
    else:
        print "no revisions in the source dump '%s' ???" % srcfile

    # cleanup
    srcdmp.close()
    dstdmp.close()
Beispiel #5
0
def copy_without_empty_revs( srcfile, dstfile ):
    """
    Copy a dump file excluding all empty revisions.

    @type srcfile: string
    @param srcfile: Source filename.
    @type dstfile: string
    @param dstfile: Destination filename.
    """

    # SvnDumpFile classes for reading/writing dumps
    srcdmp = SvnDumpFile()
    dstdmp = SvnDumpFile()

    # open source file
    srcdmp.open( srcfile )
    # used to ensure that copyfrom-revs are correct after the copy.  If
    # there are any empty revision in the source dump file, the copyfrom-revs
    # could be affected.
    revmap={}
    hasrev = srcdmp.read_next_rev()
    if hasrev:
        # create the dump file
        dstdmp.create_like( dstfile, srcdmp )
        # now copy all the revisions
        while hasrev:
            if srcdmp.get_node_count() > 0:
                for node in srcdmp.get_nodes_iter():
                    if node.has_copy_from():
                        node.set_copy_from(node.get_copy_from_path(),revmap[node.get_copy_from_rev()])
                dstdmp.add_rev_from_dump( srcdmp )
            else:
                print "Dropping empty revision: %d." % srcdmp.get_rev_nr()
            revmap[srcdmp.get_rev_nr()] = dstdmp.get_rev_nr()
            hasrev = srcdmp.read_next_rev()
    else:
        print "no revisions in the source dump '%s' ???" % srcfile

    # cleanup
    srcdmp.close()
    dstdmp.close()
Beispiel #6
0
 def apply( self ):
     """
     Applies the auto-props.
     """
     try:
         self._read_config()
         inDump = SvnDumpFile()
         outDump = SvnDumpFile()
         inDump.open( self.inputfilename )
         inDump.read_next_rev()
         outDump.create_like( self.outputfilename, inDump )
         while inDump.has_revision():
             print "revision %d" % inDump.get_rev_nr();
             outDump.add_rev( inDump.get_rev_props() )
             for index in range( 0, inDump.get_node_count() ):
                 node = inDump.get_node( index )
                 action = node.get_action()
                 if action in ( "add", "replace" ):
                     self._set_properties( node )
                 elif action == "change" and node.has_properties():
                     self._set_properties( node )
                 outDump.add_node( node )
             inDump.read_next_rev()
         inDump.close()
         outDump.close()
     except Exception, ex:
         print "Error:", ex
         return 1
Beispiel #7
0
def copy_remove_prop(propname, regex, srcfile, dstfile):
    """
    Copy a dump file while removing all properties with values matching a given regex.

    @type srcfile: string
    @param srcfile: Source filename.
    @type dstfile: string
    @param dstfile: Destination filename.
    """

    _regex = re.compile(regex, re.M)

    # SvnDumpFile classes for reading/writing dumps
    srcdmp = SvnDumpFile()
    dstdmp = SvnDumpFile()

    # open source file
    srcdmp.open(srcfile)

    # used to ensure that copyfrom-revs are correct after the copy.  If
    # there are any empty revision in the source dump file, the copyfrom-revs
    # could be affected.
    revmap = {}

    hasrev = srcdmp.read_next_rev()
    if hasrev:
        # create the dump file
        dstdmp.create_like(dstfile, srcdmp)
        # now copy all the revisions
        while hasrev:
            dstdmp.add_rev(srcdmp.get_rev_props())
            for node in srcdmp.get_nodes_iter():
                if node.has_copy_from():
                    node.set_copy_from(node.get_copy_from_path(),
                                       revmap[node.get_copy_from_rev()])

                propvalue = node.get_property(propname)
                if propvalue is not None and _regex.match(propvalue):
                    print("removing property " + propname + " with value " +
                          propvalue.strip())
                    node.del_property(propname)
                dstdmp.add_node(node)

            revmap[srcdmp.get_rev_nr()] = dstdmp.get_rev_nr()
            hasrev = srcdmp.read_next_rev()
    else:
        print("no revisions in the source dump '%s' ???" % srcfile)

    # cleanup
    srcdmp.close()
    dstdmp.close()
Beispiel #8
0
def copy_without_empty_revs(srcfile, dstfile):
    """
    Copy a dump file excluding all empty revisions.

    @type srcfile: string
    @param srcfile: Source filename.
    @type dstfile: string
    @param dstfile: Destination filename.
    """

    # SvnDumpFile classes for reading/writing dumps
    srcdmp = SvnDumpFile()
    dstdmp = SvnDumpFile()

    # open source file
    srcdmp.open(srcfile)
    # used to ensure that copyfrom-revs are correct after the copy.  If
    # there are any empty revision in the source dump file, the copyfrom-revs
    # could be affected.
    revmap = {}
    hasrev = srcdmp.read_next_rev()
    if hasrev:
        # create the dump file
        dstdmp.create_like(dstfile, srcdmp)
        # now copy all the revisions
        while hasrev:
            if srcdmp.get_node_count() > 0:
                for node in srcdmp.get_nodes_iter():
                    if node.has_copy_from():
                        node.set_copy_from(node.get_copy_from_path(),
                                           revmap[node.get_copy_from_rev()])
                dstdmp.add_rev_from_dump(srcdmp)
            else:
                print("Dropping empty revision: %d." % srcdmp.get_rev_nr())
            revmap[srcdmp.get_rev_nr()] = dstdmp.get_rev_nr()
            hasrev = srcdmp.read_next_rev()
    else:
        print("no revisions in the source dump '%s' ???" % srcfile)

    # cleanup
    srcdmp.close()
    dstdmp.close()