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