浏览代码

Keep tracker of markers in GitImportProcessor.

Jelmer Vernooij 14 年之前
父节点
当前提交
55ffa73baf
共有 2 个文件被更改,包括 29 次插入3 次删除
  1. 11 3
      dulwich/fastexport.py
  2. 18 0
      dulwich/tests/test_fastexport.py

+ 11 - 3
dulwich/fastexport.py

@@ -110,19 +110,25 @@ class GitImportProcessor(processor.ImportProcessor):
     """An import processor that imports into a Git repository using Dulwich.
 
     """
+    # FIXME: Batch creation of objects?
 
     def __init__(self, repo, params=None, verbose=False, outf=None):
         processor.ImportProcessor.__init__(self, params, verbose)
         self.repo = repo
         self.last_commit = None
+        self.markers = {}
 
     def import_stream(self, stream):
         p = parser.ImportParser(stream)
         self.process(p.iter_commands)
+        return self.markers
 
     def blob_handler(self, cmd):
         """Process a BlobCommand."""
-        self.repo.object_store.add_object(Blob.from_string(cmd.data))
+        blob = Blob.from_string(cmd.data)
+        self.repo.object_store.add_object(blob)
+        if cmd.mark:
+            self.markers[cmd.mark] = blob.id
 
     def checkpoint_handler(self, cmd):
         """Process a CheckpointCommand."""
@@ -139,10 +145,10 @@ class GitImportProcessor(processor.ImportProcessor):
         (committer_name, committer_email, commit_timestamp, commit_timezone) = cmd.committer
         commit.author = "%s <%s>" % (author_name, author_email)
         commit.author_timezone = author_timezone
-        commit.author_time = author_timestamp
+        commit.author_time = int(author_timestamp)
         commit.committer = "%s <%s>" % (committer_name, committer_email)
         commit.commit_timezone = commit_timezone
-        commit.commit_time = commit_timestamp
+        commit.commit_time = int(commit_timestamp)
         commit.message = cmd.message
         commit.parents = []
         contents = {}
@@ -155,6 +161,8 @@ class GitImportProcessor(processor.ImportProcessor):
         self.repo.object_store.add_object(commit)
         self.repo[cmd.ref] = commit.id
         self.last_commit = commit.id
+        if cmd.mark:
+            self.markers[cmd.mark] = commit.id
 
     def progress_handler(self, cmd):
         """Process a ProgressCommand."""

+ 18 - 0
dulwich/tests/test_fastexport.py

@@ -113,3 +113,21 @@ class GitImportProcessorTests(TestCase):
         self.assertEquals(3600, commit.commit_timezone)
         self.assertEquals(3600, commit.author_timezone)
         self.assertEquals(commit, self.repo["refs/heads/foo"])
+
+    def test_import_stream(self):
+        markers = self.processor.import_stream(StringIO("""blob
+mark :1
+data 11
+text for a
+
+commit refs/heads/master
+mark :2
+committer Joe Foo <joe@foo.com> 1288287382 +0000
+data 20
+<The commit message>
+M 100644 :1 a
+
+"""))
+        self.assertEquals(2, len(markers))
+        self.assertIsInstance(self.repo[markers["1"]], Blob)
+        self.assertIsInstance(self.repo[markers["2"]], Commit)