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