changeset 49429:fa00c407d61c

phase-shelve: Extract function for _target_phase
author Jason R. Coombs <jaraco@jaraco.com>
date Wed, 10 Aug 2022 14:16:55 -0400
parents cc7eb0b558c0
children 2064bbf7a1d5
files mercurial/shelve.py
diffstat 1 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/shelve.py	Tue Aug 02 10:29:05 2022 -0400
+++ b/mercurial/shelve.py	Wed Aug 10 14:16:55 2022 -0400
@@ -99,6 +99,10 @@
         return sorted(info, reverse=True)
 
 
+def _target_phase(repo):
+    return phases.internal if phases.supportinternal(repo) else phases.secret
+
+
 class Shelf:
     """Represents a shelf, including possibly multiple files storing it.
 
@@ -167,9 +171,7 @@
         filename = self.name + b'.hg'
         fp = self.vfs(filename)
         try:
-            targetphase = phases.internal
-            if not phases.supportinternal(repo):
-                targetphase = phases.secret
+            targetphase = _target_phase(repo)
             gen = exchange.readbundle(repo.ui, fp, filename, self.vfs)
             pretip = repo[b'tip']
             bundle2.applybundle(
@@ -485,9 +487,7 @@
         if hasmq:
             saved, repo.mq.checkapplied = repo.mq.checkapplied, False
 
-        targetphase = phases.internal
-        if not phases.supportinternal(repo):
-            targetphase = phases.secret
+        targetphase = _target_phase(repo)
         overrides = {(b'phases', b'new-commit'): targetphase}
         try:
             editor_ = False
@@ -851,9 +851,7 @@
             repo.setparents(state.pendingctx.node(), repo.nullid)
             repo.dirstate.write(repo.currenttransaction())
 
-        targetphase = phases.internal
-        if not phases.supportinternal(repo):
-            targetphase = phases.secret
+        targetphase = _target_phase(repo)
         overrides = {(b'phases', b'new-commit'): targetphase}
         with repo.ui.configoverride(overrides, b'unshelve'):
             with repo.dirstate.parentchange():