Show More
@@ -43,7 +43,7 b' def _getbkfile(repo):' | |||
|
43 | 43 | fp, pending = txnutil.trypending(repo.root, repo.vfs, 'bookmarks') |
|
44 | 44 | return fp |
|
45 | 45 | |
|
46 |
class bmstore( |
|
|
46 | class bmstore(object): | |
|
47 | 47 | """Storage for bookmarks. |
|
48 | 48 | |
|
49 | 49 | This object should do all bookmark-related reads and writes, so |
@@ -58,13 +58,12 b' class bmstore(dict):' | |||
|
58 | 58 | """ |
|
59 | 59 | |
|
60 | 60 | def __init__(self, repo): |
|
61 | dict.__init__(self) | |
|
62 | 61 | self._repo = repo |
|
62 | self._refmap = refmap = {} # refspec: node | |
|
63 | 63 | self._clean = True |
|
64 | 64 | self._aclean = True |
|
65 | 65 | nm = repo.changelog.nodemap |
|
66 | 66 | tonode = bin # force local lookup |
|
67 | setitem = dict.__setitem__ | |
|
68 | 67 | try: |
|
69 | 68 | with _getbkfile(repo) as bkfile: |
|
70 | 69 | for line in bkfile: |
@@ -76,7 +75,7 b' class bmstore(dict):' | |||
|
76 | 75 | node = tonode(sha) |
|
77 | 76 | if node in nm: |
|
78 | 77 | refspec = encoding.tolocal(refspec) |
|
79 |
|
|
|
78 | refmap[refspec] = node | |
|
80 | 79 | except (TypeError, ValueError): |
|
81 | 80 | # TypeError: |
|
82 | 81 | # - bin(...) |
@@ -96,38 +95,59 b' class bmstore(dict):' | |||
|
96 | 95 | |
|
97 | 96 | @active.setter |
|
98 | 97 | def active(self, mark): |
|
99 | if mark is not None and mark not in self: | |
|
98 | if mark is not None and mark not in self._refmap: | |
|
100 | 99 | raise AssertionError('bookmark %s does not exist!' % mark) |
|
101 | 100 | |
|
102 | 101 | self._active = mark |
|
103 | 102 | self._aclean = False |
|
104 | 103 | |
|
105 |
def __ |
|
|
106 | raise error.ProgrammingError("use 'bookmarks.applychanges' instead") | |
|
104 | def __len__(self): | |
|
105 | return len(self._refmap) | |
|
106 | ||
|
107 | def __iter__(self): | |
|
108 | return iter(self._refmap) | |
|
109 | ||
|
110 | def iteritems(self): | |
|
111 | return self._refmap.iteritems() | |
|
112 | ||
|
113 | def items(self): | |
|
114 | return self._refmap.items() | |
|
115 | ||
|
116 | # TODO: maybe rename to allnames()? | |
|
117 | def keys(self): | |
|
118 | return self._refmap.keys() | |
|
119 | ||
|
120 | # TODO: maybe rename to allnodes()? but nodes would have to be deduplicated | |
|
121 | def values(self): | |
|
122 | return self._refmap.values() | |
|
123 | ||
|
124 | def __contains__(self, mark): | |
|
125 | return mark in self._refmap | |
|
126 | ||
|
127 | def __getitem__(self, mark): | |
|
128 | return self._refmap[mark] | |
|
129 | ||
|
130 | def get(self, mark, default=None): | |
|
131 | return self._refmap.get(mark, default) | |
|
107 | 132 | |
|
108 | 133 | def _set(self, key, value): |
|
109 | 134 | self._clean = False |
|
110 | return dict.__setitem__(self, key, value) | |
|
111 | ||
|
112 | def __delitem__(self, key): | |
|
113 | raise error.ProgrammingError("use 'bookmarks.applychanges' instead") | |
|
135 | self._refmap[key] = value | |
|
114 | 136 | |
|
115 | 137 | def _del(self, key): |
|
116 | 138 | self._clean = False |
|
117 | return dict.__delitem__(self, key) | |
|
118 | ||
|
119 | def update(self, *others): | |
|
120 | raise error.ProgrammingError("use 'bookmarks.applychanges' instead") | |
|
139 | del self._refmap[key] | |
|
121 | 140 | |
|
122 | 141 | def changectx(self, mark): |
|
123 |
|
|
|
142 | node = self._refmap[mark] | |
|
143 | return self._repo[node] | |
|
124 | 144 | |
|
125 | 145 | def applychanges(self, repo, tr, changes): |
|
126 | 146 | """Apply a list of changes to bookmarks |
|
127 | 147 | """ |
|
128 | 148 | bmchanges = tr.changes.get('bookmarks') |
|
129 | 149 | for name, node in changes: |
|
130 | old = self.get(name) | |
|
150 | old = self._refmap.get(name) | |
|
131 | 151 | if node is None: |
|
132 | 152 | self._del(name) |
|
133 | 153 | else: |
@@ -151,7 +171,7 b' class bmstore(dict):' | |||
|
151 | 171 | def _writerepo(self, repo): |
|
152 | 172 | """Factored out for extensibility""" |
|
153 | 173 | rbm = repo._bookmarks |
|
154 | if rbm.active not in self: | |
|
174 | if rbm.active not in self._refmap: | |
|
155 | 175 | rbm.active = None |
|
156 | 176 | rbm._writeactive() |
|
157 | 177 | |
@@ -182,7 +202,7 b' class bmstore(dict):' | |||
|
182 | 202 | self._aclean = True |
|
183 | 203 | |
|
184 | 204 | def _write(self, fp): |
|
185 | for name, node in sorted(self.iteritems()): | |
|
205 | for name, node in sorted(self._refmap.iteritems()): | |
|
186 | 206 | fp.write("%s %s\n" % (hex(node), encoding.fromlocal(name))) |
|
187 | 207 | self._clean = True |
|
188 | 208 | self._repo.invalidatevolatilesets() |
@@ -208,15 +228,15 b' class bmstore(dict):' | |||
|
208 | 228 | If divergent bookmark are to be deleted, they will be returned as list. |
|
209 | 229 | """ |
|
210 | 230 | cur = self._repo['.'].node() |
|
211 | if mark in self and not force: | |
|
231 | if mark in self._refmap and not force: | |
|
212 | 232 | if target: |
|
213 | if self[mark] == target and target == cur: | |
|
233 | if self._refmap[mark] == target and target == cur: | |
|
214 | 234 | # re-activating a bookmark |
|
215 | 235 | return [] |
|
216 | 236 | rev = self._repo[target].rev() |
|
217 | 237 | anc = self._repo.changelog.ancestors([rev]) |
|
218 | 238 | bmctx = self.changectx(mark) |
|
219 | divs = [self[b] for b in self | |
|
239 | divs = [self._refmap[b] for b in self._refmap | |
|
220 | 240 | if b.split('@', 1)[0] == mark.split('@', 1)[0]] |
|
221 | 241 | |
|
222 | 242 | # allow resolving a single divergent bookmark even if moving |
General Comments 0
You need to be logged in to leave comments.
Login now