diff options
author | Javi Merino <vicho@debian.org> | 2015-04-26 10:39:12 +0100 |
---|---|---|
committer | Javi Merino <vicho@debian.org> | 2015-04-26 10:39:12 +0100 |
commit | e3dadeacf189da700cbcc4dde9c535d07534a347 (patch) | |
tree | bd66f19794ead77a150ffbe20427e3f4b14dc7db /hgsubversion/compathacks.py | |
parent | 6e1b099dbc4754626cb8972659b4b19b9ed5c717 (diff) |
Upstream version 1.8
Diffstat (limited to 'hgsubversion/compathacks.py')
-rw-r--r-- | hgsubversion/compathacks.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/hgsubversion/compathacks.py b/hgsubversion/compathacks.py index bfc4649..9e31bf6 100644 --- a/hgsubversion/compathacks.py +++ b/hgsubversion/compathacks.py @@ -1,4 +1,7 @@ -"""Functions to work around API changes inside Mercurial.""" +"""Functions to work around API changes.""" + +import errno +import sys def branchset(repo): """Return the set of branches present in a repo. @@ -25,3 +28,42 @@ def makememfilectx(repo, path, data, islink, isexec, copied): return context.memfilectx(repo, path, data, islink, isexec, copied) except TypeError: return context.memfilectx(path, data, islink, isexec, copied) + +def filectxfn_deleted(memctx, path): + """ + Return None or raise an IOError as necessary if path is deleted. + + Call as: + + if path_missing: + return compathacks.filectxfn_deleted(memctx, path) + + Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, + for deleted files, filectxfn should return None rather than returning + IOError. + """ + if getattr(memctx, '_returnnoneformissingfiles', False): + return None + raise IOError(errno.ENOENT, '%s is deleted' % path) + +def filectxfn_deleted_reraise(memctx): + """ + Return None or reraise exc as necessary. + + Call as: + + try: + # code that raises IOError if the path is missing + except IOError: + return compathacks.filectxfn_deleted_reraise(memctx) + + Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, + for deleted files, filectxfn should return None rather than returning + IOError. + """ + exc_info = sys.exc_info() + if (exc_info[1].errno == errno.ENOENT and + getattr(memctx, '_returnnoneformissingfiles', False)): + return None + # preserve traceback info + raise exc_info[0], exc_info[1], exc_info[2] |