+ tip = self.get_branch_tip(bname)
+ status = self._checkout(tip)
+
+ if not status.isclean():
+ raise RepositoryException("Unclean branch switch. This IS REALLY bad.")
+
+ return current
+ except KeyError, ke:
+ raise RepositoryException((u"Can't switch to branch '%s': no such branch." % bname) , ke)
+ except util.Abort, ae:
+ raise RepositoryException(u"Can't switch to branch '%s': %s" % (bname, ae.message), ae)
+ finally:
+ wlock.release()
+
+ def with_wlock(self, action):
+ wlock = self.repo.wlock()
+ try:
+ action()
+ finally:
+ wlock.release()
+
+ def _create_branch(self, name, parent_rev, msg=None, before_commit=None):
+ """WARNING: leaves the working directory in the new branch"""
+ name = sanitize_string(name)
+
+ if self.has_branch(name): return # just exit
+
+ self._checkout(parent_rev)
+ self.repo.dirstate.setbranch(name)
+
+ if msg is None:
+ msg = "Initial commit for branch '%s'." % name
+
+ if before_commit: before_commit()
+ self._commit(msg, user='platform')
+ return self.get_branch_tip(name)
+
+ def write_lock(self):
+ """Returns w write lock to the repository."""
+ return self.repo.wlock()
+
+ def has_branch(self, name):
+ name = sanitize_string(name)
+ return (name in self.repo.branchmap().keys())
+
+ def get_branch_tip(self, name):
+ name = sanitize_string(name)
+ return self.repo.branchtags()[name]
+
+ def getnode(self, rev):
+ return self.repo[rev]
+
+class MergeStatus(object):
+
+ def __init__(self, mstatus):
+ self.updated = mstatus[0]
+ self.merged = mstatus[1]
+ self.removed = mstatus[2]
+ self.unresolved = mstatus[3]
+
+ def isclean(self):
+ return self.unresolved == 0
+
+class UpdateStatus(object):
+
+ def __init__(self, mstatus):
+ self.modified = mstatus[0]
+ self.added = mstatus[1]
+ self.removed = mstatus[2]
+ self.deleted = mstatus[3]
+ self.untracked = mstatus[4]
+ self.ignored = mstatus[5]
+ self.clean = mstatus[6]
+
+ def has_changes(self):
+ return bool( len(self.modified) + len(self.added) + \
+ len(self.removed) + len(self.deleted) )
+
+class RepositoryException(Exception):
+ def __init__(self, msg, cause=None):
+ Exception.__init__(self, msg)
+ self.cause = cause
+
+class UncleanMerge(RepositoryException):
+ pass
+
+class RepositoryDoesNotExist(RepositoryException):
+ pass
+