Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 24341:616c01b69898
record: change interface of the filtering function
This way filtering functions accept chunks and return chunks
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Thu, 12 Mar 2015 17:51:37 -0700 |
parents | 6ddc86eedc3b |
children | 31edcea517c1 |
comparison
equal
deleted
inserted
replaced
24340:567ae5365754 | 24341:616c01b69898 |
---|---|
13 import email.Generator | 13 import email.Generator |
14 import email.Parser | 14 import email.Parser |
15 | 15 |
16 from i18n import _ | 16 from i18n import _ |
17 from node import hex, short | 17 from node import hex, short |
18 import cStringIO | |
18 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error | 19 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error |
19 | 20 |
20 gitre = re.compile('diff --git a/(.*) b/(.*)') | 21 gitre = re.compile('diff --git a/(.*) b/(.*)') |
21 tabsplitter = re.compile(r'(\t+|[^\t]+)') | 22 tabsplitter = re.compile(r'(\t+|[^\t]+)') |
22 | 23 |
1350 i = s.find(' ') | 1351 i = s.find(' ') |
1351 if i < 0: | 1352 if i < 0: |
1352 return s | 1353 return s |
1353 return s[:i] | 1354 return s[:i] |
1354 | 1355 |
1355 def parsepatch(fp): | 1356 def parsepatch(originalchunks): |
1356 """patch -> [] of headers -> [] of hunks """ | 1357 """patch -> [] of headers -> [] of hunks """ |
1357 class parser(object): | 1358 class parser(object): |
1358 """patch parsing state machine""" | 1359 """patch parsing state machine""" |
1359 def __init__(self): | 1360 def __init__(self): |
1360 self.fromline = 0 | 1361 self.fromline = 0 |
1419 'hunk': addhunk}, | 1420 'hunk': addhunk}, |
1420 'other': {'other': addother}, | 1421 'other': {'other': addother}, |
1421 } | 1422 } |
1422 | 1423 |
1423 p = parser() | 1424 p = parser() |
1425 fp = cStringIO.StringIO() | |
1426 fp.write(''.join(originalchunks)) | |
1427 fp.seek(0) | |
1424 | 1428 |
1425 state = 'context' | 1429 state = 'context' |
1426 for newstate, data in scanpatch(fp): | 1430 for newstate, data in scanpatch(fp): |
1427 try: | 1431 try: |
1428 p.transitions[state][newstate](p, data) | 1432 p.transitions[state][newstate](p, data) |
1429 except KeyError: | 1433 except KeyError: |
1430 raise PatchError('unhandled transition: %s -> %s' % | 1434 raise PatchError('unhandled transition: %s -> %s' % |
1431 (state, newstate)) | 1435 (state, newstate)) |
1432 state = newstate | 1436 state = newstate |
1437 del fp | |
1433 return p.finished() | 1438 return p.finished() |
1434 | 1439 |
1435 def pathtransform(path, strip, prefix): | 1440 def pathtransform(path, strip, prefix): |
1436 '''turn a path from a patch into a path suitable for the repository | 1441 '''turn a path from a patch into a path suitable for the repository |
1437 | 1442 |