X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/38343a3fc11f5509c8522fec94c0ae7085b7244f..3c7b27992f89ce11dfe8c2576c6f82f182e771d2:/lib/hg.py diff --git a/lib/hg.py b/lib/hg.py index 535707d8..2b885b3c 100644 --- a/lib/hg.py +++ b/lib/hg.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- import os import codecs -from mercurial import localrepo, ui, error, match, node +from mercurial import localrepo, ui, error, match, node, encoding +encoding.encoding = 'utf-8' class RepositoryDoesNotExist(Exception): pass @@ -48,7 +49,7 @@ class Repository(object): if path not in self._pending_files: self._pending_files.append(path) - def commit(self, message='hgshelve auto commit', key=None, user=None): + def commit(self, message=u'hgshelve auto commit', key=None, user=None): """ Commit unsynchronized data to disk. Arguments:: @@ -56,6 +57,11 @@ class Repository(object): - message: mercurial's changeset message - key: supply to sync only one key """ + if isinstance(message, unicode): + message = message.encode('utf-8') + if isinstance(user, unicode): + user = user.encode('utf-8') + commited = False rev = None files_to_add = [] @@ -67,7 +73,7 @@ class Repository(object): # will commit all keys pending_files = self._pending_files else: - if key not in self._pending_files: + if keys not in self._pending_files: # key isn't changed return None else: @@ -89,6 +95,9 @@ class Repository(object): self.repo.forget(files_to_remove) # ---- hg commit if files_to_commit: + for i, f in enumerate(files_to_commit): + if isinstance(f, unicode): + files_to_commit[i] = f.encode('utf-8') matcher = match.match(self.repo.root, self.repo.root, files_to_commit, default='path') rev = self.repo.commit(message, user=user, match=matcher) commited = True @@ -99,4 +108,22 @@ class Repository(object): # reread keys # self._keys = self.get_persisted_objects_keys() # return node.hex(rev) - \ No newline at end of file + + def in_branch(self, branch_name, action): + wlock = self.repo.wlock() + try: + current_branch = self.repo[None].branch() + self.repo.dirstate.setbranch(branch_name) + try: + # do some stuff + action() + finally: + self.repo.dirstate.setbranch(current_branch) + finally: + wlock.release() + + def write_lock(self): + """Returns w write lock to the repository.""" + return self.repo.wlock() + +