# HG changeset patch # User Mads Kiilerich # Date 2014-11-28 01:57:33 # Node ID 94092019e8395f4ee9570a5712981a13545aaf51 # Parent dc4d2cd3aa3e9bb3d968122bc805d123ab9f80dd 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. diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -113,7 +113,6 @@ HGHEADERS = [ '# 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 @@ def inserthgheader(lines, header, value) ['# 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 @@ def inserthgheader(lines, header, value) """ 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):