diff options
author | Mirko Friedenhagen <mirko.friedenhagen@1und1.de> | 2008-05-08 18:31:41 +0200 |
---|---|---|
committer | Mirko Friedenhagen <mirko.friedenhagen@1und1.de> | 2008-05-08 18:31:41 +0200 |
commit | 664d375943dbd8db9f2e3887fa2dc02686432a72 (patch) | |
tree | 8ad79b219d52837842b6a071a1afed9a189ca7a0 /exporters | |
parent | b150e4d34464da333be2910ecc54bb747f7b8faa (diff) | |
download | bzr-fastimport-664d375943dbd8db9f2e3887fa2dc02686432a72.tar.gz |
Use regular expressions to allow better control for files to export.
Diffstat (limited to 'exporters')
-rwxr-xr-x | exporters/svn-fast-export.py | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/exporters/svn-fast-export.py b/exporters/svn-fast-export.py index f2719ae..e44c6cb 100755 --- a/exporters/svn-fast-export.py +++ b/exporters/svn-fast-export.py @@ -35,6 +35,56 @@ def dump_file_blob(root, full_path, pool): sys.stdout.write("\n") +class Matcher(object): + + branch = None + + def __init__(self, trunk_path): + self.trunk_path = trunk_path + + def branchname(self): + return self.branch + + def __str__(self): + return super(Matcher, self).__str__() + ":" + self.trunk_path + + @staticmethod + def getMatcher(trunk_path): + if trunk_path.startswith("regex:"): + return RegexStringMatcher(trunk_path) + else: + return StaticStringMatcher(trunk_path) + +class StaticStringMatcher(Matcher): + + branch = "master" + + def matches(self, path): + return path.startswith(trunk_path) + + def replace(self, path): + return path.replace(self.trunk_path, '') + +class RegexStringMatcher(Matcher): + + def __init__(self, trunk_path): + super(RegexStringMatcher, self).__init__(trunk_path) + import re + self.matcher = re.compile(self.trunk_path[len("regex:"):]) + + def matches(self, path): + match = self.matcher.match(path) + if match: + self.branch = match.group(1) + return True + else: + return False + + def replace(self, path): + return self.matcher.sub("\g<2>", path) + +MATCHER = None + def export_revision(rev, repo, fs, pool): sys.stderr.write("Exporting revision %s... " % rev) @@ -55,15 +105,14 @@ def export_revision(rev, repo, fs, pool): c_t = ct_short[change_type.change_kind] if svn_fs_is_dir(root, path, revpool): continue - - if not path.startswith(trunk_path): + if not MATCHER.matches(path): # We don't handle branches. Or tags. Yet. pass else: if c_t == 'D': - file_changes.append("D %s" % path.replace(trunk_path, '')) + file_changes.append("D %s" % MATCHER.replace(path)) else: - marks[i] = path.replace(trunk_path, '') + marks[i] = MATCHER.replace(path) file_changes.append("M 644 :%s %s" % (i, marks[i])) sys.stdout.write("blob\nmark :%s\n" % i) dump_file_blob(root, path, revpool) @@ -85,7 +134,7 @@ def export_revision(rev, repo, fs, pool): svndate = props['svn:date'][0:-8] commit_time = mktime(strptime(svndate, '%Y-%m-%dT%H:%M:%S')) - sys.stdout.write("commit refs/heads/master\n") + sys.stdout.write("commit refs/heads/%s\n" % MATCHER.branchname()) sys.stdout.write("committer %s %s -0000\n" % (author, int(commit_time))) sys.stdout.write("data %s\n" % len(props['svn:log'])) sys.stdout.write(props['svn:log']) @@ -129,7 +178,7 @@ if __name__ == '__main__': parser.set_usage(usage) parser.add_option('-f', '--final-rev', help='Final revision to import', dest='final_rev', metavar='FINAL_REV', type='int') - parser.add_option('-t', '--trunk-path', help='Path in repo to /trunk', + parser.add_option('-t', '--trunk-path', help="Path in repo to /trunk, may be `regex:/cvs/(trunk)/proj1/(.*)`\nFirst group is used as branchname, second to match files", dest='trunk_path', metavar='TRUNK_PATH') parser.add_option('-b', '--branches-path', help='Path in repo to /branches', dest='branches_path', metavar='BRANCHES_PATH') @@ -146,6 +195,8 @@ if __name__ == '__main__': if options.final_rev != None: final_rev = options.final_rev + MATCHER = Matcher.getMatcher(trunk_path) + sys.stderr.write("%s\n" % MATCHER) if len(args) != 1: parser.print_help() sys.exit(2) |