record: turn consumefile() into a pure function
authorPatrick Mezard <pmezard@gmail.com>
Sun, 23 Jan 2011 12:44:05 +0100
changeset 13290 82133e91ce7d
parent 13289 58b26b360a57
child 13291 90e7be23167e
record: turn consumefile() into a pure function
hgext/record.py
--- a/hgext/record.py	Sun Jan 23 12:30:15 2011 +0100
+++ b/hgext/record.py	Sun Jan 23 12:44:05 2011 +0100
@@ -255,10 +255,7 @@
 
 def filterpatch(ui, chunks):
     """Interactively filter patch chunks into applied-only chunks"""
-    chunks = list(chunks)
-    chunks.reverse()
-    seen = set()
-    def consumefile():
+    def consumefile(chunks):
         """fetch next portion from chunks until a 'header' is seen
         NB: header == new-file mark
         """
@@ -266,10 +263,12 @@
         while chunks:
             if isinstance(chunks[-1], header):
                 break
-            else:
-                consumed.append(chunks.pop())
+            consumed.append(chunks.pop())
         return consumed
 
+    chunks = list(chunks)
+    chunks.reverse()
+    seen = set()
     resp_all = [None]   # this two are changed from inside prompt,
     resp_file = [None]  # so can't be usual variables
     applied = {}        # 'filename' -> [] of chunks
@@ -332,7 +331,7 @@
             fixoffset = 0
             hdr = ''.join(chunk.header)
             if hdr in seen:
-                consumefile()
+                consumefile(chunks)
                 continue
             seen.add(hdr)
             if resp_all[0] is None:
@@ -342,9 +341,9 @@
             if r:
                 applied[chunk.filename()] = [chunk]
                 if chunk.allhunks():
-                    applied[chunk.filename()] += consumefile()
+                    applied[chunk.filename()] += consumefile(chunks)
             else:
-                consumefile()
+                consumefile(chunks)
         else:
             # new hunk
             if resp_file[0] is None and resp_all[0] is None: