Mercurial > hg > mercurial-crew-with-dirclash
changeset 4207:7e1c8a565a4f
Move branch read/write to dirstate where it belongs
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 13 Mar 2007 18:50:02 -0500 |
parents | 0b48e3985765 |
children | f80cf8b7bbd9 |
files | mercurial/commands.py mercurial/context.py mercurial/dirstate.py mercurial/merge.py tests/test-newbranch |
diffstat | 5 files changed, 21 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -255,12 +255,10 @@ def branch(ui, repo, label=None): current branch name. """ - if label is not None: - repo.opener("branch", "w").write(util.fromlocal(label) + '\n') + if label: + repo.dirstate.setbranch(util.fromlocal(label)) else: - b = util.tolocal(repo.workingctx().branch()) - if b: - ui.write("%s\n" % b) + ui.write("%s\n" % util.tolocal(repo.dirstate.branch())) def branches(ui, repo): """list repository named branches
--- a/mercurial/context.py +++ b/mercurial/context.py @@ -411,11 +411,7 @@ 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): - try: - return self._repo.opener("branch").read().strip() or "default" - except IOError: - return "default" + def branch(self): return self._repo.dirstate.branch() def parents(self): """return contexts for each parent changeset"""
--- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -25,6 +25,7 @@ class dirstate(object): self.dirs = None self.copymap = {} self.ignorefunc = None + self._branch = None def wjoin(self, f): return os.path.join(self.root, f) @@ -137,6 +138,15 @@ class dirstate(object): self.lazyread() return self.pl + def branch(self): + if not self._branch: + try: + self._branch = self.opener("branch").read().strip()\ + or "default" + except IOError: + self._branch = "default" + return self._branch + def markdirty(self): if not self.dirty: self.dirty = 1 @@ -146,6 +156,10 @@ class dirstate(object): self.markdirty() self.pl = p1, p2 + def setbranch(self, branch): + self._branch = branch + self.opener("branch", "w").write(branch + '\n') + def state(self, key): try: return self[key][0]
--- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -488,9 +488,9 @@ def update(repo, node, branchmerge, forc if not partial: recordupdates(repo, action, branchmerge) repo.dirstate.setparents(fp1, fp2) + if not branchmerge: + repo.dirstate.setbranch(p2.branch()) repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3]) - if not branchmerge: - repo.opener("branch", "w").write(p2.branch() + "\n") return stats