phase-shelve: Extract function for _target_phase
authorJason R. Coombs <jaraco@jaraco.com>
Wed, 10 Aug 2022 14:16:55 -0400
changeset 49429 fa00c407d61c
parent 49428 cc7eb0b558c0
child 49430 2064bbf7a1d5
phase-shelve: Extract function for _target_phase
mercurial/shelve.py
--- 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():