mercurial/commands.py
changeset 3846 18855084b922
parent 3844 3ba82c3f4bc3
child 3848 8cbf060f637e
equal deleted inserted replaced
3845:8958417abf62 3846:18855084b922
     8 from demandload import demandload
     8 from demandload import demandload
     9 from node import *
     9 from node import *
    10 from i18n import gettext as _
    10 from i18n import gettext as _
    11 demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat")
    11 demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat")
    12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
    12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
    13 demandload(globals(), "difflib patch time help")
    13 demandload(globals(), "difflib patch time help mdiff tempfile")
    14 demandload(globals(), "traceback errno version atexit")
    14 demandload(globals(), "traceback errno version atexit")
    15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
    15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
    16 
    16 
    17 class UnknownCommand(Exception):
    17 class UnknownCommand(Exception):
    18     """Exception raised if command is not in the command table."""
    18     """Exception raised if command is not in the command table."""
   828     ui.write("}\n")
   828     ui.write("}\n")
   829 
   829 
   830 def debuginstall(ui):
   830 def debuginstall(ui):
   831     '''test Mercurial installation'''
   831     '''test Mercurial installation'''
   832 
   832 
       
   833     def writetemp(contents):
       
   834         (fd, name) = tempfile.mkstemp()
       
   835         f = os.fdopen(fd, "wb")
       
   836         f.write(contents)
       
   837         f.close()
       
   838         return name
       
   839 
   833     problems = 0
   840     problems = 0
   834 
   841 
   835     # encoding
   842     # encoding
   836     ui.status(_("Checking encoding (%s)...\n") % util._encoding)
   843     ui.status(_("Checking encoding (%s)...\n") % util._encoding)
   837     try:
   844     try:
   865     patcher = util.find_in_path('gpatch', path,
   872     patcher = util.find_in_path('gpatch', path,
   866                                 util.find_in_path('patch', path, None))
   873                                 util.find_in_path('patch', path, None))
   867     if not patcher:
   874     if not patcher:
   868         ui.write(_(" Can't find patch or gpatch in PATH\n"))
   875         ui.write(_(" Can't find patch or gpatch in PATH\n"))
   869         problems += 1
   876         problems += 1
   870     # should actually attempt a patch here
   877     else:
       
   878         # actually attempt a patch here
       
   879         a = "1\n2\n3\n4\n"
       
   880         b = "1\n2\n3\ninsert\n4\n"
       
   881         d = mdiff.unidiff(a, None, b, None, "a")
       
   882         fa = writetemp(a)
       
   883         fd = writetemp(d)
       
   884         fp = os.popen('%s %s %s' % (patcher, fa, fd))
       
   885         files = []
       
   886         output = ""
       
   887         for line in fp:
       
   888             output += line
       
   889             if line.startswith('patching file '):
       
   890                 pf = util.parse_patch_output(line.rstrip())
       
   891                 files.append(pf)
       
   892         if files != [fa]:
       
   893             ui.write(_(" unexpected patch output!"))
       
   894             ui.write(data)
       
   895             problems += 1
       
   896         a = file(fa).read()
       
   897         if a != b:
       
   898             ui.write(_(" patch test failed!"))
       
   899             problems += 1
       
   900         os.unlink(fa)
       
   901         os.unlink(fd)
   871 
   902 
   872     # merge helper
   903     # merge helper
   873     ui.status(_("Checking merge helper...\n"))
   904     ui.status(_("Checking merge helper...\n"))
   874     cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge")
   905     cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge")
   875            or "hgmerge")
   906            or "hgmerge")
   881             ui.write(_(" No merge helper set and can't find default"
   912             ui.write(_(" No merge helper set and can't find default"
   882                        " hgmerge script in PATH\n"))
   913                        " hgmerge script in PATH\n"))
   883         else:
   914         else:
   884             ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd)
   915             ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd)
   885             problems += 1
   916             problems += 1
   886     # should attempt a non-conflicting merge here
   917     else:
       
   918         # actually attempt a patch here
       
   919         fa = writetemp("1\n2\n3\n4\n")
       
   920         fl = writetemp("1\n2\n3\ninsert\n4\n")
       
   921         fr = writetemp("begin\n1\n2\n3\n4\n")
       
   922         r = os.system('%s %s %s %s' % (cmd, fl, fa, fr))
       
   923         if r:
       
   924             ui.write(_(" got unexpected merge error %d!") % r)
       
   925             problems += 1
       
   926         m = file(fl).read()
       
   927         if m != "begin\n1\n2\n3\ninsert\n4\n":
       
   928             ui.write(_(" got unexpected merge results!") % r)
       
   929             ui.write(m)
       
   930         os.unlink(fa)
       
   931         os.unlink(fl)
       
   932         os.unlink(fr)
   887 
   933 
   888     # editor
   934     # editor
   889     ui.status(_("Checking commit editor...\n"))
   935     ui.status(_("Checking commit editor...\n"))
   890     editor = (os.environ.get("HGEDITOR") or
   936     editor = (os.environ.get("HGEDITOR") or
   891               ui.config("ui", "editor") or
   937               ui.config("ui", "editor") or