mercurial/strutil.py
author Matt Harbison <matt_harbison@yahoo.com>
Thu, 27 Nov 2014 10:16:56 -0500
changeset 23686 164915e8ef7b
parent 10263 25e572394f5c
child 25979 b723f05ec49b
permissions -rw-r--r--
narrowmatcher: propagate the rel() method The full path is propagated to the original match object since this is often used directly for printing a file name to the user. This is cleaner than requiring each caller to join the prefix with the file name prior to calling it, and will lead to not having to pass the prefix around separately. It is also consistent with the bad() and abs() methods in terms of the required input. The uipath() method now inherits this path building property. There is no visible change in path style for rel() because it ultimately calls util.pathto(), which returns an os.sep based path. (The previous os.path.join() was violating the documented usage of util.pathto(), that its third parameter be '/' separated.) The doctest needed to be normalized to '/' separators to avoid test differences on Windows, now that a full path is returned for a short filename. The test changes are to drop globs that are no longer necessary when printing an absolute file in a subrepo, as returned from match.uipath(). Previously when os.path.join() was used to add the prefix, the absolute path to a file in a subrepo was printed with a mix of '/' and '\'. The absolute path for a file not in a subrepo, as returned from match.uipath(), is still purely '/' based.
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