hgext/mq.py
changeset 4037 bbdba01cce28
parent 4016 a195f11ed1a2
child 4039 55578a8d7e84
equal deleted inserted replaced
4036:ebf1a05f6479 4037:bbdba01cce28
    32 from mercurial.i18n import _
    32 from mercurial.i18n import _
    33 from mercurial import commands, cmdutil, hg, patch, revlog, util, changegroup
    33 from mercurial import commands, cmdutil, hg, patch, revlog, util, changegroup
    34 import os, sys, re, errno
    34 import os, sys, re, errno
    35 
    35 
    36 commands.norepo += " qclone qversion"
    36 commands.norepo += " qclone qversion"
       
    37 
       
    38 # Patch names looks like unix-file names.
       
    39 # They must be joinable with queue directory and result in the patch path.
       
    40 normname = util.normpath
    37 
    41 
    38 class statusentry:
    42 class statusentry:
    39     def __init__(self, rev, name=None):
    43     def __init__(self, rev, name=None):
    40         if not name:
    44         if not name:
    41             fields = rev.split(':', 1)
    45             fields = rev.split(':', 1)
  1333                     raise util.Abort(_('revision %d is not the parent of %d')
  1337                     raise util.Abort(_('revision %d is not the parent of %d')
  1334                                      % (r, lastparent))
  1338                                      % (r, lastparent))
  1335                 lastparent = p1
  1339                 lastparent = p1
  1336 
  1340 
  1337                 if not patchname:
  1341                 if not patchname:
  1338                     patchname = '%d.diff' % r
  1342                     patchname = normname('%d.diff' % r)
  1339                 checkseries(patchname)
  1343                 checkseries(patchname)
  1340                 checkfile(patchname)
  1344                 checkfile(patchname)
  1341                 self.full_series.insert(0, patchname)
  1345                 self.full_series.insert(0, patchname)
  1342 
  1346 
  1343                 patchf = self.opener(patchname, "w")
  1347                 patchf = self.opener(patchname, "w")
  1355         for filename in files:
  1359         for filename in files:
  1356             if existing:
  1360             if existing:
  1357                 if filename == '-':
  1361                 if filename == '-':
  1358                     raise util.Abort(_('-e is incompatible with import from -'))
  1362                     raise util.Abort(_('-e is incompatible with import from -'))
  1359                 if not patchname:
  1363                 if not patchname:
  1360                     patchname = filename
  1364                     patchname = normname(filename)
  1361                 if not os.path.isfile(self.join(patchname)):
  1365                 if not os.path.isfile(self.join(patchname)):
  1362                     raise util.Abort(_("patch %s does not exist") % patchname)
  1366                     raise util.Abort(_("patch %s does not exist") % patchname)
  1363             else:
  1367             else:
  1364                 try:
  1368                 try:
  1365                     if filename == '-':
  1369                     if filename == '-':
  1369                     else:
  1373                     else:
  1370                         text = file(filename).read()
  1374                         text = file(filename).read()
  1371                 except IOError:
  1375                 except IOError:
  1372                     raise util.Abort(_("unable to read %s") % patchname)
  1376                     raise util.Abort(_("unable to read %s") % patchname)
  1373                 if not patchname:
  1377                 if not patchname:
  1374                     patchname = os.path.basename(filename)
  1378                     patchname = normname(os.path.basename(filename))
  1375                 checkfile(patchname)
  1379                 checkfile(patchname)
  1376                 patchf = self.opener(patchname, "w")
  1380                 patchf = self.opener(patchname, "w")
  1377                 patchf.write(text)
  1381                 patchf.write(text)
  1378             checkseries(patchname)
  1382             checkseries(patchname)
  1379             index = self.full_series_end() + i
  1383             index = self.full_series_end() + i
  1802             ui.write(_('No patches applied\n'))
  1806             ui.write(_('No patches applied\n'))
  1803             return
  1807             return
  1804         patch = q.lookup('qtip')
  1808         patch = q.lookup('qtip')
  1805     absdest = q.join(name)
  1809     absdest = q.join(name)
  1806     if os.path.isdir(absdest):
  1810     if os.path.isdir(absdest):
  1807         name = os.path.join(name, os.path.basename(patch))
  1811         name = normname(os.path.join(name, os.path.basename(patch)))
  1808         absdest = q.join(name)
  1812         absdest = q.join(name)
  1809     if os.path.exists(absdest):
  1813     if os.path.exists(absdest):
  1810         raise util.Abort(_('%s already exists') % absdest)
  1814         raise util.Abort(_('%s already exists') % absdest)
  1811 
  1815 
  1812     if name in q.series:
  1816     if name in q.series: