[PATCH] Use patch.patch() when checking for patch availability

Patrick Mezard pmezard at gmail.com
Sat Apr 28 09:55:28 UTC 2007


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1177754016 -7200
# Node ID 3e662ccd6d37b68098dac485318f948d328c9449
# Parent  b5c24ded6e50af68e0800abbe6c09d3b06e91868
Use patch.patch() when checking for patch availability.

The test is closer to what we want to know. It also makes sense when you deal with patched versions of patch() as most people do under win32.

diff -r b5c24ded6e50 -r 3e662ccd6d37 mercurial/commands.py
--- a/mercurial/commands.py	Sat Apr 28 11:43:31 2007 +0200
+++ b/mercurial/commands.py	Sat Apr 28 11:53:36 2007 +0200
@@ -891,27 +891,28 @@ def debuginstall(ui):
         # actually attempt a patch here
         a = "1\n2\n3\n4\n"
         b = "1\n2\n3\ninsert\n4\n"
-        d = mdiff.unidiff(a, None, b, None, "a")
         fa = writetemp(a)
+        d = mdiff.unidiff(a, None, b, None, os.path.basename(fa))
         fd = writetemp(d)
-        fp = os.popen('%s %s %s' % (patcher, fa, fd))
-        files = []
-        output = ""
-        for line in fp:
-            output += line
-            if line.startswith('patching file '):
-                pf = util.parse_patch_output(line.rstrip())
-                files.append(pf)
-        if files != [fa]:
-            ui.write(_(" unexpected patch output!"))
-            ui.write(_(" (you may have an incompatible version of patch)\n"))
-            ui.write(output)
+        
+        files = {}
+        try:
+            patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files)
+        except util.Abort, e:
+            ui.write(_(" patch call failed:\n"))
+            ui.write(" " + str(e) + "\n")
             problems += 1
-        a = file(fa).read()
-        if a != b:
-            ui.write(_(" patch test failed!"))
-            ui.write(_(" (you may have an incompatible version of patch)\n"))
-            problems += 1
+        else:            
+            if list(files) != [os.path.basename(fa)]:
+                ui.write(_(" unexpected patch output!"))
+                ui.write(_(" (you may have an incompatible version of patch)\n"))
+                problems += 1
+            a = file(fa).read()
+            if a != b:
+                ui.write(_(" patch test failed!"))
+                ui.write(_(" (you may have an incompatible version of patch)\n"))
+                problems += 1
+                
         os.unlink(fa)
         os.unlink(fd)
 



More information about the Mercurial-devel mailing list