Rev 5429: _KNOWN_MERGE_TOOLS should be a dict (there is an hidden assumption that the merg tool is unique anyway). in file:///home/vila/src/bzr/reviews/mergetools/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Dec 6 14:15:16 GMT 2010


At file:///home/vila/src/bzr/reviews/mergetools/

------------------------------------------------------------
revno: 5429
revision-id: v.ladeuil+lp at free.fr-20101206141515-s6oa96cj01ley5s3
parent: v.ladeuil+lp at free.fr-20101206140144-yz3cp2paek953gp4
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: mergetools
timestamp: Mon 2010-12-06 15:15:15 +0100
message:
  _KNOWN_MERGE_TOOLS should be a dict (there is an hidden assumption that the merg tool is unique anyway).
-------------- next part --------------
=== modified file 'bzrlib/mergetools.py'
--- a/bzrlib/mergetools.py	2010-12-06 14:01:44 +0000
+++ b/bzrlib/mergetools.py	2010-12-06 14:15:15 +0000
@@ -35,9 +35,6 @@
 )
 """)
 
-from bzrlib.commands import Command
-from bzrlib.option import Option
-
 
 def subprocess_invoker(executable, args, cleanup):
     retcode = subprocess.call([executable] + args)
@@ -97,17 +94,20 @@
         return subst_args, tmp_file
 
 
-_KNOWN_MERGE_TOOLS = (
-    u'bcompare {this} {other} {base} {result}',
-    u'kdiff3 {base} {this} {other} -o {result}',
-    u'xxdiff -m -O -M {result} {this} {base} {other}',
-    u'meld {base} {this_temp} {other}',
-    u'opendiff {this} {other} -ancestor {base} -merge {result}',
-    u'winmergeu {result}',
-)
+_KNOWN_MERGE_TOOLS = {
+    'bcompare': 'bcompare {this} {other} {base} {result}',
+    'kdiff3': 'kdiff3 {base} {this} {other} -o {result}',
+    'xdiff': 'xxdiff -m -O -M {result} {this} {base} {other}',
+    'meld': 'meld {base} {this_temp} {other}',
+    'opendiff': 'opendiff {this} {other} -ancestor {base} -merge {result}',
+    'winmergeu': 'winmergeu {result}',
+}
 
 
 def detect_merge_tools():
-    tools = [MergeTool(None, commandline) for commandline in _KNOWN_MERGE_TOOLS]
-    return [tool for tool in tools if tool.is_available()]
-
+    available_merge_tools = []
+    for name, cmd_line in _KNOWN_MERGE_TOOLS.iteritems():
+        merge_tool = MergeTool(name, cmd_line)
+        if merge_tool.is_available():
+            available_merge_tools.append(merge_tool)
+    return available_merge_tools

=== modified file 'bzrlib/tests/test_mergetools.py'
--- a/bzrlib/tests/test_mergetools.py	2010-12-06 13:50:15 +0000
+++ b/bzrlib/tests/test_mergetools.py	2010-12-06 14:15:15 +0000
@@ -127,7 +127,8 @@
     def test_detect(self):
         # only way to reliably test detection is to add a known existing
         # executable to the list used for detection
-        self.overrideAttr(mergetools, '_KNOWN_MERGE_TOOLS', ['sh', 'cmd'])
+        self.overrideAttr(mergetools, '_KNOWN_MERGE_TOOLS',
+                          {'sh': 'sh', 'cmd': 'cmd'})
         tools = mergetools.detect_merge_tools()
         tools_commandlines = [mt.command_line for mt in tools]
         self.assertTrue('sh' in tools_commandlines or



More information about the bazaar-commits mailing list