Example #1
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()
Example #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()
Example #3
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()
Example #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()
Example #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()
Example #6
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()
Example #7
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()
Example #8
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()