mercurial/context.py
changeset 42296 df2f22befdc8
parent 42295 fdd4d668ceb5
child 42297 62bb49a1d05d
--- a/mercurial/context.py	Fri May 10 21:55:59 2019 -0700
+++ b/mercurial/context.py	Fri May 10 22:51:33 2019 -0700
@@ -1102,7 +1102,7 @@
     """A committablectx object provides common functionality for a context that
     wants the ability to commit, e.g. workingctx or memctx."""
     def __init__(self, repo, text="", user=None, date=None, extra=None,
-                 changes=None):
+                 changes=None, branch=None):
         super(committablectx, self).__init__(repo)
         self._rev = None
         self._node = None
@@ -1117,7 +1117,9 @@
         self._extra = {}
         if extra:
             self._extra = extra.copy()
-        if 'branch' not in self._extra:
+        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:
@@ -2308,7 +2310,8 @@
 
     def __init__(self, repo, parents, text, files, filectxfn, user=None,
                  date=None, extra=None, branch=None, editor=False):
-        super(memctx, self).__init__(repo, text, user, date, extra)
+        super(memctx, self).__init__(repo, text, user, date, extra,
+                                     branch=branch)
         self._rev = None
         self._node = None
         parents = [(p or nullid) for p in parents]
@@ -2316,8 +2319,6 @@
         self._parents = [self._repo[p] for p in (p1, p2)]
         files = sorted(set(files))
         self._files = files
-        if branch is not None:
-            self._extra['branch'] = encoding.fromlocal(branch)
         self.substate = {}
 
         if isinstance(filectxfn, patch.filestore):