##// END OF EJS Templates
bookmarks: cache reverse mapping (issue5868)...
Yuya Nishihara -
r37869:04ceb267 @26 default
parent child Browse files
Show More
@@ -60,6 +60,7 b' class bmstore(object):'
60 def __init__(self, repo):
60 def __init__(self, repo):
61 self._repo = repo
61 self._repo = repo
62 self._refmap = refmap = {} # refspec: node
62 self._refmap = refmap = {} # refspec: node
63 self._nodemap = nodemap = {} # node: sorted([refspec, ...])
63 self._clean = True
64 self._clean = True
64 self._aclean = True
65 self._aclean = True
65 nm = repo.changelog.nodemap
66 nm = repo.changelog.nodemap
@@ -76,6 +77,14 b' class bmstore(object):'
76 if node in nm:
77 if node in nm:
77 refspec = encoding.tolocal(refspec)
78 refspec = encoding.tolocal(refspec)
78 refmap[refspec] = node
79 refmap[refspec] = node
80 nrefs = nodemap.get(node)
81 if nrefs is None:
82 nodemap[node] = [refspec]
83 else:
84 nrefs.append(refspec)
85 if nrefs[-2] > refspec:
86 # bookmarks weren't sorted before 4.5
87 nrefs.sort()
79 except (TypeError, ValueError):
88 except (TypeError, ValueError):
80 # TypeError:
89 # TypeError:
81 # - bin(...)
90 # - bin(...)
@@ -118,6 +127,7 b' class bmstore(object):'
118 return self._refmap.keys()
127 return self._refmap.keys()
119
128
120 # TODO: maybe rename to allnodes()? but nodes would have to be deduplicated
129 # TODO: maybe rename to allnodes()? but nodes would have to be deduplicated
130 # could be self._nodemap.keys()
121 def values(self):
131 def values(self):
122 return self._refmap.values()
132 return self._refmap.values()
123
133
@@ -132,19 +142,29 b' class bmstore(object):'
132
142
133 def _set(self, mark, node):
143 def _set(self, mark, node):
134 self._clean = False
144 self._clean = False
145 if mark in self._refmap:
146 self._del(mark)
135 self._refmap[mark] = node
147 self._refmap[mark] = node
148 nrefs = self._nodemap.get(node)
149 if nrefs is None:
150 self._nodemap[node] = [mark]
151 else:
152 nrefs.append(mark)
153 nrefs.sort()
136
154
137 def _del(self, mark):
155 def _del(self, mark):
138 self._clean = False
156 self._clean = False
139 del self._refmap[mark]
157 node = self._refmap.pop(mark)
158 nrefs = self._nodemap[node]
159 if len(nrefs) == 1:
160 assert nrefs[0] == mark
161 del self._nodemap[node]
162 else:
163 nrefs.remove(mark)
140
164
141 def names(self, node):
165 def names(self, node):
142 """Return a sorted list of bookmarks pointing to the specified node"""
166 """Return a sorted list of bookmarks pointing to the specified node"""
143 marks = []
167 return self._nodemap.get(node, [])
144 for m, n in self._refmap.iteritems():
145 if n == node:
146 marks.append(m)
147 return sorted(marks)
148
168
149 def changectx(self, mark):
169 def changectx(self, mark):
150 node = self._refmap[mark]
170 node = self._refmap[mark]
@@ -68,6 +68,9 b' list bookmarks'
68 X 0:f7b1eb17ad24
68 X 0:f7b1eb17ad24
69 * X2 0:f7b1eb17ad24
69 * X2 0:f7b1eb17ad24
70 Y -1:000000000000
70 Y -1:000000000000
71 $ hg log -T '{bookmarks % "{rev} {bookmark}\n"}'
72 0 X
73 0 X2
71
74
72 $ echo b > b
75 $ echo b > b
73 $ hg add b
76 $ hg add b
@@ -299,6 +302,11 b' list bookmarks'
299 Y 2:db815d6d32e6
302 Y 2:db815d6d32e6
300 Z 0:f7b1eb17ad24
303 Z 0:f7b1eb17ad24
301 * x y 2:db815d6d32e6
304 * x y 2:db815d6d32e6
305 $ hg log -T '{bookmarks % "{rev} {bookmark}\n"}'
306 2 Y
307 2 x y
308 1 X2
309 0 Z
302
310
303 look up stripped bookmark name
311 look up stripped bookmark name
304
312
@@ -445,6 +453,11 b' list bookmarks'
445 Y 2:db815d6d32e6
453 Y 2:db815d6d32e6
446 * Z 2:db815d6d32e6
454 * Z 2:db815d6d32e6
447 x y 2:db815d6d32e6
455 x y 2:db815d6d32e6
456 $ hg log -T '{bookmarks % "{rev} {bookmark}\n"}'
457 2 Y
458 2 Z
459 2 x y
460 1 X2
448
461
449 revision but no bookmark name
462 revision but no bookmark name
450
463
General Comments 0
You need to be logged in to leave comments. Login now