From 506c44802c966798568eec128f8c893605046870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 19 Jul 2017 21:10:54 +0000 Subject: [PATCH] Add test for reset behaviour fixes, simplify handling of ZERO_SHA a bit. --- AUTHORS | 1 + NEWS | 5 +++++ dulwich/fastexport.py | 12 +++++------- dulwich/tests/test_fastexport.py | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index f7195b7dd..252f8048b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -127,5 +127,6 @@ max Segev Finer fviolette dzhuang +Antoine Pietri If you contributed but are missing from this list, please send me an e-mail. diff --git a/NEWS b/NEWS index 8974867b1..0dd6bbd75 100644 --- a/NEWS +++ b/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``. diff --git a/dulwich/fastexport.py b/dulwich/fastexport.py index 862c2abb4..28178c822 100644 --- a/dulwich/fastexport.py +++ b/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 @@ def commit_handler(self, cmd): 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 @@ def progress_handler(self, cmd): 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 @@ def reset_handler(self, cmd): 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_ diff --git a/dulwich/tests/test_fastexport.py b/dulwich/tests/test_fastexport.py index a5b899188..09fbb9864 100644 --- a/dulwich/tests/test_fastexport.py +++ b/dulwich/tests/test_fastexport.py @@ -29,6 +29,7 @@ Blob, Commit, Tree, + ZERO_SHA, ) from dulwich.repo import ( MemoryRepo, @@ -107,6 +108,22 @@ def test_reset_handler(self): 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