##// END OF EJS Templates
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet -
r10107:c03f4674 default
parent child Browse files
Show More
@@ -63,7 +63,7 b' def write(repo):'
63 refs = repo._bookmarks
63 refs = repo._bookmarks
64 if os.path.exists(repo.join('bookmarks')):
64 if os.path.exists(repo.join('bookmarks')):
65 util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
65 util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
66 if current(repo) not in refs:
66 if repo._bookmarkcurrent not in refs:
67 setcurrent(repo, None)
67 setcurrent(repo, None)
68 wlock = repo.wlock()
68 wlock = repo.wlock()
69 try:
69 try:
@@ -81,8 +81,6 b' def current(repo):'
81 we are on. This function returns the name of the bookmark. It
81 we are on. This function returns the name of the bookmark. It
82 is stored in .hg/bookmarks.current
82 is stored in .hg/bookmarks.current
83 '''
83 '''
84 if repo._bookmarkcurrent:
85 return repo._bookmarkcurrent
86 mark = None
84 mark = None
87 if os.path.exists(repo.join('bookmarks.current')):
85 if os.path.exists(repo.join('bookmarks.current')):
88 file = repo.opener('bookmarks.current')
86 file = repo.opener('bookmarks.current')
@@ -91,7 +89,6 b' def current(repo):'
91 if mark == '':
89 if mark == '':
92 mark = None
90 mark = None
93 file.close()
91 file.close()
94 repo._bookmarkcurrent = mark
95 return mark
92 return mark
96
93
97 def setcurrent(repo, mark):
94 def setcurrent(repo, mark):
@@ -100,14 +97,15 b' def setcurrent(repo, mark):'
100 Set the name of the bookmark that we are on (hg update <bookmark>).
97 Set the name of the bookmark that we are on (hg update <bookmark>).
101 The name is recorded in .hg/bookmarks.current
98 The name is recorded in .hg/bookmarks.current
102 '''
99 '''
103 if current(repo) == mark:
100 current = repo._bookmarkcurrent
101 if current == mark:
104 return
102 return
105
103
106 refs = repo._bookmarks
104 refs = repo._bookmarks
107
105
108 # do not update if we do update to a rev equal to the current bookmark
106 # do not update if we do update to a rev equal to the current bookmark
109 if (mark and mark not in refs and
107 if (mark and mark not in refs and
110 current(repo) and refs[current(repo)] == repo.changectx('.').node()):
108 current and refs[current] == repo.changectx('.').node()):
111 return
109 return
112 if mark not in refs:
110 if mark not in refs:
113 mark = ''
111 mark = ''
@@ -146,7 +144,7 b' def bookmark(ui, repo, mark=None, rev=No'
146 raise util.Abort(_("new bookmark name required"))
144 raise util.Abort(_("new bookmark name required"))
147 marks[mark] = marks[rename]
145 marks[mark] = marks[rename]
148 del marks[rename]
146 del marks[rename]
149 if current(repo) == rename:
147 if repo._bookmarkcurrent == rename:
150 setcurrent(repo, mark)
148 setcurrent(repo, mark)
151 write(repo)
149 write(repo)
152 return
150 return
@@ -156,7 +154,7 b' def bookmark(ui, repo, mark=None, rev=No'
156 raise util.Abort(_("bookmark name required"))
154 raise util.Abort(_("bookmark name required"))
157 if mark not in marks:
155 if mark not in marks:
158 raise util.Abort(_("a bookmark of this name does not exist"))
156 raise util.Abort(_("a bookmark of this name does not exist"))
159 if mark == current(repo):
157 if mark == repo._bookmarkcurrent:
160 setcurrent(repo, None)
158 setcurrent(repo, None)
161 del marks[mark]
159 del marks[mark]
162 write(repo)
160 write(repo)
@@ -188,7 +186,8 b' def bookmark(ui, repo, mark=None, rev=No'
188 else:
186 else:
189 for bmark, n in marks.iteritems():
187 for bmark, n in marks.iteritems():
190 if ui.configbool('bookmarks', 'track.current'):
188 if ui.configbool('bookmarks', 'track.current'):
191 prefix = (bmark == current(repo) and n == cur) and '*' or ' '
189 current = repo._bookmarkcurrent
190 prefix = (bmark == current and n == cur) and '*' or ' '
192 else:
191 else:
193 prefix = (n == cur) and '*' or ' '
192 prefix = (n == cur) and '*' or ' '
194
193
@@ -233,16 +232,16 b' def reposetup(ui, repo):'
233 if not repo.local():
232 if not repo.local():
234 return
233 return
235
234
236 # init a bookmark cache as otherwise we would get a infinite reading
237 # in lookup()
238 repo._bookmarkcurrent = None
239
240 class bookmark_repo(repo.__class__):
235 class bookmark_repo(repo.__class__):
241
236
242 @util.propertycache
237 @util.propertycache
243 def _bookmarks(self):
238 def _bookmarks(self):
244 return parse(self)
239 return parse(self)
245
240
241 @util.propertycache
242 def _bookmarkcurrent(self):
243 return current(self)
244
246 def rollback(self):
245 def rollback(self):
247 if os.path.exists(self.join('undo.bookmarks')):
246 if os.path.exists(self.join('undo.bookmarks')):
248 util.rename(self.join('undo.bookmarks'), self.join('bookmarks'))
247 util.rename(self.join('undo.bookmarks'), self.join('bookmarks'))
@@ -267,7 +266,7 b' def reposetup(ui, repo):'
267 marks = self._bookmarks
266 marks = self._bookmarks
268 update = False
267 update = False
269 if ui.configbool('bookmarks', 'track.current'):
268 if ui.configbool('bookmarks', 'track.current'):
270 mark = current(self)
269 mark = self._bookmarkcurrent
271 if mark and marks[mark] in parents:
270 if mark and marks[mark] in parents:
272 marks[mark] = node
271 marks[mark] = node
273 update = True
272 update = True
@@ -294,7 +293,7 b' def reposetup(ui, repo):'
294 marks = self._bookmarks
293 marks = self._bookmarks
295 update = False
294 update = False
296 if ui.configbool('bookmarks', 'track.current'):
295 if ui.configbool('bookmarks', 'track.current'):
297 mark = current(self)
296 mark = self._bookmarkcurrent
298 if mark and marks[mark] in parents:
297 if mark and marks[mark] in parents:
299 marks[mark] = node
298 marks[mark] = node
300 update = True
299 update = True
General Comments 0
You need to be logged in to leave comments. Login now