0
 ê    ‹      ½”QoÓ0…ß÷+.~à­¹MÖ"Ø£ÑT¢¢k«.BÈ�ÝÚ"‰#Û]7~=nÓjµà)vòùÞsŽcÓgÙt�šám~;†Ùû7ãÑ HñÃå 1Ë³öC/êÆˆÃ	¢¼o®7›M´¹ŒŒ]a>Gå«²‡Î[]øHxAØÝ¾c@•ä"<�zíKÉFµ�`–€fí�29P˜Ê¡“µXêRFBV&R.*ŒiBa
×q®<Ð=\;‹º.ÊuXÚ¨“n’t_&¯P>x´¼å(¶MƒÜë #·òâÿ-%tÜÅÀ;EÛ¡eÔ+¸ç¥^Õ)ñ¦!ŒêjÎ)A]˜Úá¢äõ·h¥—xéSòy4˜~	zµ]Í(eå2%¯éäzšf„Mx%)òÓÌm`nsç¡2B/µgá»¾ÓßÏÌZ&“®°ºñÚÔO(‹ÇVSº†¯ýà@ÙcªEÄïÒàÅOaÌnæÃIž�æm$b[âIÝ¿ÝXÂfÜÊÚC¦­,¼±�{ã­ŠçõÂ5×‡)ìmY½Rž0€œ$ÿ"Dg‘ÌO¦„mÂHv<;Öû‹ÀàôE'Ž;IâþU¯pÎIœ¼;ïä÷÷§‚âîxRlo�GpÐ     A   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þBGYY¹BáYI#MùÅƒtO3Ä_ŠI|¥�+Wé3ž¯ÄÃ s    # grep.py - logic for history walk and grep
#
# Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.


import difflib

from .i18n import _

from . import (
    error,
    match as matchmod,
    pycompat,
    scmutil,
    util,
)


def matchlines(body, regexp):
    begin = 0
    linenum = 0
    while begin < len(body):
        match = regexp.search(body, begin)
        if not match:
            break
        mstart, mend = match.span()
        linenum += body.count(b'\n', begin, mstart) + 1
        lstart = body.rfind(b'\n', begin, mstart) + 1 or begin
        begin = body.find(b'\n', mend) + 1 or len(body) + 1
        lend = begin - 1
        yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]


class linestate:
    def __init__(self, line, linenum, colstart, colend):
        self.line = line
        self.linenum = linenum
        self.colstart = colstart
        self.colend = colend

    def __hash__(self):
        return hash(self.line)

    def __eq__(self, other):
        return self.line == other.line

    def findpos(self, regexp):
        """Iterate all (start, end) indices of matches"""
        yield self.colstart, self.colend
        p = self.colend
        while p < len(self.line):
            m = regexp.search(self.line, p)
            if not m:
                break
            if m.end() == p:
                p += 1
            else:
                yield m.span()
                p = m.end()


def difflinestates(a, b):
    sm = difflib.SequenceMatcher(None, a, b)
    for tag, alo, ahi, blo, bhi in sm.get_opcodes():
        if tag == 'insert':
            for i in range(blo, bhi):
                yield (b'+', b[i])
        elif tag == 'delete':
            for i in range(alo, ahi):
                yield (b'-', a[i])
        elif tag == 'replace':
            for i in range(alo, ahi):
                yield (b'-', a[i])
            for i in range(blo, bhi):
                yield (b'+', b[i])


class grepsearcher:
    """Search files and revisions for lines matching the given pattern

    Options:
    - all_files to search unchanged files at that revision.
    - diff to search files in the parent revision so diffs can be generated.
    - follow to skip files across copies and renames.
    """

    def __init__(
        self, ui, repo, regexp, all_files=False, diff=False, follow=False
    ):
        self._ui = ui
        self._repo = repo
        self._regexp = regexp
        self._all_files = all_files
        self._diff = diff
        self._follow = follow

        self._getfile = util.lrucachefunc(repo.file)
        self._getrenamed = scmutil.getrenamedfn(repo)

        self._matches = {}
        self._copies = {}
        self._skip = set()
        self._revfiles = {}

    def skipfile(self, fn, rev):
        """Exclude the given file (and the copy at the specified revision)
        from future search"""
        copy = self._copies.get(rev, {}).get(fn)
        self._skip.add(fn)
        if copy:
            self._skip.add(copy)

    def searchfiles(self, revs, makefilematcher):
        """Walk files and revisions to yield (fn, ctx, pstates, states)
        matches

        states is a list of linestate objects. pstates may be empty unless
        diff is True.
        """
        for ctx in scmutil.walkchangerevs(
            self._repo, revs, makefilematcher, self._prep
        ):
     