# HG changeset patch # User Laurent Charignon # Date 1426207897 25200 # Node ID 616c01b69898ca255370716f1494f3aa6710d5a6 # Parent 567ae53657544744155897ada91f16f8af61ad8a record: change interface of the filtering function This way filtering functions accept chunks and return chunks diff -r 567ae5365754 -r 616c01b69898 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Thu Mar 12 23:15:06 2015 -0400 +++ b/mercurial/cmdutil.py Thu Mar 12 17:51:37 2015 -0700 @@ -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 -r 567ae5365754 -r 616c01b69898 mercurial/patch.py --- a/mercurial/patch.py Thu Mar 12 23:15:06 2015 -0400 +++ b/mercurial/patch.py Thu Mar 12 17:51:37 2015 -0700 @@ -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/(.*)') @@ -1352,7 +1353,7 @@ return s return s[:i] -def parsepatch(fp): +def parsepatch(originalchunks): """patch -> [] of headers -> [] of hunks """ class parser(object): """patch parsing state machine""" @@ -1421,6 +1422,9 @@ } p = parser() + fp = cStringIO.StringIO() + fp.write(''.join(originalchunks)) + fp.seek(0) state = 'context' for newstate, data in scanpatch(fp): @@ -1430,6 +1434,7 @@ raise PatchError('unhandled transition: %s -> %s' % (state, newstate)) state = newstate + del fp return p.finished() def pathtransform(path, strip, prefix):