Mercurial > hg
changeset 45231:f0d4d1343cb4
commitctx: extract the function that commit a new manifest
The logic is large enough and isolated enough to be extracted, this reduce the
size of the main function, making it simpler to follow.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 23 Jul 2020 14:58:21 +0200 |
parents | 5d0998ccedbb |
children | 4eb6466e6889 |
files | mercurial/commit.py |
diffstat | 1 files changed, 63 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commit.py Fri Jul 24 12:52:32 2020 +0200 +++ b/mercurial/commit.py Thu Jul 23 14:58:21 2020 +0200 @@ -132,41 +132,7 @@ filesremoved = removed files = touched - md = None - if not files: - # if no "files" actually changed in terms of the changelog, - # try hard to detect unmodified manifest entry so that the - # exact same commit can be reproduced later on convert. - md = m1.diff(m, scmutil.matchfiles(repo, ctx.files())) - if not files and md: - repo.ui.debug( - b'not reusing manifest (no file change in ' - b'changelog, but manifest differs)\n' - ) - if files or md: - repo.ui.note(_(b"committing manifest\n")) - # we're using narrowmatch here since it's already applied at - # other stages (such as dirstate.walk), so we're already - # ignoring things outside of narrowspec in most cases. The - # one case where we might have files outside the narrowspec - # at this point is merges, and we already error out in the - # case where the merge has files outside of the narrowspec, - # so this is safe. - mn = mctx.write( - tr, - linkrev, - p1.manifestnode(), - p2.manifestnode(), - added, - drop, - match=repo.narrowmatch(), - ) - else: - repo.ui.debug( - b'reusing manifest from p1 (listed files ' - b'actually unchanged)\n' - ) - mn = p1.manifestnode() + mn = _commit_manifest(tr, linkrev, ctx, mctx, files, added, drop) if writecopiesto == b'changeset-only': # If writing only to changeset extras, use None to indicate that @@ -349,3 +315,65 @@ else: fnode = fparent1 return fnode, touched + + +def _commit_manifest(tr, linkrev, ctx, mctx, files, added, drop): + """make a new manifest entry (or reuse a new one) + + given an initialised manifest context and precomputed list of + - files: files affected by the commit + - added: new entries in the manifest + - drop: entries present in parents but absent of this one + + Create a new manifest revision, reuse existing ones if possible. + + Return the nodeid of the manifest revision. + """ + repo = ctx.repo() + + md = None + + # all this is cached, so it is find to get them all from the ctx. + p1 = ctx.p1() + p2 = ctx.p2() + m1ctx = p1.manifestctx() + + m1 = m1ctx.read() + + manifest = mctx.read() + + if not files: + # if no "files" actually changed in terms of the changelog, + # try hard to detect unmodified manifest entry so that the + # exact same commit can be reproduced later on convert. + md = m1.diff(manifest, scmutil.matchfiles(repo, ctx.files())) + if not files and md: + repo.ui.debug( + b'not reusing manifest (no file change in ' + b'changelog, but manifest differs)\n' + ) + if files or md: + repo.ui.note(_(b"committing manifest\n")) + # we're using narrowmatch here since it's already applied at + # other stages (such as dirstate.walk), so we're already + # ignoring things outside of narrowspec in most cases. The + # one case where we might have files outside the narrowspec + # at this point is merges, and we already error out in the + # case where the merge has files outside of the narrowspec, + # so this is safe. + mn = mctx.write( + tr, + linkrev, + p1.manifestnode(), + p2.manifestnode(), + added, + drop, + match=repo.narrowmatch(), + ) + else: + repo.ui.debug( + b'reusing manifest from p1 (listed files ' b'actually unchanged)\n' + ) + mn = p1.manifestnode() + + return mn