File: patches.py

package info (click to toggle)
xxdiff 1%3A4.0.1%2Bhg487%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,724 kB
  • ctags: 2,250
  • sloc: cpp: 18,524; python: 6,134; sh: 1,550; ansic: 1,537; perl: 308; lex: 284; yacc: 279; lisp: 250; tcl: 213; makefile: 86
file content (35 lines) | stat: -rwxr-xr-x 812 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This file is part of the xxdiff package.  See xxdiff for license and details.

"""
Functions to manipulate patches.
"""

__author__ = 'Martin Blais <blais@furius.ca>'


# stdlib imports.
import re


def splitpatch(text):
    """
    Split output in chunks starting with ^Index.  Returns a list of pairs
    (tuples), each with (filename, patch) contents.
    """

    ## splitre = re.compile('^Index: (.*)$', re.M)
    splitre = re.compile('^Index: (.*)$', re.M)
    chunks = []
    curbeg, curfn = None, None
    for mo in splitre.finditer(text):
        if curbeg != None:
            assert curfn
            chunks.append( (curfn, text[curbeg:mo.start()]) )
        curbeg = mo.start()
        curfn = mo.group(1)
    if curbeg != None:
        chunks.append( (curfn, text[curbeg:]) )

    return chunks