Mercurial > hgsubversion
annotate hgsubversion/compathacks.py @ 1247:3a4d74823187
pull: wrap exchange.pull if localrepository.pull isn't available
Mercurial rev 73b5b8312ce6 removed localrepository.pull. We don't do it the
other way round (wrap pull if exchange.pull is available) because that's been
available with a different signature since Mercurial 3.0.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 13 Oct 2014 23:56:13 -0700 |
parents | 4ed0855d211f |
children | c5b7fb8911c0 |
rev | line source |
---|---|
1139
d1bd52202c6d
compathacks: specify for generic compatibility hacks
Sean Farley <sean.michael.farley@gmail.com>
parents:
1138
diff
changeset
|
1 """Functions to work around API changes.""" |
1103
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 |
1237
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
3 import errno |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
4 import sys |
1103
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 |
6e1dbf6cbc92
compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
6 def branchset(repo): |
1218
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
7 """Return the set of branches present in a repo. |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
8 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
9 Works around branchtags() vanishing between 2.8 and 2.9. |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
10 """ |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
11 try: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
12 return set(repo.branchmap()) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
13 except AttributeError: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
14 return set(repo.branchtags()) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
15 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
16 def pickle_load(f): |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
17 import cPickle as pickle |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
18 f.seek(0) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
19 return pickle.load(f) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
20 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
21 def makememfilectx(repo, path, data, islink, isexec, copied): |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
22 """Return a memfilectx |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
23 |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
24 Works around memfilectx() adding a repo argument between 3.0 and 3.1. |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
25 """ |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
26 from mercurial import context |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
27 try: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
28 return context.memfilectx(repo, path, data, islink, isexec, copied) |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
29 except TypeError: |
68e6927fa387
compathacks: add wrapper for memfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents:
1103
diff
changeset
|
30 return context.memfilectx(path, data, islink, isexec, copied) |
1237
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
31 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
32 def filectxfn_deleted(memctx, path): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
33 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
34 Return None or raise an IOError as necessary if path is deleted. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
35 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
36 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
37 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
38 if path_missing: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
39 return compathacks.filectxfn_deleted(memctx, path) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
40 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
41 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
42 for deleted files, filectxfn should return None rather than returning |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
43 IOError. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
44 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
45 if getattr(memctx, '_returnnoneformissingfiles', False): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
46 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
47 raise IOError(errno.ENOENT, '%s is deleted' % path) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
48 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
49 def filectxfn_deleted_reraise(memctx): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
50 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
51 Return None or reraise exc as necessary. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
52 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
53 Call as: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
54 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
55 try: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
56 # code that raises IOError if the path is missing |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
57 except IOError: |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
58 return compathacks.filectxfn_deleted_reraise(memctx) |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
59 |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
60 Works around filectxfn's contract changing between 3.1 and 3.2: 3.2 onwards, |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
61 for deleted files, filectxfn should return None rather than returning |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
62 IOError. |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
63 """ |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
64 exc_info = sys.exc_info() |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
65 if (exc_info[1].errno == errno.ENOENT and |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
66 getattr(memctx, '_returnnoneformissingfiles', False)): |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
67 return None |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
68 # preserve traceback info |
4ed0855d211f
compathacks: add hacks for filectxfn deletion contract changing
Siddharth Agarwal <sid0@fb.com>
parents:
1228
diff
changeset
|
69 raise exc_info[0], exc_info[1], exc_info[2] |