changeset 45233:ada51c1b6916

commitctx: move copy meta config reading in a dedicated function The logic is non trivial, make it contained in a function is clearer. It also unlock easy re-use of that logic without having the pass the value around.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 23 Jul 2020 21:09:42 +0200
parents 4eb6466e6889
children 595307e14140
files mercurial/commit.py
diffstat 1 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commit.py	Thu Jul 23 21:03:30 2020 +0200
+++ b/mercurial/commit.py	Thu Jul 23 21:09:42 2020 +0200
@@ -24,6 +24,25 @@
 )
 
 
+def _write_copy_meta(repo):
+    """return a (changelog, filelog) boolean tuple
+
+    changelog: copy related information should be stored in the changeset
+    filelof:   copy related information should be written in the file revision
+    """
+    if repo.filecopiesmode == b'changeset-sidedata':
+        writechangesetcopy = True
+        writefilecopymeta = True
+    else:
+        writecopiesto = repo.ui.config(b'experimental', b'copies.write-to')
+        writefilecopymeta = writecopiesto != b'changeset-only'
+        writechangesetcopy = writecopiesto in (
+            b'changeset-only',
+            b'compatibility',
+        )
+    return writechangesetcopy, writefilecopymeta
+
+
 def commitctx(repo, ctx, error=False, origctx=None):
     """Add a new revision to the target repository.
     Revision information is passed via the context argument.
@@ -44,16 +63,8 @@
     p1, p2 = ctx.p1(), ctx.p2()
     user = ctx.user()
 
-    if repo.filecopiesmode == b'changeset-sidedata':
-        writechangesetcopy = True
-        writefilecopymeta = True
-    else:
-        writecopiesto = repo.ui.config(b'experimental', b'copies.write-to')
-        writefilecopymeta = writecopiesto != b'changeset-only'
-        writechangesetcopy = writecopiesto in (
-            b'changeset-only',
-            b'compatibility',
-        )
+    writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
+
     p1copies, p2copies = None, None
     if writechangesetcopy:
         p1copies = ctx.p1copies()