Patchwork D6374: context: default to using branch from dirstate only in workingctx

login
register
mail settings
Submitter phabricator
Date May 15, 2019, 4:17 a.m.
Message ID <differential-rev-PHID-DREV-zi5bovapr5wbmckixxeh-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40031/
State Superseded
Headers show

Comments

phabricator - May 15, 2019, 4:17 a.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Same reasoning as previous commits: only the workingctx should know
  about the dirstate.
  
  committablectx now seems free of dirstate references.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6374

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1119,13 +1119,7 @@ 
             self._extra = extra.copy()
         if branch is not None:
             self._extra['branch'] = encoding.fromlocal(branch)
-        elif 'branch' not in self._extra:
-            try:
-                branch = encoding.fromlocal(self._repo.dirstate.branch())
-            except UnicodeDecodeError:
-                raise error.Abort(_('branch name not in UTF-8!'))
-            self._extra['branch'] = branch
-        if self._extra['branch'] == '':
+        if not self._extra.get('branch'):
             self._extra['branch'] = 'default'
 
     def __bytes__(self):
@@ -1243,7 +1237,14 @@ 
     """
     def __init__(self, repo, text="", user=None, date=None, extra=None,
                  changes=None):
-        super(workingctx, self).__init__(repo, text, user, date, extra, changes)
+        branch = None
+        if not extra or 'branch' not in extra:
+            try:
+                branch = repo.dirstate.branch()
+            except UnicodeDecodeError:
+                raise error.Abort(_('branch name not in UTF-8!'))
+        super(workingctx, self).__init__(repo, text, user, date, extra, changes,
+                                         branch=branch)
 
     def __iter__(self):
         d = self._repo.dirstate