mq: simplify save_dirty
authorVadim Gelfer <vadim.gelfer@gmail.com>
Wed, 02 Aug 2006 20:33:57 -0700
changeset 2772 4720e79486d3
parent 2771 519bf0cd28d2
child 2773 871ca5b9d348
mq: simplify save_dirty
hgext/mq.py
--- a/hgext/mq.py	Wed Aug 02 15:07:37 2006 -0700
+++ b/hgext/mq.py	Wed Aug 02 20:33:57 2006 -0700
@@ -83,20 +83,13 @@
                 self.series.append(s)
 
     def save_dirty(self):
-        if self.applied_dirty:
-            if len(self.applied) > 0:
-                nl = "\n"
-            else:
-                nl = ""
-            f = self.opener(self.status_path, "w")
-            f.write("\n".join(self.applied) + nl)
-        if self.series_dirty:
-            if len(self.full_series) > 0:
-                nl = "\n"
-            else:
-                nl = ""
-            f = self.opener(self.series_path, "w")
-            f.write("\n".join(self.full_series) + nl)
+        def write_list(items, path):
+            fp = self.opener(path, 'w')
+            for i in items:
+                print >> fp, i
+            fp.close()
+        if self.applied_dirty: write_list(self.applied, self.status_path)
+        if self.series_dirty: write_list(self.full_series, self.series_path)
 
     def readheaders(self, patch):
         def eatdiff(lines):