hgext/mq.py
changeset 2767 60683ab1ed33
parent 2766 c5ac397f7671
child 2770 5f8259e4d292
equal deleted inserted replaced
2766:c5ac397f7671 2767:60683ab1ed33
    55         self.series_path = "series"
    55         self.series_path = "series"
    56         self.status_path = "status"
    56         self.status_path = "status"
    57 
    57 
    58         if os.path.exists(os.path.join(self.path, self.series_path)):
    58         if os.path.exists(os.path.join(self.path, self.series_path)):
    59             self.full_series = self.opener(self.series_path).read().splitlines()
    59             self.full_series = self.opener(self.series_path).read().splitlines()
    60         self.read_series(self.full_series)
    60         self.parse_series()
    61 
    61 
    62         if os.path.exists(os.path.join(self.path, self.status_path)):
    62         if os.path.exists(os.path.join(self.path, self.status_path)):
    63             self.applied = self.opener(self.status_path).read().splitlines()
    63             self.applied = self.opener(self.status_path).read().splitlines()
    64 
    64 
    65     def find_series(self, patch):
    65     def find_series(self, patch):
    73                 if s == patch:
    73                 if s == patch:
    74                     return index
    74                     return index
    75             index += 1
    75             index += 1
    76         return None
    76         return None
    77 
    77 
    78     def read_series(self, list):
    78     def parse_series(self):
    79         def matcher(list):
       
    80             pre = re.compile("(\s*)([^#]+)")
       
    81             for l in list:
       
    82                 m = pre.match(l)
       
    83                 if m:
       
    84                     s = m.group(2)
       
    85                     s = s.rstrip()
       
    86                     if len(s) > 0:
       
    87                         yield s
       
    88         self.series = []
    79         self.series = []
    89         self.series = [ x for x in matcher(list) ]
    80         for l in self.full_series:
       
    81             s = l.split('#', 1)[0].strip()
       
    82             if s:
       
    83                 self.series.append(s)
    90 
    84 
    91     def save_dirty(self):
    85     def save_dirty(self):
    92         if self.applied_dirty:
    86         if self.applied_dirty:
    93             if len(self.applied) > 0:
    87             if len(self.applied) > 0:
    94                 nl = "\n"
    88                 nl = "\n"
   395                 r.remove([patch], True)
   389                 r.remove([patch], True)
   396             else:
   390             else:
   397                 os.unlink(os.path.join(self.path, patch))
   391                 os.unlink(os.path.join(self.path, patch))
   398         i = self.find_series(patch)
   392         i = self.find_series(patch)
   399         del self.full_series[i]
   393         del self.full_series[i]
   400         self.read_series(self.full_series)
   394         self.parse_series()
   401         self.series_dirty = 1
   395         self.series_dirty = 1
   402 
   396 
   403     def check_toppatch(self, repo):
   397     def check_toppatch(self, repo):
   404         if len(self.applied) > 0:
   398         if len(self.applied) > 0:
   405             (top, patch) = self.applied[-1].split(':')
   399             (top, patch) = self.applied[-1].split(':')
   433                             "New patch: %s" % patch, force=True, wlock=wlock)
   427                             "New patch: %s" % patch, force=True, wlock=wlock)
   434         if n == None:
   428         if n == None:
   435             raise util.Abort(_("repo commit failed"))
   429             raise util.Abort(_("repo commit failed"))
   436         self.full_series[insert:insert] = [patch]
   430         self.full_series[insert:insert] = [patch]
   437         self.applied.append(revlog.hex(n) + ":" + patch)
   431         self.applied.append(revlog.hex(n) + ":" + patch)
   438         self.read_series(self.full_series)
   432         self.parse_series()
   439         self.series_dirty = 1
   433         self.series_dirty = 1
   440         self.applied_dirty = 1
   434         self.applied_dirty = 1
   441         p = self.opener(patch, "w")
   435         p = self.opener(patch, "w")
   442         if msg:
   436         if msg:
   443             msg = msg + "\n"
   437             msg = msg + "\n"
  1010             self.ui.warn("No saved patch data found\n")
  1004             self.ui.warn("No saved patch data found\n")
  1011             return 1
  1005             return 1
  1012         self.ui.warn("restoring status: %s\n" % lines[0])
  1006         self.ui.warn("restoring status: %s\n" % lines[0])
  1013         self.full_series = series
  1007         self.full_series = series
  1014         self.applied = applied
  1008         self.applied = applied
  1015         self.read_series(self.full_series)
  1009         self.parse_series()
  1016         self.series_dirty = 1
  1010         self.series_dirty = 1
  1017         self.applied_dirty = 1
  1011         self.applied_dirty = 1
  1018         heads = repo.changelog.heads()
  1012         heads = repo.changelog.heads()
  1019         if delete:
  1013         if delete:
  1020             if rev not in heads:
  1014             if rev not in heads:
  1157             if patch in self.series:
  1151             if patch in self.series:
  1158                 raise util.Abort(_('patch %s is already in the series file')
  1152                 raise util.Abort(_('patch %s is already in the series file')
  1159                                  % patch)
  1153                                  % patch)
  1160             index = self.full_series_end() + i
  1154             index = self.full_series_end() + i
  1161             self.full_series[index:index] = [patch]
  1155             self.full_series[index:index] = [patch]
  1162             self.read_series(self.full_series)
  1156             self.parse_series()
  1163             self.ui.warn("adding %s to series file\n" % patch)
  1157             self.ui.warn("adding %s to series file\n" % patch)
  1164             i += 1
  1158             i += 1
  1165             added.append(patch)
  1159             added.append(patch)
  1166             patch = None
  1160             patch = None
  1167         self.series_dirty = 1
  1161         self.series_dirty = 1
  1485 
  1479 
  1486     if ui.verbose:
  1480     if ui.verbose:
  1487         ui.write('Renaming %s to %s\n' % (patch, name))
  1481         ui.write('Renaming %s to %s\n' % (patch, name))
  1488     i = q.find_series(patch)
  1482     i = q.find_series(patch)
  1489     q.full_series[i] = name
  1483     q.full_series[i] = name
  1490     q.read_series(q.full_series)
  1484     q.parse_series()
  1491     q.series_dirty = 1
  1485     q.series_dirty = 1
  1492 
  1486 
  1493     info = q.isapplied(patch)
  1487     info = q.isapplied(patch)
  1494     if info:
  1488     if info:
  1495         q.applied[info[0]] = info[1] + ':' + name
  1489         q.applied[info[0]] = info[1] + ':' + name