[diffoscope] What is a good implementation to prefer gdiff in diffoscope?

Guangyuan Yang yzgyyang at outlook.com
Sun Aug 6 20:16:50 CEST 2017


I had some failed cases when running diffoscope test suite on FreeBSD. Most of 
the issues are caused by the difference between BSD Diff (`diff` on FreeBSD) 
and GNU Diff (`gdiff` on FreeBSD).

I would like to submit a patch to let diffoscope use `gdiff` when available. I 
will also make `gdiff` a dependency of diffoscope in FreeBSD Ports. My 
implementation is as follow:

+from distutils.spawn import find_executable
 from .tools import tool_required
 from .config import Config
 DIFF_CHUNK = 4096
+DIFF_TOOL = 'diff'
+gdiff_path = find_executable('gdiff')
+if gdiff_path:
+    DIFF_TOOL = 'gdiff'
 logger = logging.getLogger(__name__)
 re_diff_change = re.compile(r'^([+-@]).*', re.MULTILINE)
@@ -159,9 +167,9 @@ class DiffParser(object):
         return self.skip_block
- at tool_required('diff')
+ at tool_required(DIFF_TOOL)
 def run_diff(fifo1, fifo2, end_nl_q1, end_nl_q2):
-    cmd = ['diff', '-aU7', fifo1, fifo2]
+    cmd = [DIFF_TOOL, '-aU7', fifo1, fifo2]
     logger.debug("Running %s", ' '.join(cmd))

This is not really a clean implementation. I would like to ask for input on 
this issue.


More information about the diffoscope mailing list