localrepo: let commit() get extra data from workingctx
authorPatrick Mezard <pmezard@gmail.com>
Wed, 18 Jun 2008 22:52:26 +0200
changeset 6708 7566f00a3979
parent 6707 02bad34230a2
child 6709 f84f507c53d3
localrepo: let commit() get extra data from workingctx
mercurial/context.py
mercurial/localrepo.py
--- a/mercurial/context.py	Wed Jun 18 22:52:25 2008 +0200
+++ b/mercurial/context.py	Wed Jun 18 22:52:26 2008 +0200
@@ -446,10 +446,11 @@
     """A workingctx object makes access to data related to
     the current working directory convenient.
     parents - a pair of parent nodeids, or None to use the dirstate.
+    extra - a dictionary of extra values, or None.
     changes - a list of file lists as returned by localrepo.status()
                or None to use the repository status.
     """
-    def __init__(self, repo, parents=None, changes=None):
+    def __init__(self, repo, parents=None, extra=None, changes=None):
         self._repo = repo
         self._rev = None
         self._node = None
@@ -459,6 +460,19 @@
         if changes:
             self._status = list(changes)
 
+        self._extra = {}
+        if extra:
+            self._extra = extra.copy()
+        if 'branch' not in self._extra:
+            branch = self._repo.dirstate.branch()
+            try:
+                branch = branch.decode('UTF-8').encode('UTF-8')
+            except UnicodeDecodeError:
+                raise util.Abort(_('branch name not in UTF-8!'))
+            self._extra['branch'] = branch
+        if self._extra['branch'] == '':
+            self._extra['branch'] = 'default'
+
     def __str__(self):
         return str(self._parents[0]) + "+"
 
@@ -518,7 +532,8 @@
     def deleted(self): return self._status[3]
     def unknown(self): return self._status[4]
     def clean(self): return self._status[5]
-    def branch(self): return self._repo.dirstate.branch()
+    def branch(self): return self._extra['branch']
+    def extra(self): return self._extra
 
     def tags(self):
         t = []
--- a/mercurial/localrepo.py	Wed Jun 18 22:52:25 2008 +0200
+++ b/mercurial/localrepo.py	Wed Jun 18 22:52:26 2008 +0200
@@ -491,8 +491,8 @@
     def changectx(self, changeid=None):
         return context.changectx(self, changeid)
 
-    def workingctx(self, parents=None, changes=None):
-        return context.workingctx(self, parents, changes)
+    def workingctx(self, parents=None, extra=None, changes=None):
+        return context.workingctx(self, parents, extra, changes)
 
     def parents(self, changeid=None):
         '''
@@ -767,7 +767,6 @@
             remove = []
             changed = []
             use_dirstate = (p1 is None) # not rawcommit
-            extra = extra.copy()
 
             if use_dirstate:
                 p1, p2 = self.dirstate.parents()
@@ -796,9 +795,11 @@
                 update_dirstate = (self.dirstate.parents()[0] == p1)
                 changes = [files, [], [], [], []]
 
-            wctx = self.workingctx((p1, p2), changes)
+            wctx = self.workingctx((p1, p2), extra, changes)
             commit = wctx.modified() + wctx.added()
             remove = wctx.removed()
+            extra = wctx.extra().copy()
+            branchname = extra['branch']
 
             c1 = self.changelog.read(p1)
             c2 = self.changelog.read(p2)
@@ -806,15 +807,6 @@
             m2 = self.manifest.read(c2[0])
 
             if use_dirstate:
-                branchname = wctx.branch()
-                try:
-                    branchname = branchname.decode('UTF-8').encode('UTF-8')
-                except UnicodeDecodeError:
-                    raise util.Abort(_('branch name not in UTF-8!'))
-            else:
-                branchname = ""
-
-            if use_dirstate:
                 oldname = c1[5].get("branch") # stored in UTF-8
                 if (not commit and not remove and not force and p2 == nullid
                     and branchname == oldname):
@@ -901,9 +893,6 @@
                 text = self.ui.edit("\n".join(edittext), user)
                 os.chdir(olddir)
 
-            if branchname:
-                extra["branch"] = branchname
-
             lines = [line.rstrip() for line in text.rstrip().splitlines()]
             while lines and not lines[0]:
                 del lines[0]