Mercurial > hg
comparison mercurial/merge.py @ 45334:b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
This is similar to past 20 patches or so where we are replacing use of a bare
actions dict with a dedicated mergeresult object. The goal is to have a
dedicated powerful object instead of a dict while making the code more easier to
understand.
In past few patches, we have already simplified the code at some places using
the newly introduced object.
This patch does not updates applyupdates() to use the mergeresult object
directly. That will be done in next patch to make things easier to review.
Differential Revision: https://phab.mercurial-scm.org/D8876
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 03 Aug 2020 14:12:13 +0530 |
parents | f569ca3eb430 |
children | 2c96fd8e05f6 |
comparison
equal
deleted
inserted
replaced
45333:f569ca3eb430 | 45334:b9b055f15035 |
---|---|
1326 } | 1326 } |
1327 | 1327 |
1328 | 1328 |
1329 def applyupdates( | 1329 def applyupdates( |
1330 repo, | 1330 repo, |
1331 actions, | 1331 mresult, |
1332 wctx, | 1332 wctx, |
1333 mctx, | 1333 mctx, |
1334 overwrite, | 1334 overwrite, |
1335 wantfiledata, | 1335 wantfiledata, |
1336 labels=None, | 1336 labels=None, |
1337 commitinfo=None, | 1337 commitinfo=None, |
1338 ): | 1338 ): |
1339 """apply the merge action list to the working directory | 1339 """apply the merge action list to the working directory |
1340 | 1340 |
1341 mresult is a mergeresult object representing result of the merge | |
1341 wctx is the working copy context | 1342 wctx is the working copy context |
1342 mctx is the context to be merged into the working copy | 1343 mctx is the context to be merged into the working copy |
1343 commitinfo is a mapping of information which needs to be stored somewhere | 1344 commitinfo is a mapping of information which needs to be stored somewhere |
1344 (probably mergestate) so that it can be used at commit time. | 1345 (probably mergestate) so that it can be used at commit time. |
1345 | 1346 |
1347 (updated, merged, removed, unresolved) that describes how many | 1348 (updated, merged, removed, unresolved) that describes how many |
1348 files were affected by the update, and filedata is as described in | 1349 files were affected by the update, and filedata is as described in |
1349 batchget. | 1350 batchget. |
1350 """ | 1351 """ |
1351 | 1352 |
1353 actions = mresult.actionsdict | |
1352 _prefetchfiles(repo, mctx, actions) | 1354 _prefetchfiles(repo, mctx, actions) |
1353 | 1355 |
1354 updated, merged, removed = 0, 0, 0 | 1356 updated, merged, removed = 0, 0, 0 |
1355 ms = mergestatemod.mergestate.clean( | 1357 ms = mergestatemod.mergestate.clean( |
1356 repo, wctx.p1().node(), mctx.node(), labels | 1358 repo, wctx.p1().node(), mctx.node(), labels |
1611 extraactions = ms.actions() | 1613 extraactions = ms.actions() |
1612 if extraactions: | 1614 if extraactions: |
1613 mfiles = {a[0] for a in actions[mergestatemod.ACTION_MERGE]} | 1615 mfiles = {a[0] for a in actions[mergestatemod.ACTION_MERGE]} |
1614 for k, acts in pycompat.iteritems(extraactions): | 1616 for k, acts in pycompat.iteritems(extraactions): |
1615 actions[k].extend(acts) | 1617 actions[k].extend(acts) |
1618 for a in acts: | |
1619 mresult.addfile(a[0], k, *a[1:]) | |
1616 if k == mergestatemod.ACTION_GET and wantfiledata: | 1620 if k == mergestatemod.ACTION_GET and wantfiledata: |
1617 # no filedata until mergestate is updated to provide it | 1621 # no filedata until mergestate is updated to provide it |
1618 for a in acts: | 1622 for a in acts: |
1619 getfiledata[a[0]] = None | 1623 getfiledata[a[0]] = None |
1620 # Remove these files from actions[ACTION_MERGE] as well. This is | 1624 # Remove these files from actions[ACTION_MERGE] as well. This is |
1636 mfiles.difference_update(a[0] for a in acts) | 1640 mfiles.difference_update(a[0] for a in acts) |
1637 | 1641 |
1638 actions[mergestatemod.ACTION_MERGE] = [ | 1642 actions[mergestatemod.ACTION_MERGE] = [ |
1639 a for a in actions[mergestatemod.ACTION_MERGE] if a[0] in mfiles | 1643 a for a in actions[mergestatemod.ACTION_MERGE] if a[0] in mfiles |
1640 ] | 1644 ] |
1645 for a in mresult.getactions([mergestatemod.ACTION_MERGE]): | |
1646 if a[0] not in mfiles: | |
1647 mresult.removefile(a[0]) | |
1641 | 1648 |
1642 progress.complete() | 1649 progress.complete() |
1643 assert len(getfiledata) == ( | 1650 assert len(getfiledata) == ( |
1644 len(actions[mergestatemod.ACTION_GET]) if wantfiledata else 0 | 1651 len(actions[mergestatemod.ACTION_GET]) if wantfiledata else 0 |
1645 ) | 1652 ) |
2014 ) | 2021 ) |
2015 | 2022 |
2016 wantfiledata = updatedirstate and not branchmerge | 2023 wantfiledata = updatedirstate and not branchmerge |
2017 stats, getfiledata = applyupdates( | 2024 stats, getfiledata = applyupdates( |
2018 repo, | 2025 repo, |
2019 actions, | 2026 mresult, |
2020 wc, | 2027 wc, |
2021 p2, | 2028 p2, |
2022 overwrite, | 2029 overwrite, |
2023 wantfiledata, | 2030 wantfiledata, |
2024 labels=labels, | 2031 labels=labels, |
2027 | 2034 |
2028 if updatedirstate: | 2035 if updatedirstate: |
2029 with repo.dirstate.parentchange(): | 2036 with repo.dirstate.parentchange(): |
2030 repo.setparents(fp1, fp2) | 2037 repo.setparents(fp1, fp2) |
2031 mergestatemod.recordupdates( | 2038 mergestatemod.recordupdates( |
2032 repo, actions, branchmerge, getfiledata | 2039 repo, mresult.actionsdict, branchmerge, getfiledata |
2033 ) | 2040 ) |
2034 # update completed, clear state | 2041 # update completed, clear state |
2035 util.unlink(repo.vfs.join(b'updatestate')) | 2042 util.unlink(repo.vfs.join(b'updatestate')) |
2036 | 2043 |
2037 if not branchmerge: | 2044 if not branchmerge: |