diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -446,10 +446,11 @@ class workingctx(changectx): """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 @@ class workingctx(changectx): 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 @@ class workingctx(changectx): 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 = [] diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -491,8 +491,8 @@ class localrepository(repo.repository): 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 @@ class localrepository(repo.repository): remove = [] changed = [] use_dirstate = (p1 is None) # not rawcommit - extra = extra.copy() if use_dirstate: p1, p2 = self.dirstate.parents() @@ -796,9 +795,11 @@ class localrepository(repo.repository): 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 @@ class localrepository(repo.repository): 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 @@ class localrepository(repo.repository): 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]