Mercurial > public > mercurial-scm > hg
comparison mercurial/tagmerge.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | 89a2afe31e82 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
84 ) | 84 ) |
85 | 85 |
86 hexnullid = hex(nullid) | 86 hexnullid = hex(nullid) |
87 | 87 |
88 | 88 |
89 def readtagsformerge(ui, repo, lines, fn='', keeplinenums=False): | 89 def readtagsformerge(ui, repo, lines, fn=b'', keeplinenums=False): |
90 '''read the .hgtags file into a structure that is suitable for merging | 90 '''read the .hgtags file into a structure that is suitable for merging |
91 | 91 |
92 Depending on the keeplinenums flag, clear the line numbers associated | 92 Depending on the keeplinenums flag, clear the line numbers associated |
93 with each tag. This is done because only the line numbers of the first | 93 with each tag. This is done because only the line numbers of the first |
94 parent are useful for merging. | 94 parent are useful for merging. |
152 mergedtags[tname] = grouptagnodesbyline(taglist) | 152 mergedtags[tname] = grouptagnodesbyline(taglist) |
153 | 153 |
154 # convert the grouped merged tags dict into a format that resembles the | 154 # convert the grouped merged tags dict into a format that resembles the |
155 # final .hgtags file (i.e. a list of blocks of 'node tag' pairs) | 155 # final .hgtags file (i.e. a list of blocks of 'node tag' pairs) |
156 def taglist2string(tlist, tname): | 156 def taglist2string(tlist, tname): |
157 return '\n'.join(['%s %s' % (hexnode, tname) for hexnode in tlist]) | 157 return b'\n'.join([b'%s %s' % (hexnode, tname) for hexnode in tlist]) |
158 | 158 |
159 finaltags = [] | 159 finaltags = [] |
160 for tname, tags in mergedtags.items(): | 160 for tname, tags in mergedtags.items(): |
161 for block in tags: | 161 for block in tags: |
162 block[1] = taglist2string(block[1], tname) | 162 block[1] = taglist2string(block[1], tname) |
168 # file to the first parent's .hgtags file is as small as possible | 168 # file to the first parent's .hgtags file is as small as possible |
169 finaltags.sort(key=lambda x: -1 if x[0] is None else x[0]) | 169 finaltags.sort(key=lambda x: -1 if x[0] is None else x[0]) |
170 | 170 |
171 # finally we can join the sorted groups to get the final contents of the | 171 # finally we can join the sorted groups to get the final contents of the |
172 # merged .hgtags file, and then write it to disk | 172 # merged .hgtags file, and then write it to disk |
173 mergedtagstring = '\n'.join([tags for rank, tags in finaltags if tags]) | 173 mergedtagstring = b'\n'.join([tags for rank, tags in finaltags if tags]) |
174 fcd.write(mergedtagstring + '\n', fcd.flags()) | 174 fcd.write(mergedtagstring + b'\n', fcd.flags()) |
175 | 175 |
176 | 176 |
177 def singletagmerge(p1nodes, p2nodes): | 177 def singletagmerge(p1nodes, p2nodes): |
178 ''' | 178 ''' |
179 merge the nodes corresponding to a single tag | 179 merge the nodes corresponding to a single tag |
227 ''' | 227 ''' |
228 ui = repo.ui | 228 ui = repo.ui |
229 # read the p1, p2 and base tags | 229 # read the p1, p2 and base tags |
230 # only keep the line numbers for the p1 tags | 230 # only keep the line numbers for the p1 tags |
231 p1tags = readtagsformerge( | 231 p1tags = readtagsformerge( |
232 ui, repo, fcd.data().splitlines(), fn="p1 tags", keeplinenums=True | 232 ui, repo, fcd.data().splitlines(), fn=b"p1 tags", keeplinenums=True |
233 ) | 233 ) |
234 p2tags = readtagsformerge( | 234 p2tags = readtagsformerge( |
235 ui, repo, fco.data().splitlines(), fn="p2 tags", keeplinenums=False | 235 ui, repo, fco.data().splitlines(), fn=b"p2 tags", keeplinenums=False |
236 ) | 236 ) |
237 basetags = readtagsformerge( | 237 basetags = readtagsformerge( |
238 ui, repo, fca.data().splitlines(), fn="base tags", keeplinenums=False | 238 ui, repo, fca.data().splitlines(), fn=b"base tags", keeplinenums=False |
239 ) | 239 ) |
240 | 240 |
241 # recover the list of "lost tags" (i.e. those that were found on the base | 241 # recover the list of "lost tags" (i.e. those that were found on the base |
242 # revision but not on one of the revisions being merged) | 242 # revision but not on one of the revisions being merged) |
243 basetagset = set(basetags) | 243 basetagset = set(basetags) |
265 | 265 |
266 if conflictedtags: | 266 if conflictedtags: |
267 numconflicts = len(conflictedtags) | 267 numconflicts = len(conflictedtags) |
268 ui.warn( | 268 ui.warn( |
269 _( | 269 _( |
270 'automatic .hgtags merge failed\n' | 270 b'automatic .hgtags merge failed\n' |
271 'the following %d tags are in conflict: %s\n' | 271 b'the following %d tags are in conflict: %s\n' |
272 ) | 272 ) |
273 % (numconflicts, ', '.join(sorted(conflictedtags))) | 273 % (numconflicts, b', '.join(sorted(conflictedtags))) |
274 ) | 274 ) |
275 return True, 1 | 275 return True, 1 |
276 | 276 |
277 writemergedtags(fcd, mergedtags) | 277 writemergedtags(fcd, mergedtags) |
278 ui.note(_('.hgtags merged successfully\n')) | 278 ui.note(_(b'.hgtags merged successfully\n')) |
279 return False, 0 | 279 return False, 0 |