view mercurial/strutil.py @ 15322:c8e2a5ea7062 stable

mq: avoid data loss upon qfold + qmv (issue3058) When renaming a patch A as B where B was previously qfolded into A and therefore marked as removed, a versioned MQ would first restore B before marking it as a copy of A, thus losing A changes. The undelete() call is probably a left-over, wctx.copy() explicitely handles the case where the destination is removed. Also note that status command represents "hg rm b; hg mv a b" as: A b a R a which explains the first hunk in test-mq-qrename.t.
author Patrick Mezard <pmezard@gmail.com>
date Thu, 20 Oct 2011 16:43:31 +0200
parents 25e572394f5c
children b723f05ec49b
line wrap: on
line source

# strutil.py - string utilities for Mercurial
#
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

def findall(haystack, needle, start=0, end=None):
    if end is None:
        end = len(haystack)
    if end < 0:
        end += len(haystack)
    if start < 0:
        start += len(haystack)
    while start < end:
        c = haystack.find(needle, start, end)
        if c == -1:
            break
        yield c
        start = c + 1

def rfindall(haystack, needle, start=0, end=None):
    if end is None:
        end = len(haystack)
    if end < 0:
        end += len(haystack)
    if start < 0:
        start += len(haystack)
    while end >= 0:
        c = haystack.rfind(needle, start, end)
        if c == -1:
            break
        yield c
        end = c - 1