comparison mercurial/merge.py @ 49911:c7a04bfabd4d

merge: add mergeresult.mapaction to improve speed As a part of [hg update] we convert all [ACTION_CREATED] merge results into [ACTION_GET] actions, and that's slightly inefficient because every insertion pays the full cost of maintaining the [mergeresult] data structure up to date. This commit adds a function [mapaction], which is faster. (saves around 0.3s on a large update involving ~400k files)
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 12 Jan 2023 13:14:00 +0000
parents 7b474609f199
children c166b212bdee
comparison
equal deleted inserted replaced
49910:7b474609f199 49911:c7a04bfabd4d
244 if repo.wvfs.isfileorlink(f): 244 if repo.wvfs.isfileorlink(f):
245 repo.ui.warn(_(b"%s: replacing untracked file\n") % f) 245 repo.ui.warn(_(b"%s: replacing untracked file\n") % f)
246 else: 246 else:
247 repo.ui.warn(_(b"%s: replacing untracked files in directory\n") % f) 247 repo.ui.warn(_(b"%s: replacing untracked files in directory\n") % f)
248 248
249 for f, args, msg in list( 249 def transformargs(f, args):
250 mresult.getactions([mergestatemod.ACTION_CREATED])
251 ):
252 backup = ( 250 backup = (
253 f in fileconflicts 251 f in fileconflicts
254 or pathconflicts 252 or pathconflicts
255 and ( 253 and (
256 f in pathconflicts 254 f in pathconflicts
257 or any(p in pathconflicts for p in pathutil.finddirs(f)) 255 or any(p in pathconflicts for p in pathutil.finddirs(f))
258 ) 256 )
259 ) 257 )
260 (flags,) = args 258 (flags,) = args
261 mresult.addfile(f, mergestatemod.ACTION_GET, (flags, backup), msg) 259 return (flags, backup)
260
261 mresult.mapaction(
262 mergestatemod.ACTION_CREATED, mergestatemod.ACTION_GET, transformargs
263 )
262 264
263 265
264 def _forgetremoved(wctx, mctx, branchmerge, mresult): 266 def _forgetremoved(wctx, mctx, branchmerge, mresult):
265 """ 267 """
266 Forget removed files 268 Forget removed files
587 a, d, m = self._filemapping[filename] 589 a, d, m = self._filemapping[filename]
588 del self._actionmapping[a][filename] 590 del self._actionmapping[a][filename]
589 591
590 self._filemapping[filename] = (action, data, message) 592 self._filemapping[filename] = (action, data, message)
591 self._actionmapping[action][filename] = (data, message) 593 self._actionmapping[action][filename] = (data, message)
594
595 def mapaction(self, actionfrom, actionto, transform):
596 """changes all occurrences of action `actionfrom` into `actionto`,
597 transforming its args with the function `transform`.
598 """
599 orig = self._actionmapping[actionfrom]
600 del self._actionmapping[actionfrom]
601 dest = self._actionmapping[actionto]
602 for f, (data, msg) in orig.items():
603 data = transform(f, data)
604 self._filemapping[f] = (actionto, data, msg)
605 dest[f] = (data, msg)
592 606
593 def getfile(self, filename, default_return=None): 607 def getfile(self, filename, default_return=None):
594 """returns (action, args, msg) about this file 608 """returns (action, args, msg) about this file
595 609
596 returns default_return if the file is not present""" 610 returns default_return if the file is not present"""