Browse Source

Add test for reset behaviour fixes, simplify handling of ZERO_SHA a bit.

Jelmer Vernooij 7 years ago
parent
commit
506c44802c
4 changed files with 28 additions and 7 deletions
  1. 1 0
      AUTHORS
  2. 5 0
      NEWS
  3. 5 7
      dulwich/fastexport.py
  4. 17 0
      dulwich/tests/test_fastexport.py

+ 1 - 0
AUTHORS

@@ -127,5 +127,6 @@ max <max0d41@github.com>
 Segev Finer <segev208@gmail.com>
 fviolette <fviolette@talend.com>
 dzhuang <dzhuang.scut@gmail.com>
+Antoine Pietri <antoine.pietri1@gmail.com>
 
 If you contributed but are missing from this list, please send me an e-mail.

+ 5 - 0
NEWS

@@ -20,6 +20,11 @@
   * ``dulwich.porcelain.remove`` now actually removes files from
     disk, not just from the index. (Jelmer Vernooij, #488)
 
+  * Fix handling of "reset" command with markers and without
+    "from". (Antoine Pietri)
+
+  * Fix handling of "merge" command with markers. (Antoine Pietri)
+
  IMPROVEMENTS
 
   * Add basic support for reading ignore files in ``dulwich.ignore``.

+ 5 - 7
dulwich/fastexport.py

@@ -129,7 +129,7 @@ class GitImportProcessor(processor.ImportProcessor):
     def __init__(self, repo, params=None, verbose=False, outf=None):
         processor.ImportProcessor.__init__(self, params, verbose)
         self.repo = repo
-        self.last_commit = None
+        self.last_commit = ZERO_SHA
         self.markers = {}
         self._contents = {}
 
@@ -198,7 +198,7 @@ class GitImportProcessor(processor.ImportProcessor):
             self.repo.object_store,
             ((path, hexsha, mode) for (path, (mode, hexsha)) in
                 self._contents.items()))
-        if self.last_commit is not None:
+        if self.last_commit != ZERO_SHA:
             commit.parents.append(self.last_commit)
         for merge in cmd.merges:
             if merge.startswith(b':'):
@@ -215,19 +215,15 @@ class GitImportProcessor(processor.ImportProcessor):
         pass
 
     def _reset_base(self, commit_id):
-        if commit_id.startswith(b":"):
-            commit_id = self.markers[commit_id[1:]]
         if self.last_commit == commit_id:
             return
         self._contents = {}
+        self.last_commit = commit_id
         if commit_id != ZERO_SHA:
-            self.last_commit = commit_id
             tree_id = self.repo[commit_id].tree
             for (path, mode, hexsha) in (
                     self.repo.object_store.iter_tree_contents(tree_id)):
                 self._contents[path] = (mode, hexsha)
-        else:
-            self.last_commit = None
 
     def reset_handler(self, cmd):
         """Process a ResetCommand."""
@@ -235,6 +231,8 @@ class GitImportProcessor(processor.ImportProcessor):
             from_ = ZERO_SHA
         else:
             from_ = cmd.from_
+            if from_.startswith(b":"):
+                from_ = self.markers[from_[1:]]
         self._reset_base(from_)
         self.repo.refs[cmd.ref] = from_
 

+ 17 - 0
dulwich/tests/test_fastexport.py

@@ -29,6 +29,7 @@ from dulwich.objects import (
     Blob,
     Commit,
     Tree,
+    ZERO_SHA,
     )
 from dulwich.repo import (
     MemoryRepo,
@@ -107,6 +108,22 @@ class GitImportProcessorTests(TestCase):
         cmd = commands.ResetCommand(b"refs/heads/foo", c1.id)
         self.processor.reset_handler(cmd)
         self.assertEqual(c1.id, self.repo.get_refs()[b"refs/heads/foo"])
+        self.assertEqual(c1.id, self.processor.last_commit)
+
+    def test_reset_handler_marker(self):
+        from fastimport import commands
+        [c1, c2] = build_commit_graph(self.repo.object_store, [[1], [2]])
+        self.processor.markers[b'10'] = c1.id
+        cmd = commands.ResetCommand(b"refs/heads/foo", b':10')
+        self.processor.reset_handler(cmd)
+        self.assertEqual(c1.id, self.repo.get_refs()[b"refs/heads/foo"])
+
+    def test_reset_handler_default(self):
+        from fastimport import commands
+        [c1, c2] = build_commit_graph(self.repo.object_store, [[1], [2]])
+        cmd = commands.ResetCommand(b"refs/heads/foo", None)
+        self.processor.reset_handler(cmd)
+        self.assertEqual(ZERO_SHA, self.repo.get_refs()[b"refs/heads/foo"])
 
     def test_commit_handler(self):
         from fastimport import commands