comparison mercurial/commands.py @ 4382:caaba589d9c7

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.
author Patrick Mezard <pmezard@gmail.com>
date Sat, 28 Apr 2007 11:53:36 +0200
parents 28054fc34923
children 9770d260a405
comparison
equal deleted inserted replaced
4381:28054fc34923 4382:caaba589d9c7
889 problems += 1 889 problems += 1
890 else: 890 else:
891 # actually attempt a patch here 891 # actually attempt a patch here
892 a = "1\n2\n3\n4\n" 892 a = "1\n2\n3\n4\n"
893 b = "1\n2\n3\ninsert\n4\n" 893 b = "1\n2\n3\ninsert\n4\n"
894 d = mdiff.unidiff(a, None, b, None, "a")
895 fa = writetemp(a) 894 fa = writetemp(a)
895 d = mdiff.unidiff(a, None, b, None, os.path.basename(fa))
896 fd = writetemp(d) 896 fd = writetemp(d)
897 fp = os.popen('%s %s %s' % (patcher, fa, fd)) 897
898 files = [] 898 files = {}
899 output = "" 899 try:
900 for line in fp: 900 patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files)
901 output += line 901 except util.Abort, e:
902 if line.startswith('patching file '): 902 ui.write(_(" patch call failed:\n"))
903 pf = util.parse_patch_output(line.rstrip()) 903 ui.write(" " + str(e) + "\n")
904 files.append(pf)
905 if files != [fa]:
906 ui.write(_(" unexpected patch output!"))
907 ui.write(_(" (you may have an incompatible version of patch)\n"))
908 ui.write(output)
909 problems += 1 904 problems += 1
910 a = file(fa).read() 905 else:
911 if a != b: 906 if list(files) != [os.path.basename(fa)]:
912 ui.write(_(" patch test failed!")) 907 ui.write(_(" unexpected patch output!"))
913 ui.write(_(" (you may have an incompatible version of patch)\n")) 908 ui.write(_(" (you may have an incompatible version of patch)\n"))
914 problems += 1 909 problems += 1
910 a = file(fa).read()
911 if a != b:
912 ui.write(_(" patch test failed!"))
913 ui.write(_(" (you may have an incompatible version of patch)\n"))
914 problems += 1
915
915 os.unlink(fa) 916 os.unlink(fa)
916 os.unlink(fd) 917 os.unlink(fd)
917 918
918 # merge helper 919 # merge helper
919 ui.status(_("Checking merge helper...\n")) 920 ui.status(_("Checking merge helper...\n"))