Mercurial > hgsubversion
comparison hgsubversion/compathacks.py @ 1237:4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Mercurial rev 650b5b6e75ed changed the contract for filectxfn, and rev
d226fe36e362 added a way for us to detect the change.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 16 Sep 2014 16:42:57 -0700 |
parents | 9490a3052935 |
children | c5b7fb8911c0 |
comparison
equal
deleted
inserted
replaced
1236:f367a4462191 | 1237:4ed0855d211f |
---|---|
1 """Functions to work around API changes.""" | 1 """Functions to work around API changes.""" |
2 | 2 |
3 import errno | |
4 import sys | |
3 | 5 |
4 def branchset(repo): | 6 def branchset(repo): |
5 """Return the set of branches present in a repo. | 7 """Return the set of branches present in a repo. |
6 | 8 |
7 Works around branchtags() vanishing between 2.8 and 2.9. | 9 Works around branchtags() vanishing between 2.8 and 2.9. |
24 from mercurial import context | 26 from mercurial import context |
25 try: | 27 try: |
26 return context.memfilectx(repo, path, data, islink, isexec, copied) | 28 return context.memfilectx(repo, path, data, islink, isexec, copied) |
27 except TypeError: | 29 except TypeError: |
28 return context.memfilectx(path, data, islink, isexec, copied) | 30 return context.memfilectx(path, data, islink, isexec, copied) |
31 | |
32 def filectxfn_deleted(memctx, path): | |
33 """ | |
34 Return None or raise an IOError as necessary if path is deleted. | |
35 | |
36 Call as: | |
37 | |
38 if path_missing: | |
39 return compathacks.filectxfn_deleted(memctx, path) | |
40 | |
41 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, | |
42 for deleted files, filectxfn should return None rather than returning | |
43 IOError. | |
44 """ | |
45 if getattr(memctx, '_returnnoneformissingfiles', False): | |
46 return None | |
47 raise IOError(errno.ENOENT, '%s is deleted' % path) | |
48 | |
49 def filectxfn_deleted_reraise(memctx): | |
50 """ | |
51 Return None or reraise exc as necessary. | |
52 | |
53 Call as: | |
54 | |
55 try: | |
56 # code that raises IOError if the path is missing | |
57 except IOError: | |
58 return compathacks.filectxfn_deleted_reraise(memctx) | |
59 | |
60 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, | |
61 for deleted files, filectxfn should return None rather than returning | |
62 IOError. | |
63 """ | |
64 exc_info = sys.exc_info() | |
65 if (exc_info[1].errno == errno.ENOENT and | |
66 getattr(memctx, '_returnnoneformissingfiles', False)): | |
67 return None | |
68 # preserve traceback info | |
69 raise exc_info[0], exc_info[1], exc_info[2] |