mercurial/strutil.py
author Martin von Zweigbergk <martinvonz@google.com>
Mon, 23 Mar 2015 23:04:51 -0700
changeset 24438 5b85a5bc5bbb
parent 10263 25e572394f5c
child 25979 b723f05ec49b
permissions -rw-r--r--
revert: evaluate filesets against working directory (issue4497) As the failing revert tests in test-fileset-generated.t show, Revert currently creates one matcher for matching files in the working copy and another matcher for matching files in the target revision. The two matchers are created with different contexts, which means filesets are evaluated differently. Then the union of the sets of files matching the matchers in the two contexts are reverted. It doesn't seem to make sense to use two different matchers; only the context they're applied to should be different. It seems very likely that the user wants the filesets to be evaluated against the working directory, which the tests test-fileset-generated.t also assume, so let's make it so. I willingly admit that the largefiles code was modified by trial and error (according to tests).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2953
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     1
# strutil.py - string utilities for Mercurial
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
#
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     3
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8155
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8225
diff changeset
     6
# GNU General Public License version 2 or any later version.
2953
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     7
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     8
def findall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     9
    if end is None:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    10
        end = len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    11
    if end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    12
        end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    13
    if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    14
        start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    15
    while start < end:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    16
        c = haystack.find(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    17
        if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    18
            break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    19
        yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    20
        start = c + 1
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    21
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    22
def rfindall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    23
    if end is None:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    24
        end = len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    25
    if end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    26
        end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    27
    if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    28
        start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    29
    while end >= 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    30
        c = haystack.rfind(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    31
        if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    32
            break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    33
        yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    34
        end = c - 1