Mercurial > hatta
changeset 2455:6aa6642aeb2e
Fix #104, compatibility with Mercurial 3.2
Unfortunately, this time just catching TypeError is not enough and
I have to actually check the version to see whether to raise an
exception or return None.
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 19 Dec 2014 23:23:10 +0100 |
| parents | 501cdc1e4962 |
| children | 8bb6ece4d0b4 |
| files | hatta/storage.py |
| diffstat | 1 files changed, 38 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/hatta/storage.py Tue May 27 18:03:56 2014 +0200 +++ b/hatta/storage.py Fri Dec 19 23:23:10 2014 +0100 @@ -19,6 +19,7 @@ import mercurial.ui import mercurial.util import mercurial.simplemerge +import mercurial.__version__ from hatta import error from hatta import page @@ -57,6 +58,37 @@ return ui +def _get_memfilectx(repo, path, data, islink=False, isexec=False, copied=None, memctx=None): + try: + # For mercurial 3.2+ + return mercurial.context.memfilectx( + repo=repo, + path=path, + data=data, + islink=islink, + isexec=isexec, + memctx=memctx, + copied=copied, + ) + except TypeError: + # For older mercurial + return mercurial.context.memfilectx( + path=path, + data=data, + islink=islink, + isexec=isexec, + copied=copied, + ) + + +def _file_deleted(): + if mercurial.__version__.version.startswith(('0.', '1.', '2.', '3.0', '3.1')): + # For older mercurial + raise IOError() + # For mercurial 3.2+ + return None + + def merge_func(base, other, this): """Used for merging edit conflicts.""" @@ -193,6 +225,7 @@ other_data = filetip.filectx(other).data() return merge_func(parent_data, other_data, data) + def save_data(self, title, data, author=None, comment=None, parent_rev=None): """Save a new revision of the page. If the data is None, deletes it.""" @@ -213,8 +246,8 @@ text = _(u'failed merge of edit conflict').encode('utf-8') def filectxfn(repo, memctx, path): if data is None: - raise IOError() - return mercurial.context.memfilectx(path, data, False, False, None) + return _file_deleted() + return _get_memfilectx(repo, path, data, memctx=memctx) ctx = mercurial.context.memctx( repo=self.repo, parents=(parent, other), @@ -469,11 +502,10 @@ text = _(u'failed merge of edit conflict').encode('utf-8') def filectxfn(repo, memctx, path): if data is None or path == dir_path: - raise IOError() + return _file_deleted() if path == new_dir_path: - return mercurial.context.memfilectx(path, dir_data, - False, False, dir_path) - return mercurial.context.memfilectx(path, data, False, False, None) + return _get_memfilectx(repo, path, dir_data, memctx=memctx, copied=dir_path) + return _get_memfilectx(repo, path, data, memctx=memctx) ctx = mercurial.context.memctx( repo=self.repo, parents=(parent, other),
