Fix issue #1778: Better handling if diff is not available.

r1824410 solves the basic issue, to use the internal diff functions
when available. However if diffoptions is not None, an external
diff command is still called. If diff (or diff.exe) is not found
in PATH, Python2 will raise an OSError and Python3 will raise a
FileNotFoundError (which inherits OSError).

r1912724 adds a docstring to FileDiff.get_pipe() documenting this
behaviour.

This revision add an improved error message. When dropping Python2
support, the code can catch FileNotFoundError and remove the check
for ENOENT.

* subversion/bindings/swig/python/svn/fs.py
  (FileDiff.get_pipe): Catch OSError/ENOENT and improve error msg

* subversion/bindings/swig/python/tests/fs.py
  (test_diff_repos_paths_external): Add note to change code when
   droping Python2 support. No functional change.



git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1912743 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/subversion/bindings/swig/python/svn/fs.py b/subversion/bindings/swig/python/svn/fs.py
index 10b1cc0..8e75bff 100644
--- a/subversion/bindings/swig/python/svn/fs.py
+++ b/subversion/bindings/swig/python/svn/fs.py
@@ -23,6 +23,7 @@
 #    under the License.
 ######################################################################
 
+import errno
 from libsvn.fs import *
 
 ######################################################################
@@ -182,8 +183,17 @@
             + [self.tempfile1, self.tempfile2]
 
       # open the pipe, and return the file object for reading from the child.
-      p = _subprocess.Popen(cmd, stdout=_subprocess.PIPE, bufsize=-1,
-                            close_fds=_sys.platform != "win32")
+      try:
+        p = _subprocess.Popen(cmd, stdout=_subprocess.PIPE, bufsize=-1,
+                              close_fds=_sys.platform != "win32")
+      # When removing Python 2 support: Change to FileNotFoundError and 
+      # remove check for ENOENT (FileNotFoundError "Corresponds to errno
+      # ENOENT" according to documentation)
+      except OSError as err:
+        if err.errno == errno.ENOENT:
+          err.strerror = "External diff command not found in PATH"
+        raise err
+
       return _PopenStdoutWrapper(p)
 
     else:
diff --git a/subversion/bindings/swig/python/tests/fs.py b/subversion/bindings/swig/python/tests/fs.py
index 0b5cbd4..68696be 100644
--- a/subversion/bindings/swig/python/tests/fs.py
+++ b/subversion/bindings/swig/python/tests/fs.py
@@ -308,6 +308,9 @@
     try:
       diffout, differr = Popen(["diff"], stdin=PIPE, stderr=PIPE).communicate()
 
+    # When removing Python 2 support: Change to FileNotFoundError and 
+    # remove check for ENOENT (FileNotFoundError "Corresponds to errno
+    # ENOENT" according to documentation)
     except OSError as err:
       if err.errno == errno.ENOENT:
         self.skipTest("'diff' command not present")