Show More
@@ -113,7 +113,6 b' HGHEADERS = [' | |||||
113 | '# Branch ', |
|
113 | '# Branch ', | |
114 | '# Node ID ', |
|
114 | '# Node ID ', | |
115 | '# Parent ', # can occur twice for merges - but that is not relevant for mq |
|
115 | '# Parent ', # can occur twice for merges - but that is not relevant for mq | |
116 | '', # all lines after headers 'has' this prefix - simplifies the algorithm |
|
|||
117 | ] |
|
116 | ] | |
118 |
|
117 | |||
119 | def inserthgheader(lines, header, value): |
|
118 | def inserthgheader(lines, header, value): | |
@@ -127,6 +126,9 b' def inserthgheader(lines, header, value)' | |||||
127 | ['# HG changeset patch', '# Date z', ''] |
|
126 | ['# HG changeset patch', '# Date z', ''] | |
128 | >>> inserthgheader(['# HG changeset patch', '# User y'], '# Date ', 'z') |
|
127 | >>> inserthgheader(['# HG changeset patch', '# User y'], '# Date ', 'z') | |
129 | ['# HG changeset patch', '# User y', '# Date z'] |
|
128 | ['# HG changeset patch', '# User y', '# Date z'] | |
|
129 | >>> inserthgheader(['# HG changeset patch', '# Date x', '# User y'], | |||
|
130 | ... '# User ', 'z') | |||
|
131 | ['# HG changeset patch', '# Date x', '# User z'] | |||
130 | >>> inserthgheader(['# HG changeset patch', '# Date y'], '# Date ', 'z') |
|
132 | >>> inserthgheader(['# HG changeset patch', '# Date y'], '# Date ', 'z') | |
131 | ['# HG changeset patch', '# Date z'] |
|
133 | ['# HG changeset patch', '# Date z'] | |
132 | >>> inserthgheader(['# HG changeset patch', '', '# Date y'], '# Date ', 'z') |
|
134 | >>> inserthgheader(['# HG changeset patch', '', '# Date y'], '# Date ', 'z') | |
@@ -136,18 +138,21 b' def inserthgheader(lines, header, value)' | |||||
136 | """ |
|
138 | """ | |
137 | start = lines.index('# HG changeset patch') + 1 |
|
139 | start = lines.index('# HG changeset patch') + 1 | |
138 | newindex = HGHEADERS.index(header) |
|
140 | newindex = HGHEADERS.index(header) | |
|
141 | bestpos = len(lines) | |||
139 | for i in range(start, len(lines)): |
|
142 | for i in range(start, len(lines)): | |
140 | line = lines[i] |
|
143 | line = lines[i] | |
|
144 | if not line.startswith('# '): | |||
|
145 | bestpos = min(bestpos, i) | |||
|
146 | break | |||
141 | for lineindex, h in enumerate(HGHEADERS): |
|
147 | for lineindex, h in enumerate(HGHEADERS): | |
142 | if line.startswith(h): |
|
148 | if line.startswith(h): | |
143 | if lineindex < newindex: |
|
|||
144 | break # next line |
|
|||
145 | if lineindex == newindex: |
|
149 | if lineindex == newindex: | |
146 | lines[i] = header + value |
|
150 | lines[i] = header + value | |
147 |
|
|
151 | return lines | |
148 |
|
|
152 | if lineindex > newindex: | |
149 |
|
|
153 | bestpos = min(bestpos, i) | |
150 | lines.append(header + value) |
|
154 | break # next line | |
|
155 | lines.insert(bestpos, header + value) | |||
151 | return lines |
|
156 | return lines | |
152 |
|
157 | |||
153 | def insertplainheader(lines, header, value): |
|
158 | def insertplainheader(lines, header, value): |
General Comments 0
You need to be logged in to leave comments.
Login now