changeset 2767:60683ab1ed33

mq: rename read_series as parse_series, make simpler and faster
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Wed, 02 Aug 2006 10:48:34 -0700
parents c5ac397f7671
children b1b1aa6f275c
files hgext/mq.py
diffstat 1 files changed, 11 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Wed Aug 02 09:18:56 2006 -0700
+++ b/hgext/mq.py	Wed Aug 02 10:48:34 2006 -0700
@@ -57,7 +57,7 @@
 
         if os.path.exists(os.path.join(self.path, self.series_path)):
             self.full_series = self.opener(self.series_path).read().splitlines()
-        self.read_series(self.full_series)
+        self.parse_series()
 
         if os.path.exists(os.path.join(self.path, self.status_path)):
             self.applied = self.opener(self.status_path).read().splitlines()
@@ -75,18 +75,12 @@
             index += 1
         return None
 
-    def read_series(self, list):
-        def matcher(list):
-            pre = re.compile("(\s*)([^#]+)")
-            for l in list:
-                m = pre.match(l)
-                if m:
-                    s = m.group(2)
-                    s = s.rstrip()
-                    if len(s) > 0:
-                        yield s
+    def parse_series(self):
         self.series = []
-        self.series = [ x for x in matcher(list) ]
+        for l in self.full_series:
+            s = l.split('#', 1)[0].strip()
+            if s:
+                self.series.append(s)
 
     def save_dirty(self):
         if self.applied_dirty:
@@ -397,7 +391,7 @@
                 os.unlink(os.path.join(self.path, patch))
         i = self.find_series(patch)
         del self.full_series[i]
-        self.read_series(self.full_series)
+        self.parse_series()
         self.series_dirty = 1
 
     def check_toppatch(self, repo):
@@ -435,7 +429,7 @@
             raise util.Abort(_("repo commit failed"))
         self.full_series[insert:insert] = [patch]
         self.applied.append(revlog.hex(n) + ":" + patch)
-        self.read_series(self.full_series)
+        self.parse_series()
         self.series_dirty = 1
         self.applied_dirty = 1
         p = self.opener(patch, "w")
@@ -1012,7 +1006,7 @@
         self.ui.warn("restoring status: %s\n" % lines[0])
         self.full_series = series
         self.applied = applied
-        self.read_series(self.full_series)
+        self.parse_series()
         self.series_dirty = 1
         self.applied_dirty = 1
         heads = repo.changelog.heads()
@@ -1159,7 +1153,7 @@
                                  % patch)
             index = self.full_series_end() + i
             self.full_series[index:index] = [patch]
-            self.read_series(self.full_series)
+            self.parse_series()
             self.ui.warn("adding %s to series file\n" % patch)
             i += 1
             added.append(patch)
@@ -1487,7 +1481,7 @@
         ui.write('Renaming %s to %s\n' % (patch, name))
     i = q.find_series(patch)
     q.full_series[i] = name
-    q.read_series(q.full_series)
+    q.parse_series()
     q.series_dirty = 1
 
     info = q.isapplied(patch)