mercurial/commands.py
changeset 2864 71e78f2ca5ae
parent 2858 345bac2bc4ec
parent 2861 1f813d4fbcc8
child 2865 2893e51407a4
equal deleted inserted replaced
2858:345bac2bc4ec 2864:71e78f2ca5ae
     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(), "os re sys signal shutil imp urllib pdb")
    11 demandload(globals(), "os re sys signal shutil imp urllib pdb")
    12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
    12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
    13 demandload(globals(), "fnmatch mdiff random signal tempfile time")
    13 demandload(globals(), "fnmatch mdiff patch random signal tempfile time")
    14 demandload(globals(), "traceback errno socket version struct atexit sets bz2")
    14 demandload(globals(), "traceback errno socket version struct atexit sets bz2")
    15 demandload(globals(), "archival cStringIO changegroup email.Parser")
    15 demandload(globals(), "archival cStringIO changegroup email.Parser")
    16 demandload(globals(), "hgweb.server sshserver")
    16 demandload(globals(), "hgweb.server sshserver")
    17 
    17 
    18 class UnknownCommand(Exception):
    18 class UnknownCommand(Exception):
  1823                         '(---|\*\*\*)[ \t])', re.MULTILINE)
  1823                         '(---|\*\*\*)[ \t])', re.MULTILINE)
  1824 
  1824 
  1825     wlock = repo.wlock()
  1825     wlock = repo.wlock()
  1826     lock = repo.lock()
  1826     lock = repo.lock()
  1827 
  1827 
  1828     for patch in patches:
  1828     for p in patches:
  1829         pf = os.path.join(d, patch)
  1829         pf = os.path.join(d, p)
  1830 
  1830 
  1831         message = None
  1831         message = None
  1832         user = None
  1832         user = None
  1833         date = None
  1833         date = None
  1834         hgpatch = False
  1834         hgpatch = False
  1835 
  1835 
  1836         p = email.Parser.Parser()
  1836         parser = email.Parser.Parser()
  1837         if pf == '-':
  1837         if pf == '-':
  1838             msg = p.parse(sys.stdin)
  1838             msg = parser.parse(sys.stdin)
  1839             ui.status(_("applying patch from stdin\n"))
  1839             ui.status(_("applying patch from stdin\n"))
  1840         else:
  1840         else:
  1841             msg = p.parse(file(pf))
  1841             msg = parser.parse(file(pf))
  1842             ui.status(_("applying %s\n") % patch)
  1842             ui.status(_("applying %s\n") % p)
  1843 
  1843 
  1844         fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
  1844         fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
  1845         tmpfp = os.fdopen(fd, 'w')
  1845         tmpfp = os.fdopen(fd, 'w')
  1846         try:
  1846         try:
  1847             message = msg['Subject']
  1847             message = msg['Subject']
  1905 
  1905 
  1906             tmpfp.close()
  1906             tmpfp.close()
  1907             if not diffs_seen:
  1907             if not diffs_seen:
  1908                 raise util.Abort(_('no diffs found'))
  1908                 raise util.Abort(_('no diffs found'))
  1909 
  1909 
  1910             files = util.patch(strip, tmpname, ui, cwd=repo.root)
  1910             files = patch.patch(strip, tmpname, ui, cwd=repo.root)
       
  1911             removes = []
  1911             if len(files) > 0:
  1912             if len(files) > 0:
  1912                 cfiles = files
  1913                 cfiles = files.keys()
       
  1914                 copies = []
       
  1915                 copts = {'after': False, 'force': False}
  1913                 cwd = repo.getcwd()
  1916                 cwd = repo.getcwd()
  1914                 if cwd:
  1917                 if cwd:
  1915                     cfiles = [util.pathto(cwd, f) for f in files]
  1918                     cfiles = [util.pathto(cwd, f) for f in files.keys()]
       
  1919                 for f in files:
       
  1920                     ctype, gp = files[f]
       
  1921                     if ctype == 'RENAME':
       
  1922                         copies.append((gp.oldpath, gp.path, gp.copymod))
       
  1923                         removes.append(gp.oldpath)
       
  1924                     elif ctype == 'COPY':
       
  1925                         copies.append((gp.oldpath, gp.path, gp.copymod))
       
  1926                     elif ctype == 'DELETE':
       
  1927                         removes.append(gp.path)
       
  1928                 for src, dst, after in copies:
       
  1929                     absdst = os.path.join(repo.root, dst)
       
  1930                     if not after and os.path.exists(absdst):
       
  1931                         raise util.Abort(_('patch creates existing file %s') % dst)
       
  1932                     if cwd:
       
  1933                         src, dst = [util.pathto(cwd, f) for f in (src, dst)]
       
  1934                     copts['after'] = after
       
  1935                     errs, copied = docopy(ui, repo, (src, dst), copts, wlock=wlock)
       
  1936                     if errs:
       
  1937                         raise util.Abort(errs)
       
  1938                 if removes:
       
  1939                     repo.remove(removes, True, wlock=wlock)
       
  1940                 for f in files:
       
  1941                     ctype, gp = files[f]
       
  1942                     if gp and gp.mode:
       
  1943                         x = gp.mode & 0100 != 0
       
  1944                         dst = os.path.join(repo.root, gp.path)
       
  1945                         util.set_exec(dst, x)
  1916                 addremove_lock(ui, repo, cfiles, {}, wlock=wlock)
  1946                 addremove_lock(ui, repo, cfiles, {}, wlock=wlock)
       
  1947             files = files.keys()
       
  1948             files.extend([r for r in removes if r not in files])
  1917             repo.commit(files, message, user, date, wlock=wlock, lock=lock)
  1949             repo.commit(files, message, user, date, wlock=wlock, lock=lock)
  1918         finally:
  1950         finally:
  1919             os.unlink(tmpname)
  1951             os.unlink(tmpname)
  1920 
  1952 
  1921 def incoming(ui, repo, source="default", **opts):
  1953 def incoming(ui, repo, source="default", **opts):