mercurial/localrepo.py
changeset 50195 11e6eee4b063
parent 50194 8fb391363aad
child 50265 240a04cedd24
--- a/mercurial/localrepo.py	Thu Feb 23 04:53:34 2023 +0100
+++ b/mercurial/localrepo.py	Thu Feb 23 15:37:46 2023 +0100
@@ -100,7 +100,9 @@
 urlerr = util.urlerr
 urlreq = util.urlreq
 
-RE_SKIP_DIRSTATE_ROLLBACK = re.compile(b"^(dirstate|narrowspec.dirstate).*")
+RE_SKIP_DIRSTATE_ROLLBACK = re.compile(
+    b"^((dirstate|narrowspec.dirstate).*|branch$)"
+)
 
 # set of (path, vfs-location) tuples. vfs-location is:
 # - 'plain for vfs relative paths
@@ -2671,6 +2673,13 @@
         # strip" to pick a working copy destination on `hg rollback`
         if self.currentwlock() is not None:
             ds = self.dirstate
+            if ds.branch() == b'default':
+                # force a file to be written if None exist
+                ds.setbranch(b'default')
+            # we cannot simply add "branch" to `all_file_names` because branch
+            # is written outside of the transaction control. So we need to
+            # backup early.
+            tr.addbackup(b"branch", hardlink=True, location=b'plain')
 
             def backup_dirstate(tr):
                 for f in ds.all_file_names():
@@ -2685,7 +2694,6 @@
     def _journalfiles(self):
         return (
             (self.svfs, b'journal'),
-            (self.vfs, b'journal.branch'),
             (self.vfs, b'journal.desc'),
         )
 
@@ -2694,9 +2702,6 @@
 
     @unfilteredmethod
     def _writejournal(self, desc):
-        self.vfs.write(
-            b"journal.branch", encoding.fromlocal(self.dirstate.branch())
-        )
         self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc))
 
     def recover(self):
@@ -2799,18 +2804,6 @@
                     self.dirstate.setparents(self.nullid)
                     self.dirstate.clear()
 
-            try:
-                branch = self.vfs.read(b'undo.branch')
-                self.dirstate.setbranch(encoding.tolocal(branch))
-            except IOError:
-                ui.warn(
-                    _(
-                        b'named branch could not be reset: '
-                        b'current branch is still \'%s\'\n'
-                    )
-                    % self.dirstate.branch()
-                )
-
             parents = tuple([p.rev() for p in self[None].parents()])
             if len(parents) > 1:
                 ui.status(