Patchwork [05,of,11] commitctx: move copy meta config reading in a dedicated function

login
register
mail settings
Submitter Pierre-Yves David
Date July 24, 2020, 2:38 p.m.
Message ID <87553bac39d2fec8dd7b.1595601510@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/46870/
State Accepted
Headers show

Comments

Pierre-Yves David - July 24, 2020, 2:38 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1595531382 -7200
#      Thu Jul 23 21:09:42 2020 +0200
# Node ID 87553bac39d2fec8dd7b23b44152ec89bcb2f74d
# Parent  93c606831026b6c9644ad84a89204a2338a8aa03
# EXP-Topic commitctx-cleanup-2
# Available At https://foss.heptapod.net/octobus/mercurial-devel/
#              hg pull https://foss.heptapod.net/octobus/mercurial-devel/ -r 87553bac39d2
commitctx: move copy meta config reading in a dedicated function

The logic is non trivial, make it contained in a function is clearer. I also
unlock easy re-use of tha logic without having the pass the value around.

Patch

diff --git a/mercurial/commit.py b/mercurial/commit.py
--- a/mercurial/commit.py
+++ b/mercurial/commit.py
@@ -24,6 +24,25 @@  from . import (
 )
 
 
+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 @@  def commitctx(repo, ctx, error=False, or
     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()