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
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
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()
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()
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()