Skip to content

Commit

Permalink
Merge branch 'plugin_reorder'
Browse files Browse the repository at this point in the history
  • Loading branch information
metatoaster committed Oct 6, 2023
2 parents 034d3cf + 8264ec9 commit abc6ea5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

0.5.0 - 2023-10-06
------------------

- Dulwich is now registered first.
- Have the registration by name show all available implementations.

0.4.0 - 2023-06-16
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/pmr2/wfctrl/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def add(self, workspace, path, **kw):


def _register():
register_cmd(MercurialDvcsCmd, GitDvcsCmd, DulwichDvcsCmd)
register_cmd(MercurialDvcsCmd, DulwichDvcsCmd, GitDvcsCmd)

register = _register
register()
Expand Down
11 changes: 6 additions & 5 deletions src/pmr2/wfctrl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def dummy_action(workspace):

def register_cmd(*cmd_classes):
for cmd_cls in cmd_classes:
if cmd_cls.marker in _cmd_classes:
if not cmd_cls.available():
continue
if cmd_cls.available():
# The classes passed to register_cmd controls the order of which
# the marker gets priority - the first one wins.
if cmd_cls.marker not in _cmd_classes:
_cmd_classes[cmd_cls.marker] = cmd_cls
# XXX we are not handling cases where two markers in different
# classes that uses the same name
_cmd_names[cmd_cls.name] = cmd_cls
# The name gets registered regardless.
_cmd_names[cmd_cls.name] = cmd_cls

def get_cmd_by_name(cmd_name):
return _cmd_names.get(cmd_name)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def _make_remote(self):
def test_get_cmd_by_name(self):
self.assertEqual(get_cmd_by_name('git'), self.cmdcls)

@skipIf(DulwichDvcsCmd.available(), 'git is not available')
def test_auto_init(self): # pragma: no cover
super(GitDvcsCmdTestCase, self).test_auto_init()


@skipIf(not MercurialDvcsCmd.available(), 'mercurial is not available')
class MercurialDvcsCmdTestCase(CoreTestCase, RawCmdTests):
Expand Down Expand Up @@ -339,7 +343,4 @@ def _ls_root(self, workspace=None):
return ''.join(outstream.getvalue()).encode(), b'', 0

def test_get_cmd_by_name(self):
pass

def test_auto_init(self):
pass
self.assertEqual(get_cmd_by_name('dulwich'), self.cmdcls)

0 comments on commit abc6ea5

Please sign in to comment.