Skip to content

Commit

Permalink
Add test for reset behaviour fixes, simplify handling of ZERO_SHA a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Jul 19, 2017
1 parent f66e753 commit 506c448
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
12 changes: 5 additions & 7 deletions dulwich/fastexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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':'):
Expand All @@ -215,26 +215,24 @@ 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."""
if cmd.from_ is None:
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_

Expand Down
17 changes: 17 additions & 0 deletions dulwich/tests/test_fastexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Blob,
Commit,
Tree,
ZERO_SHA,
)
from dulwich.repo import (
MemoryRepo,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 506c448

Please sign in to comment.