hgext/mq.py
changeset 14572 8ff2957c1d82
parent 14564 65f4512e40e4
child 14573 d590ff1f22b2
equal deleted inserted replaced
14571:17c0cb1045e5 14572:8ff2957c1d82
   300             lines = self.opener.read(self.status_path).splitlines()
   300             lines = self.opener.read(self.status_path).splitlines()
   301             return list(parselines(lines))
   301             return list(parselines(lines))
   302         return []
   302         return []
   303 
   303 
   304     @util.propertycache
   304     @util.propertycache
   305     def full_series(self):
   305     def fullseries(self):
   306         if os.path.exists(self.join(self.series_path)):
   306         if os.path.exists(self.join(self.series_path)):
   307             return self.opener.read(self.series_path).splitlines()
   307             return self.opener.read(self.series_path).splitlines()
   308         return []
   308         return []
   309 
   309 
   310     @util.propertycache
   310     @util.propertycache
   316     def series_guards(self):
   316     def series_guards(self):
   317         self.parse_series()
   317         self.parse_series()
   318         return self.series_guards
   318         return self.series_guards
   319 
   319 
   320     def invalidate(self):
   320     def invalidate(self):
   321         for a in 'applied full_series series series_guards'.split():
   321         for a in 'applied fullseries series series_guards'.split():
   322             if a in self.__dict__:
   322             if a in self.__dict__:
   323                 delattr(self, a)
   323                 delattr(self, a)
   324         self.applied_dirty = 0
   324         self.applied_dirty = 0
   325         self.series_dirty = 0
   325         self.series_dirty = 0
   326         self.guards_dirty = False
   326         self.guards_dirty = False
   362 
   362 
   363     def find_series(self, patch):
   363     def find_series(self, patch):
   364         def matchpatch(l):
   364         def matchpatch(l):
   365             l = l.split('#', 1)[0]
   365             l = l.split('#', 1)[0]
   366             return l.strip() == patch
   366             return l.strip() == patch
   367         for index, l in enumerate(self.full_series):
   367         for index, l in enumerate(self.fullseries):
   368             if matchpatch(l):
   368             if matchpatch(l):
   369                 return index
   369                 return index
   370         return None
   370         return None
   371 
   371 
   372     guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)')
   372     guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)')
   373 
   373 
   374     def parse_series(self):
   374     def parse_series(self):
   375         self.series = []
   375         self.series = []
   376         self.series_guards = []
   376         self.series_guards = []
   377         for l in self.full_series:
   377         for l in self.fullseries:
   378             h = l.find('#')
   378             h = l.find('#')
   379             if h == -1:
   379             if h == -1:
   380                 patch = l
   380                 patch = l
   381                 comment = ''
   381                 comment = ''
   382             elif h == 0:
   382             elif h == 0:
   439             if g[0] not in '-+':
   439             if g[0] not in '-+':
   440                 raise util.Abort(_('guard %r starts with invalid char') % g)
   440                 raise util.Abort(_('guard %r starts with invalid char') % g)
   441             bad = self.check_guard(g[1:])
   441             bad = self.check_guard(g[1:])
   442             if bad:
   442             if bad:
   443                 raise util.Abort(bad)
   443                 raise util.Abort(bad)
   444         drop = self.guard_re.sub('', self.full_series[idx])
   444         drop = self.guard_re.sub('', self.fullseries[idx])
   445         self.full_series[idx] = drop + ''.join([' #' + g for g in guards])
   445         self.fullseries[idx] = drop + ''.join([' #' + g for g in guards])
   446         self.parse_series()
   446         self.parse_series()
   447         self.series_dirty = True
   447         self.series_dirty = True
   448 
   448 
   449     def pushable(self, idx):
   449     def pushable(self, idx):
   450         if isinstance(idx, str):
   450         if isinstance(idx, str):
   496                 fp.write("%s\n" % i)
   496                 fp.write("%s\n" % i)
   497             fp.close()
   497             fp.close()
   498         if self.applied_dirty:
   498         if self.applied_dirty:
   499             write_list(map(str, self.applied), self.status_path)
   499             write_list(map(str, self.applied), self.status_path)
   500         if self.series_dirty:
   500         if self.series_dirty:
   501             write_list(self.full_series, self.series_path)
   501             write_list(self.fullseries, self.series_path)
   502         if self.guards_dirty:
   502         if self.guards_dirty:
   503             write_list(self.active_guards, self.guards_path)
   503             write_list(self.active_guards, self.guards_path)
   504         if self.added:
   504         if self.added:
   505             qrepo = self.qrepo()
   505             qrepo = self.qrepo()
   506             if qrepo:
   506             if qrepo:
   747         unknown = []
   747         unknown = []
   748 
   748 
   749         for (i, p) in sorted([(self.find_series(p), p) for p in patches],
   749         for (i, p) in sorted([(self.find_series(p), p) for p in patches],
   750                              reverse=True):
   750                              reverse=True):
   751             if i is not None:
   751             if i is not None:
   752                 del self.full_series[i]
   752                 del self.fullseries[i]
   753             else:
   753             else:
   754                 unknown.append(p)
   754                 unknown.append(p)
   755 
   755 
   756         if unknown:
   756         if unknown:
   757             if numrevs:
   757             if numrevs:
   943                 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
   943                 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
   944                 n = repo.commit(commitmsg, user, date, match=match, force=True)
   944                 n = repo.commit(commitmsg, user, date, match=match, force=True)
   945                 if n is None:
   945                 if n is None:
   946                     raise util.Abort(_("repo commit failed"))
   946                     raise util.Abort(_("repo commit failed"))
   947                 try:
   947                 try:
   948                     self.full_series[insert:insert] = [patchfn]
   948                     self.fullseries[insert:insert] = [patchfn]
   949                     self.applied.append(statusentry(n, patchfn))
   949                     self.applied.append(statusentry(n, patchfn))
   950                     self.parse_series()
   950                     self.parse_series()
   951                     self.series_dirty = 1
   951                     self.series_dirty = 1
   952                     self.applied_dirty = 1
   952                     self.applied_dirty = 1
   953                     if msg:
   953                     if msg:
  1148                     hg.update(repo, target)
  1148                     hg.update(repo, target)
  1149 
  1149 
  1150             if move:
  1150             if move:
  1151                 if not patch:
  1151                 if not patch:
  1152                     raise util.Abort(_("please specify the patch to move"))
  1152                     raise util.Abort(_("please specify the patch to move"))
  1153                 for i, rpn in enumerate(self.full_series[start:]):
  1153                 for i, rpn in enumerate(self.fullseries[start:]):
  1154                     # strip markers for patch guards
  1154                     # strip markers for patch guards
  1155                     if self.guard_re.split(rpn, 1)[0] == patch:
  1155                     if self.guard_re.split(rpn, 1)[0] == patch:
  1156                         break
  1156                         break
  1157                 index = start + i
  1157                 index = start + i
  1158                 assert index < len(self.full_series)
  1158                 assert index < len(self.fullseries)
  1159                 fullpatch = self.full_series[index]
  1159                 fullpatch = self.fullseries[index]
  1160                 del self.full_series[index]
  1160                 del self.fullseries[index]
  1161                 self.full_series.insert(start, fullpatch)
  1161                 self.fullseries.insert(start, fullpatch)
  1162                 self.parse_series()
  1162                 self.parse_series()
  1163                 self.series_dirty = 1
  1163                 self.series_dirty = 1
  1164 
  1164 
  1165             self.applied_dirty = 1
  1165             self.applied_dirty = 1
  1166             if start > 0:
  1166             if start > 0:
  1636                     series.append(l)
  1636                     series.append(l)
  1637         if datastart is None:
  1637         if datastart is None:
  1638             self.ui.warn(_("No saved patch data found\n"))
  1638             self.ui.warn(_("No saved patch data found\n"))
  1639             return 1
  1639             return 1
  1640         self.ui.warn(_("restoring status: %s\n") % lines[0])
  1640         self.ui.warn(_("restoring status: %s\n") % lines[0])
  1641         self.full_series = series
  1641         self.fullseries = series
  1642         self.applied = applied
  1642         self.applied = applied
  1643         self.parse_series()
  1643         self.parse_series()
  1644         self.series_dirty = 1
  1644         self.series_dirty = 1
  1645         self.applied_dirty = 1
  1645         self.applied_dirty = 1
  1646         heads = repo.changelog.heads()
  1646         heads = repo.changelog.heads()
  1682         if r:
  1682         if r:
  1683             pp = r.dirstate.parents()
  1683             pp = r.dirstate.parents()
  1684             msg += "\nDirstate: %s %s" % (hex(pp[0]), hex(pp[1]))
  1684             msg += "\nDirstate: %s %s" % (hex(pp[0]), hex(pp[1]))
  1685         msg += "\n\nPatch Data:\n"
  1685         msg += "\n\nPatch Data:\n"
  1686         msg += ''.join('%s\n' % x for x in self.applied)
  1686         msg += ''.join('%s\n' % x for x in self.applied)
  1687         msg += ''.join(':%s\n' % x for x in self.full_series)
  1687         msg += ''.join(':%s\n' % x for x in self.fullseries)
  1688         n = repo.commit(msg, force=True)
  1688         n = repo.commit(msg, force=True)
  1689         if not n:
  1689         if not n:
  1690             self.ui.warn(_("repo commit failed\n"))
  1690             self.ui.warn(_("repo commit failed\n"))
  1691             return 1
  1691             return 1
  1692         self.applied.append(statusentry(n, '.hg.patches.save.line'))
  1692         self.applied.append(statusentry(n, '.hg.patches.save.line'))
  1696     def full_series_end(self):
  1696     def full_series_end(self):
  1697         if self.applied:
  1697         if self.applied:
  1698             p = self.applied[-1].name
  1698             p = self.applied[-1].name
  1699             end = self.find_series(p)
  1699             end = self.find_series(p)
  1700             if end is None:
  1700             if end is None:
  1701                 return len(self.full_series)
  1701                 return len(self.fullseries)
  1702             return end + 1
  1702             return end + 1
  1703         return 0
  1703         return 0
  1704 
  1704 
  1705     def series_end(self, all_patches=False):
  1705     def series_end(self, all_patches=False):
  1706         """If all_patches is False, return the index of the next pushable patch
  1706         """If all_patches is False, return the index of the next pushable patch
  1787 
  1787 
  1788                 if not patchname:
  1788                 if not patchname:
  1789                     patchname = normname('%d.diff' % r)
  1789                     patchname = normname('%d.diff' % r)
  1790                 checkseries(patchname)
  1790                 checkseries(patchname)
  1791                 self.checkpatchname(patchname, force)
  1791                 self.checkpatchname(patchname, force)
  1792                 self.full_series.insert(0, patchname)
  1792                 self.fullseries.insert(0, patchname)
  1793 
  1793 
  1794                 patchf = self.opener(patchname, "w")
  1794                 patchf = self.opener(patchname, "w")
  1795                 cmdutil.export(repo, [n], fp=patchf, opts=diffopts)
  1795                 cmdutil.export(repo, [n], fp=patchf, opts=diffopts)
  1796                 patchf.close()
  1796                 patchf.close()
  1797 
  1797 
  1843                 patchf.close()
  1843                 patchf.close()
  1844             if not force:
  1844             if not force:
  1845                 checkseries(patchname)
  1845                 checkseries(patchname)
  1846             if patchname not in self.series:
  1846             if patchname not in self.series:
  1847                 index = self.full_series_end() + i
  1847                 index = self.full_series_end() + i
  1848                 self.full_series[index:index] = [patchname]
  1848                 self.fullseries[index:index] = [patchname]
  1849             self.parse_series()
  1849             self.parse_series()
  1850             self.series_dirty = True
  1850             self.series_dirty = True
  1851             self.ui.warn(_("adding %s to series file\n") % patchname)
  1851             self.ui.warn(_("adding %s to series file\n") % patchname)
  1852             self.added.append(patchname)
  1852             self.added.append(patchname)
  1853             patchname = None
  1853             patchname = None
  2592         absdest = q.join(name)
  2592         absdest = q.join(name)
  2593     q.checkpatchname(name)
  2593     q.checkpatchname(name)
  2594 
  2594 
  2595     ui.note(_('renaming %s to %s\n') % (patch, name))
  2595     ui.note(_('renaming %s to %s\n') % (patch, name))
  2596     i = q.find_series(patch)
  2596     i = q.find_series(patch)
  2597     guards = q.guard_re.findall(q.full_series[i])
  2597     guards = q.guard_re.findall(q.fullseries[i])
  2598     q.full_series[i] = name + ''.join([' #' + g for g in guards])
  2598     q.fullseries[i] = name + ''.join([' #' + g for g in guards])
  2599     q.parse_series()
  2599     q.parse_series()
  2600     q.series_dirty = 1
  2600     q.series_dirty = 1
  2601 
  2601 
  2602     info = q.isapplied(patch)
  2602     info = q.isapplied(patch)
  2603     if info:
  2603     if info: