comparison mercurial/tagmerge.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents b77ff4fbe9ad
children 687b865b95ad
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
76 from .i18n import _ 76 from .i18n import _
77 from .node import ( 77 from .node import (
78 hex, 78 hex,
79 nullid, 79 nullid,
80 ) 80 )
81 from .import ( 81 from . import (
82 tags as tagsmod, 82 tags as tagsmod,
83 util, 83 util,
84 ) 84 )
85 85
86 hexnullid = hex(nullid) 86 hexnullid = hex(nullid)
87 87
88
88 def readtagsformerge(ui, repo, lines, fn='', keeplinenums=False): 89 def readtagsformerge(ui, repo, lines, fn='', keeplinenums=False):
89 '''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
90 91
91 Depending on the keeplinenums flag, clear the line numbers associated 92 Depending on the keeplinenums flag, clear the line numbers associated
92 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
93 parent are useful for merging. 94 parent are useful for merging.
94 ''' 95 '''
95 filetags = tagsmod._readtaghist(ui, repo, lines, fn=fn, recode=None, 96 filetags = tagsmod._readtaghist(
96 calcnodelines=True)[1] 97 ui, repo, lines, fn=fn, recode=None, calcnodelines=True
98 )[1]
97 for tagname, taginfo in filetags.items(): 99 for tagname, taginfo in filetags.items():
98 if not keeplinenums: 100 if not keeplinenums:
99 for el in taginfo: 101 for el in taginfo:
100 el[1] = None 102 el[1] = None
101 return filetags 103 return filetags
104
102 105
103 def grouptagnodesbyline(tagnodes): 106 def grouptagnodesbyline(tagnodes):
104 ''' 107 '''
105 Group nearby nodes (i.e. those that must be written next to each other) 108 Group nearby nodes (i.e. those that must be written next to each other)
106 109
132 groupednodes[-1][1].append(hexnode) 135 groupednodes[-1][1].append(hexnode)
133 if linenum is not None: 136 if linenum is not None:
134 prevlinenum = linenum 137 prevlinenum = linenum
135 return groupednodes 138 return groupednodes
136 139
140
137 def writemergedtags(fcd, mergedtags): 141 def writemergedtags(fcd, mergedtags):
138 ''' 142 '''
139 write the merged tags while trying to minimize the diff to the first parent 143 write the merged tags while trying to minimize the diff to the first parent
140 144
141 This function uses the ordering info stored on the merged tags dict to 145 This function uses the ordering info stored on the merged tags dict to
166 170
167 # 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
168 # merged .hgtags file, and then write it to disk 172 # merged .hgtags file, and then write it to disk
169 mergedtagstring = '\n'.join([tags for rank, tags in finaltags if tags]) 173 mergedtagstring = '\n'.join([tags for rank, tags in finaltags if tags])
170 fcd.write(mergedtagstring + '\n', fcd.flags()) 174 fcd.write(mergedtagstring + '\n', fcd.flags())
175
171 176
172 def singletagmerge(p1nodes, p2nodes): 177 def singletagmerge(p1nodes, p2nodes):
173 ''' 178 '''
174 merge the nodes corresponding to a single tag 179 merge the nodes corresponding to a single tag
175 180
212 # - non common highest ranking nodes 217 # - non common highest ranking nodes
213 # note that the common nodes plus the non common lowest ranking nodes is the 218 # note that the common nodes plus the non common lowest ranking nodes is the
214 # whole list of lr nodes 219 # whole list of lr nodes
215 return lrnodes + hrnodes[commonidx:] 220 return lrnodes + hrnodes[commonidx:]
216 221
222
217 def merge(repo, fcd, fco, fca): 223 def merge(repo, fcd, fco, fca):
218 ''' 224 '''
219 Merge the tags of two revisions, taking into account the base tags 225 Merge the tags of two revisions, taking into account the base tags
220 Try to minimize the diff between the merged tags and the first parent tags 226 Try to minimize the diff between the merged tags and the first parent tags
221 ''' 227 '''
222 ui = repo.ui 228 ui = repo.ui
223 # read the p1, p2 and base tags 229 # read the p1, p2 and base tags
224 # only keep the line numbers for the p1 tags 230 # only keep the line numbers for the p1 tags
225 p1tags = readtagsformerge( 231 p1tags = readtagsformerge(
226 ui, repo, fcd.data().splitlines(), fn="p1 tags", 232 ui, repo, fcd.data().splitlines(), fn="p1 tags", keeplinenums=True
227 keeplinenums=True) 233 )
228 p2tags = readtagsformerge( 234 p2tags = readtagsformerge(
229 ui, repo, fco.data().splitlines(), fn="p2 tags", 235 ui, repo, fco.data().splitlines(), fn="p2 tags", keeplinenums=False
230 keeplinenums=False) 236 )
231 basetags = readtagsformerge( 237 basetags = readtagsformerge(
232 ui, repo, fca.data().splitlines(), fn="base tags", 238 ui, repo, fca.data().splitlines(), fn="base tags", keeplinenums=False
233 keeplinenums=False) 239 )
234 240
235 # 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
236 # revision but not on one of the revisions being merged) 242 # revision but not on one of the revisions being merged)
237 basetagset = set(basetags) 243 basetagset = set(basetags)
238 for n, pntags in enumerate((p1tags, p2tags)): 244 for n, pntags in enumerate((p1tags, p2tags)):
257 continue 263 continue
258 mergedtags[tname] = mergednodes 264 mergedtags[tname] = mergednodes
259 265
260 if conflictedtags: 266 if conflictedtags:
261 numconflicts = len(conflictedtags) 267 numconflicts = len(conflictedtags)
262 ui.warn(_('automatic .hgtags merge failed\n' 268 ui.warn(
263 'the following %d tags are in conflict: %s\n') 269 _(
264 % (numconflicts, ', '.join(sorted(conflictedtags)))) 270 'automatic .hgtags merge failed\n'
271 'the following %d tags are in conflict: %s\n'
272 )
273 % (numconflicts, ', '.join(sorted(conflictedtags)))
274 )
265 return True, 1 275 return True, 1
266 276
267 writemergedtags(fcd, mergedtags) 277 writemergedtags(fcd, mergedtags)
268 ui.note(_('.hgtags merged successfully\n')) 278 ui.note(_('.hgtags merged successfully\n'))
269 return False, 0 279 return False, 0