|
@@ -0,0 +1,57 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+"""Fast export/import functionality."""
|
|
|
+
|
|
|
+from dulwich.objects import format_timezone
|
|
|
+
|
|
|
+import stat
|
|
|
+
|
|
|
+class FastExporter(object):
|
|
|
+
|
|
|
+ def __init__(self, outf, store):
|
|
|
+ self.outf = outf
|
|
|
+ self.store = store
|
|
|
+ self.markers = {}
|
|
|
+
|
|
|
+ def export_blob(self, blob, i):
|
|
|
+ self.outf.write("blob\nmark :%s\n" % i)
|
|
|
+ self.outf.write("data %s\n" % blob.raw_length())
|
|
|
+ self.outf.write(blob.as_raw_string())
|
|
|
+ self.outf.write("\n")
|
|
|
+
|
|
|
+ def export_commit(self, commit, branchname):
|
|
|
+ file_changes = []
|
|
|
+ for path, mode, hexsha in tree_changes(commit.tree):
|
|
|
+ if stat.S_ISDIR(mode):
|
|
|
+ file_changes.extend(self.dump_file_tree(self.store[hexsha]))
|
|
|
+ else:
|
|
|
+ self.dump_file_blob(self.store[hexsha], i)
|
|
|
+ file_changes.append("M %o :%s %s" % (mode, i, path))
|
|
|
+ return file_changes
|
|
|
+ self.write("commit refs/heads/%s\n" % branchname)
|
|
|
+ self.write("committer %s %s %s\n" % (commit.committer, commit.commit_time, format_timezone(commit.commit_timezone)))
|
|
|
+ self.write("author %s %s %s\n" % (commit.author, commit.author_time, format_timezone(commit.author_timezone)))
|
|
|
+ self.write("data %s\n" % len(commit.message))
|
|
|
+ self.write(commit.message)
|
|
|
+ self.write("\n")
|
|
|
+ file_changes = self.export_tree(self.store[commit.tree])
|
|
|
+ self.write('\n'.join(file_changes))
|
|
|
+ self.write("\n\n")
|