mercurial/strutil.py
author Matt Harbison <matt_harbison@yahoo.com>
Wed, 09 Sep 2015 21:07:38 -0400
changeset 26228 0fd20a71abdb
parent 25979 b723f05ec49b
permissions -rw-r--r--
extdiff: add a --patch argument for diffing changeset deltas One of the things I missed the most when transitioning from versioned MQ to evolve was the loss of being able to check that rebase conflicts were properly resolved by: $ hg ci --mq -m "before" $ hg rebase -s qbase -d tip $ hg bcompare --mq The old csets stay in the tree with evolve, but a straight diff includes all of the other changes that were pulled in, obscuring the code that was rebased. Diffing deltas can be confusing, but unless radical changes were made during the resolve, it is very clear when individual hunks are added, dropped or modified. Unlike the MQ technique, this can only compare a single pair of csets/patches at a time. Like the MQ method, this also highlights changes in the commit comment and other metadata. I originally tried monkey patching from the evolve extension, but that is too complicated given that it depends on the order the two different extensions are loaded. This functionality is also useful when comparing grafts however, so implementing it in the core is more than just convenience. The --change argument doesn't make much sense for this, but it isn't harmful so I didn't bother blocking it. The -I/-X options are ignored because of a limitation of cmdutil.export(). We'll fix that next.
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
25979
b723f05ec49b strutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 10263
diff changeset
     8
from __future__ import absolute_import
b723f05ec49b strutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 10263
diff changeset
     9
2953
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    10
def findall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    11
    if end is None:
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 end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    14
        end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    15
    if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    16
        start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    17
    while start < end:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    18
        c = haystack.find(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    19
        if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    20
            break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    21
        yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    22
        start = c + 1
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    23
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    24
def rfindall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    25
    if end is None:
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 end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    28
        end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    29
    if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    30
        start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    31
    while end >= 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    32
        c = haystack.rfind(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    33
        if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    34
            break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    35
        yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    36
        end = c - 1