From: Eric S. Raymond Date: Fri, 7 Nov 2014 13:41:54 +0000 (-0500) Subject: Halfway to fast-export. X-Git-Tag: 0.2~58 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=95d5cf82353c2d2f16de78513db36d617e784ea7;p=src.git Halfway to fast-export. --- diff --git a/src b/src index df15ecb..29dccf4 100755 --- a/src +++ b/src @@ -178,6 +178,12 @@ class RCSLog: if item.revision == revision: return item.revno return None + def by_revno(self, revno): + "Map a revno to a revision item." + for item in self.revlist: + if item.revno == revno: + return item + croak("{0} has no revno {1}".format(self.name, revno)) def revno_to_rcs(self, revno): "Map a revno to an RCS ID" for item in self.revlist: @@ -495,19 +501,64 @@ def tag_method(*args): return set_tags(args) +def fast_export_method(*args): + "Dump revision content to standard output." + (revspec, args) = preamble("cat", args) + if revspec and len(revspec) > 1: + croak("checkout needs an empty or singleton revision spec") + mark = 0 + for arg in args: + master = RCSLog(arg) + revspec = master.resolve(revspec) + if revspec is None: + revspec = 1 + revrange = range(1, len(master)) + with lifted(arg): + markmap = {} + last_commit_mark = 0 + if len(args) == 1: + branch = "master" + else: + # FIXME: Sanitize branch names + branch = arg + "master" + for revno in revrange: + scratchfile = "/tmp/src%dtmp" % os.getpid() + do_or_die("co -q -p -r{1} {0} >{2}".format(arg, master.revno_to_rcs(revno), scratchfile)) + size = os.path.getsize(scratchfile) + mark += 1 + markmap[revno] = mark + sys.stdout.write("blob\nmark :%d\ndata %d\n" % (mark, size)) + sys.stdout.write(open(scratchfile).read() + "\n\n") + sys.stdout.write("commit refs/heads/%s\n" % branch) + item = master.by_revno(revno) + sys.stdout.write("mark :%d\n" % (mark + 1)) + sys.stdout.write("data %s\n%s\n" % (len(item.log), item.log)) + if last_commit_mark: + sys.stdout.write("from :%d\n" % last_commit_mark) + perms = "10064" + sys.stdout.write("M %s :%d '%s'\n\n" % (perms, mark, arg)) + last_commit_mark = mark + mark += 1 + markmap[revno] = mark + for (key, val) in master.symbols.items(): + val = master.rcs_to_revno(val) + if val in revrange: + sys.stdout.write("reset refs/tags/%s\nfrom :%d\n\n" % (key, markmap[val])) + dispatch = { - "help": help_method, - "init": init_method, - "add": add_method, - "commit": commit_method, - "ci": commit_method, - "list": list_method, - "log": log_method, - "checkout": checkout_method, - "co": checkout_method, - "cat": cat_method, - "diff": diff_method, - "tag": tag_method, + "help": help_method, + "init": init_method, + "add": add_method, + "commit": commit_method, + "ci": commit_method, + "list": list_method, + "log": log_method, + "checkout": checkout_method, + "co": checkout_method, + "cat": cat_method, + "diff": diff_method, + "tag": tag_method, + "fast-export": fast_export_method, } if __name__ == "__main__":