comparison mercurial/tagmerge.py @ 45942:89a2afe31e82

formating: upgrade to black 20.8b1 This required a couple of small tweaks to un-confuse black, but now it works. Big formatting changes come from: * Dramatically improved collection-splitting logic upstream * Black having a strong (correct IMO) opinion that """ is better than ''' Differential Revision: https://phab.mercurial-scm.org/D9430
author Augie Fackler <raf@durin42.com>
date Fri, 27 Nov 2020 17:03:29 -0500
parents 687b865b95ad
children 59fa3890d40a
comparison
equal deleted inserted replaced
45941:346af7687c6f 45942:89a2afe31e82
85 85
86 hexnullid = hex(nullid) 86 hexnullid = hex(nullid)
87 87
88 88
89 def readtagsformerge(ui, repo, lines, fn=b'', 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.
95 ''' 95 """
96 filetags = tagsmod._readtaghist( 96 filetags = tagsmod._readtaghist(
97 ui, repo, lines, fn=fn, recode=None, calcnodelines=True 97 ui, repo, lines, fn=fn, recode=None, calcnodelines=True
98 )[1] 98 )[1]
99 for tagname, taginfo in filetags.items(): 99 for tagname, taginfo in filetags.items():
100 if not keeplinenums: 100 if not keeplinenums:
102 el[1] = None 102 el[1] = None
103 return filetags 103 return filetags
104 104
105 105
106 def grouptagnodesbyline(tagnodes): 106 def grouptagnodesbyline(tagnodes):
107 ''' 107 """
108 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)
109 109
110 The input is a list of [node, position] pairs, corresponding to a given tag 110 The input is a list of [node, position] pairs, corresponding to a given tag
111 The position is the line number where the node was found on the first parent 111 The position is the line number where the node was found on the first parent
112 .hgtags file, or None for those nodes that came from the base or the second 112 .hgtags file, or None for those nodes that came from the base or the second
116 groups of nodes that must be written next to each other because their 116 groups of nodes that must be written next to each other because their
117 positions are consecutive or have no position preference (because their 117 positions are consecutive or have no position preference (because their
118 position is None). 118 position is None).
119 119
120 The result is a list of [position, [consecutive node list]] 120 The result is a list of [position, [consecutive node list]]
121 ''' 121 """
122 firstlinenum = None 122 firstlinenum = None
123 for hexnode, linenum in tagnodes: 123 for hexnode, linenum in tagnodes:
124 firstlinenum = linenum 124 firstlinenum = linenum
125 if firstlinenum is not None: 125 if firstlinenum is not None:
126 break 126 break
137 prevlinenum = linenum 137 prevlinenum = linenum
138 return groupednodes 138 return groupednodes
139 139
140 140
141 def writemergedtags(fcd, mergedtags): 141 def writemergedtags(fcd, mergedtags):
142 ''' 142 """
143 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
144 144
145 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
146 generate an .hgtags file which is correct (in the sense that its contents 146 generate an .hgtags file which is correct (in the sense that its contents
147 correspond to the result of the tag merge) while also being as close as 147 correspond to the result of the tag merge) while also being as close as
148 possible to the first parent's .hgtags file. 148 possible to the first parent's .hgtags file.
149 ''' 149 """
150 # group the node-tag pairs that must be written next to each other 150 # group the node-tag pairs that must be written next to each other
151 for tname, taglist in list(mergedtags.items()): 151 for tname, taglist in list(mergedtags.items()):
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
173 mergedtagstring = b'\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 + b'\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
180 180
181 Note that the inputs are lists of node-linenum pairs (i.e. not just lists 181 Note that the inputs are lists of node-linenum pairs (i.e. not just lists
182 of nodes) 182 of nodes)
183 ''' 183 """
184 if not p2nodes: 184 if not p2nodes:
185 return p1nodes 185 return p1nodes
186 if not p1nodes: 186 if not p1nodes:
187 return p2nodes 187 return p2nodes
188 188
219 # whole list of lr nodes 219 # whole list of lr nodes
220 return lrnodes + hrnodes[commonidx:] 220 return lrnodes + hrnodes[commonidx:]
221 221
222 222
223 def merge(repo, fcd, fco, fca): 223 def merge(repo, fcd, fco, fca):
224 ''' 224 """
225 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
226 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
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=b"p1 tags", keeplinenums=True 232 ui, repo, fcd.data().splitlines(), fn=b"p1 tags", keeplinenums=True