Mercurial > hg-stable
changeset 23412:94092019e839 stable
mq: fix update of headers that occur in the "wrong" order
Mq tried to insert headers in the right order. Sometimes it would stop
searching before checking all headers and it could thus duplicate a header
instead of replacing it.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 28 Nov 2014 02:57:33 +0100 |
parents | dc4d2cd3aa3e |
children | 0c432696dae3 |
files | hgext/mq.py |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/mq.py Fri Nov 28 10:59:02 2014 -0800 +++ b/hgext/mq.py Fri Nov 28 02:57:33 2014 +0100 @@ -113,7 +113,6 @@ '# Branch ', '# Node ID ', '# Parent ', # can occur twice for merges - but that is not relevant for mq - '', # all lines after headers 'has' this prefix - simplifies the algorithm ] def inserthgheader(lines, header, value): @@ -127,6 +126,9 @@ ['# HG changeset patch', '# Date z', ''] >>> inserthgheader(['# HG changeset patch', '# User y'], '# Date ', 'z') ['# HG changeset patch', '# User y', '# Date z'] + >>> inserthgheader(['# HG changeset patch', '# Date x', '# User y'], + ... '# User ', 'z') + ['# HG changeset patch', '# Date x', '# User z'] >>> inserthgheader(['# HG changeset patch', '# Date y'], '# Date ', 'z') ['# HG changeset patch', '# Date z'] >>> inserthgheader(['# HG changeset patch', '', '# Date y'], '# Date ', 'z') @@ -136,18 +138,21 @@ """ start = lines.index('# HG changeset patch') + 1 newindex = HGHEADERS.index(header) + bestpos = len(lines) for i in range(start, len(lines)): line = lines[i] + if not line.startswith('# '): + bestpos = min(bestpos, i) + break for lineindex, h in enumerate(HGHEADERS): if line.startswith(h): - if lineindex < newindex: - break # next line if lineindex == newindex: lines[i] = header + value - else: - lines.insert(i, header + value) - return lines - lines.append(header + value) + return lines + if lineindex > newindex: + bestpos = min(bestpos, i) + break # next line + lines.insert(bestpos, header + value) return lines def insertplainheader(lines, header, value):