Patchwork [1,of,6] record: change interface of the filtering function

login
register
mail settings
Submitter Laurent Charignon
Date March 13, 2015, 9:21 p.m.
Message ID <5fbca5c98a71c0e1491d.1426281712@dev919.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8066/
State Accepted
Headers show

Comments

Laurent Charignon - March 13, 2015, 9:21 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1426207897 25200
#      Thu Mar 12 17:51:37 2015 -0700
# Node ID 5fbca5c98a71c0e1491d10a9944518a4704ba71e
# Parent  5afd327fe0dc802ff9cb99f3abf5899eec6eb005
record: change interface of the filtering function

This way filtering functions accepts chunks and return chunks

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -20,8 +20,8 @@ 
 def parsealiases(cmd):
     return cmd.lstrip("^").split("|")
 
-def recordfilter(ui, fp):
-    return patch.filterpatch(ui, patch.parsepatch(fp))
+def recordfilter(ui, originalhunks):
+    return patch.filterpatch(ui, originalhunks)
 
 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
             filterfn, *pats, **opts):
@@ -59,19 +59,15 @@ 
         diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True)
         diffopts.nodates = True
         diffopts.git = True
-        originalchunks = patch.diff(repo, changes=status, opts=diffopts)
-        fp = cStringIO.StringIO()
-        fp.write(''.join(originalchunks))
-        fp.seek(0)
+        originaldiff =  patch.diff(repo, changes=status, opts=diffopts)
+        originalchunks = patch.parsepatch(originaldiff)
 
         # 1. filter patch, so we have intending-to apply subset of it
         try:
-            chunks = filterfn(ui, fp)
+            chunks = filterfn(ui, originalchunks)
         except patch.PatchError, err:
             raise util.Abort(_('error parsing patch: %s') % err)
 
-        del fp
-
         contenders = set()
         for h in chunks:
             try:
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -15,6 +15,7 @@ 
 
 from i18n import _
 from node import hex, short
+import cStringIO
 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
@@ -1343,7 +1344,7 @@ 
             return s
     return s[:i]
 
-def parsepatch(fp):
+def parsepatch(originalchunks):
     """patch -> [] of headers -> [] of hunks """
     class parser(object):
         """patch parsing state machine"""
@@ -1412,6 +1413,9 @@ 
             }
 
     p = parser()
+    fp = cStringIO.StringIO()
+    fp.write(''.join(originalchunks))
+    fp.seek(0)
 
     state = 'context'
     for newstate, data in scanpatch(fp):
@@ -1421,6 +1425,7 @@ 
             raise PatchError('unhandled transition: %s -> %s' %
                                    (state, newstate))
         state = newstate
+    del fp
     return p.finished()
 
 def pathtransform(path, strip, prefix):