comparison mercurial/commands.py @ 5310:ba3dc7883968

debuginstall: stop looking for patch utility, just test it
author Patrick Mezard <pmezard@gmail.com>
date Sat, 15 Sep 2007 16:07:05 +0200
parents 81575b7b505e
children 599f3a690d8f
comparison
equal deleted inserted replaced
5309:e21644bbf01e 5310:ba3dc7883968
861 ui.write(_(" (templates seem to have been installed incorrectly)\n")) 861 ui.write(_(" (templates seem to have been installed incorrectly)\n"))
862 problems += 1 862 problems += 1
863 863
864 # patch 864 # patch
865 ui.status(_("Checking patch...\n")) 865 ui.status(_("Checking patch...\n"))
866 patcher = ui.config('ui', 'patch') 866 patchproblems = 0
867 patcher = ((patcher and util.find_exe(patcher)) or 867 a = "1\n2\n3\n4\n"
868 util.find_exe('gpatch') or 868 b = "1\n2\n3\ninsert\n4\n"
869 util.find_exe('patch')) 869 fa = writetemp(a)
870 if not patcher: 870 d = mdiff.unidiff(a, None, b, None, os.path.basename(fa))
871 ui.write(_(" Can't find patch or gpatch in PATH\n")) 871 fd = writetemp(d)
872 ui.write(_(" (specify a patch utility in your .hgrc file)\n")) 872
873 problems += 1 873 files = {}
874 try:
875 patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files)
876 except util.Abort, e:
877 ui.write(_(" patch call failed:\n"))
878 ui.write(" " + str(e) + "\n")
879 patchproblems += 1
874 else: 880 else:
875 # actually attempt a patch here 881 if list(files) != [os.path.basename(fa)]:
876 a = "1\n2\n3\n4\n" 882 ui.write(_(" unexpected patch output!\n"))
877 b = "1\n2\n3\ninsert\n4\n" 883 patchproblems += 1
878 fa = writetemp(a) 884 a = file(fa).read()
879 d = mdiff.unidiff(a, None, b, None, os.path.basename(fa)) 885 if a != b:
880 fd = writetemp(d) 886 ui.write(_(" patch test failed!\n"))
881 887 patchproblems += 1
882 files = {} 888
883 try: 889 if patchproblems:
884 patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files) 890 if ui.config('ui', 'patch'):
885 except util.Abort, e: 891 ui.write(_(" (Current patch tool may be incompatible with patch,"
886 ui.write(_(" patch call failed:\n")) 892 " or misconfigured. Please check your .hgrc file)\n"))
887 ui.write(" " + str(e) + "\n")
888 problems += 1
889 else: 893 else:
890 if list(files) != [os.path.basename(fa)]: 894 ui.write(_(" Internal patcher failure, please report this error"
891 ui.write(_(" unexpected patch output!")) 895 " to http://www.selenic.com/mercurial/bts\n"))
892 ui.write(_(" (you may have an incompatible version of patch)\n")) 896 problems += patchproblems
893 problems += 1 897
894 a = file(fa).read() 898 os.unlink(fa)
895 if a != b: 899 os.unlink(fd)
896 ui.write(_(" patch test failed!"))
897 ui.write(_(" (you may have an incompatible version of patch)\n"))
898 problems += 1
899
900 os.unlink(fa)
901 os.unlink(fd)
902 900
903 # merge helper 901 # merge helper
904 ui.status(_("Checking merge helper...\n")) 902 ui.status(_("Checking merge helper...\n"))
905 cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge") 903 cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge")
906 or "hgmerge") 904 or "hgmerge")