X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/92e5a00682baeaa5a8c293351d270acee6e72a69..cd69a086aa9ce06b83f277b24e2992238654c320:/lib/hg.py?ds=sidebyside diff --git a/lib/hg.py b/lib/hg.py index 9e08e516..6dd6e0cb 100644 --- a/lib/hg.py +++ b/lib/hg.py @@ -7,8 +7,7 @@ import mercurial.merge, mercurial.error encoding.encoding = 'utf-8' -class RepositoryDoesNotExist(Exception): - pass + class Repository(object): """Abstrakcja repozytorium Mercurial. Działa z Mercurial w wersji 1.3.1.""" @@ -45,13 +44,29 @@ class Repository(object): return self.in_branch(lambda: self._get_file(path), branch) def _get_file(self, path): + if not self._file_exists(path): + raise RepositoryException("File not availble in this branch.") + return self.repo.wread(path) - + + def file_exists(self, path, branch): + return self.in_branch(lambda: self._file_exists(path), branch) + + def _file_exists(self, path): + return self.repo.dirstate[path] != "?" + + def write_file(self, path, value, branch): + return self.in_branch(lambda: self._write_file(path, value), branch) + + def _write_file(self, path, value): + return self.repo.wwrite(path, value, []) + def add_file(self, path, value, branch): return self.in_branch(lambda: self._add_file(path, value), branch) def _add_file(self, path, value): - return self.repo.wwrite(path, value.encode('utf-8'), []) + self._write_file(path, value) + return self.repo.add( [path] ) def _commit(self, message, user=None): return self.repo.commit(text=message, user=user) @@ -100,7 +115,7 @@ class Repository(object): except KeyError, ke: raise RepositoryException("Can't switch to branch '%s': no such branch." % bname , ke) except util.Abort, ae: - raise repositoryException("Can't switch to branch '%s': %s" % (bname, ae.message), ae) + raise RepositoryException("Can't switch to branch '%s': %s" % (bname, ae.message), ae) finally: wlock.release() @@ -114,3 +129,6 @@ class RepositoryException(Exception): def __init__(self, msg, cause=None): Exception.__init__(self, msg) self.cause = cause + +class RepositoryDoesNotExist(RepositoryException): + pass