Show More
@@ -1,107 +1,110 b'' | |||||
1 | # Infinite push |
|
1 | # Infinite push | |
2 | # |
|
2 | # | |
3 | # Copyright 2016 Facebook, Inc. |
|
3 | # Copyright 2016 Facebook, Inc. | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 | """ |
|
7 | """ | |
8 | [infinitepush] |
|
8 | [infinitepush] | |
9 | # Server-side option. Used only if indextype=disk. |
|
9 | # Server-side option. Used only if indextype=disk. | |
10 | # Filesystem path to the index store |
|
10 | # Filesystem path to the index store | |
11 | indexpath = PATH |
|
11 | indexpath = PATH | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | from __future__ import absolute_import |
|
14 | from __future__ import absolute_import | |
15 |
|
15 | |||
16 | import os |
|
16 | import os | |
17 |
|
17 | |||
|
18 | from mercurial import util | |||
|
19 | ||||
18 | from mercurial.utils import stringutil |
|
20 | from mercurial.utils import stringutil | |
19 |
|
21 | |||
20 | from . import indexapi |
|
22 | from . import indexapi | |
21 |
|
23 | |||
22 | class fileindexapi(indexapi.indexapi): |
|
24 | class fileindexapi(indexapi.indexapi): | |
23 | def __init__(self, repo): |
|
25 | def __init__(self, repo): | |
24 | super(fileindexapi, self).__init__() |
|
26 | super(fileindexapi, self).__init__() | |
25 | self._repo = repo |
|
27 | self._repo = repo | |
26 | root = repo.ui.config('infinitepush', 'indexpath') |
|
28 | root = repo.ui.config('infinitepush', 'indexpath') | |
27 | if not root: |
|
29 | if not root: | |
28 | root = os.path.join('scratchbranches', 'index') |
|
30 | root = os.path.join('scratchbranches', 'index') | |
29 |
|
31 | |||
30 | self._nodemap = os.path.join(root, 'nodemap') |
|
32 | self._nodemap = os.path.join(root, 'nodemap') | |
31 | self._bookmarkmap = os.path.join(root, 'bookmarkmap') |
|
33 | self._bookmarkmap = os.path.join(root, 'bookmarkmap') | |
32 | self._metadatamap = os.path.join(root, 'nodemetadatamap') |
|
34 | self._metadatamap = os.path.join(root, 'nodemetadatamap') | |
33 | self._lock = None |
|
35 | self._lock = None | |
34 |
|
36 | |||
35 | def __enter__(self): |
|
37 | def __enter__(self): | |
36 | self._lock = self._repo.wlock() |
|
38 | self._lock = self._repo.wlock() | |
37 | return self |
|
39 | return self | |
38 |
|
40 | |||
39 | def __exit__(self, exc_type, exc_val, exc_tb): |
|
41 | def __exit__(self, exc_type, exc_val, exc_tb): | |
40 | if self._lock: |
|
42 | if self._lock: | |
41 | self._lock.__exit__(exc_type, exc_val, exc_tb) |
|
43 | self._lock.__exit__(exc_type, exc_val, exc_tb) | |
42 |
|
44 | |||
43 | def addbundle(self, bundleid, nodesctx): |
|
45 | def addbundle(self, bundleid, nodesctx): | |
44 | for node in nodesctx: |
|
46 | for node in nodesctx: | |
45 | nodepath = os.path.join(self._nodemap, node.hex()) |
|
47 | nodepath = os.path.join(self._nodemap, node.hex()) | |
46 | self._write(nodepath, bundleid) |
|
48 | self._write(nodepath, bundleid) | |
47 |
|
49 | |||
48 | def addbookmark(self, bookmark, node): |
|
50 | def addbookmark(self, bookmark, node): | |
49 | bookmarkpath = os.path.join(self._bookmarkmap, bookmark) |
|
51 | bookmarkpath = os.path.join(self._bookmarkmap, bookmark) | |
50 | self._write(bookmarkpath, node) |
|
52 | self._write(bookmarkpath, node) | |
51 |
|
53 | |||
52 | def addmanybookmarks(self, bookmarks): |
|
54 | def addmanybookmarks(self, bookmarks): | |
53 | for bookmark, node in bookmarks.items(): |
|
55 | for bookmark, node in bookmarks.items(): | |
54 | self.addbookmark(bookmark, node) |
|
56 | self.addbookmark(bookmark, node) | |
55 |
|
57 | |||
56 | def deletebookmarks(self, patterns): |
|
58 | def deletebookmarks(self, patterns): | |
57 | for pattern in patterns: |
|
59 | for pattern in patterns: | |
58 | for bookmark, _ in self._listbookmarks(pattern): |
|
60 | for bookmark, _ in self._listbookmarks(pattern): | |
59 | bookmarkpath = os.path.join(self._bookmarkmap, bookmark) |
|
61 | bookmarkpath = os.path.join(self._bookmarkmap, bookmark) | |
60 | self._delete(bookmarkpath) |
|
62 | self._delete(bookmarkpath) | |
61 |
|
63 | |||
62 | def getbundle(self, node): |
|
64 | def getbundle(self, node): | |
63 | nodepath = os.path.join(self._nodemap, node) |
|
65 | nodepath = os.path.join(self._nodemap, node) | |
64 | return self._read(nodepath) |
|
66 | return self._read(nodepath) | |
65 |
|
67 | |||
66 | def getnode(self, bookmark): |
|
68 | def getnode(self, bookmark): | |
67 | bookmarkpath = os.path.join(self._bookmarkmap, bookmark) |
|
69 | bookmarkpath = os.path.join(self._bookmarkmap, bookmark) | |
68 | return self._read(bookmarkpath) |
|
70 | return self._read(bookmarkpath) | |
69 |
|
71 | |||
70 | def getbookmarks(self, query): |
|
72 | def getbookmarks(self, query): | |
71 | return dict(self._listbookmarks(query)) |
|
73 | return dict(self._listbookmarks(query)) | |
72 |
|
74 | |||
73 | def saveoptionaljsonmetadata(self, node, jsonmetadata): |
|
75 | def saveoptionaljsonmetadata(self, node, jsonmetadata): | |
74 | vfs = self._repo.vfs |
|
76 | vfs = self._repo.vfs | |
75 | vfs.write(os.path.join(self._metadatamap, node), jsonmetadata) |
|
77 | vfs.write(os.path.join(self._metadatamap, node), jsonmetadata) | |
76 |
|
78 | |||
77 | def _listbookmarks(self, pattern): |
|
79 | def _listbookmarks(self, pattern): | |
78 | if pattern.endswith('*'): |
|
80 | if pattern.endswith('*'): | |
79 | pattern = 're:^' + pattern[:-1] + '.*' |
|
81 | pattern = 're:^' + pattern[:-1] + '.*' | |
80 | kind, pat, matcher = stringutil.stringmatcher(pattern) |
|
82 | kind, pat, matcher = stringutil.stringmatcher(pattern) | |
81 | prefixlen = len(self._bookmarkmap) + 1 |
|
83 | prefixlen = len(self._bookmarkmap) + 1 | |
82 | for dirpath, _, books in self._repo.vfs.walk(self._bookmarkmap): |
|
84 | for dirpath, _, books in self._repo.vfs.walk(self._bookmarkmap): | |
83 | for book in books: |
|
85 | for book in books: | |
84 | bookmark = os.path.join(dirpath, book)[prefixlen:] |
|
86 | bookmark = os.path.join(dirpath, book)[prefixlen:] | |
|
87 | bookmark = util.pconvert(bookmark) | |||
85 | if not matcher(bookmark): |
|
88 | if not matcher(bookmark): | |
86 | continue |
|
89 | continue | |
87 | yield bookmark, self._read(os.path.join(dirpath, book)) |
|
90 | yield bookmark, self._read(os.path.join(dirpath, book)) | |
88 |
|
91 | |||
89 | def _write(self, path, value): |
|
92 | def _write(self, path, value): | |
90 | vfs = self._repo.vfs |
|
93 | vfs = self._repo.vfs | |
91 | dirname = vfs.dirname(path) |
|
94 | dirname = vfs.dirname(path) | |
92 | if not vfs.exists(dirname): |
|
95 | if not vfs.exists(dirname): | |
93 | vfs.makedirs(dirname) |
|
96 | vfs.makedirs(dirname) | |
94 |
|
97 | |||
95 | vfs.write(path, value) |
|
98 | vfs.write(path, value) | |
96 |
|
99 | |||
97 | def _read(self, path): |
|
100 | def _read(self, path): | |
98 | vfs = self._repo.vfs |
|
101 | vfs = self._repo.vfs | |
99 | if not vfs.exists(path): |
|
102 | if not vfs.exists(path): | |
100 | return None |
|
103 | return None | |
101 | return vfs.read(path) |
|
104 | return vfs.read(path) | |
102 |
|
105 | |||
103 | def _delete(self, path): |
|
106 | def _delete(self, path): | |
104 | vfs = self._repo.vfs |
|
107 | vfs = self._repo.vfs | |
105 | if not vfs.exists(path): |
|
108 | if not vfs.exists(path): | |
106 | return |
|
109 | return | |
107 | return vfs.unlink(path) |
|
110 | return vfs.unlink(path) |
General Comments 0
You need to be logged in to leave comments.
Login now