##// END OF EJS Templates
bookmarks: move read methods to core
Matt Mackall -
r13351:6c5368cd default
parent child Browse files
Show More
@@ -167,39 +167,11 b' def reposetup(ui, repo):'
167
167
168 @util.propertycache
168 @util.propertycache
169 def _bookmarks(self):
169 def _bookmarks(self):
170 '''Parse .hg/bookmarks file and return a dictionary
170 return bookmarks.read(self)
171
172 Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values
173 in the .hg/bookmarks file.
174 Read the file and return a (name=>nodeid) dictionary
175 '''
176 try:
177 bookmarks = {}
178 for line in self.opener('bookmarks'):
179 sha, refspec = line.strip().split(' ', 1)
180 refspec = encoding.tolocal(refspec)
181 bookmarks[refspec] = self.changelog.lookup(sha)
182 except:
183 pass
184 return bookmarks
185
171
186 @util.propertycache
172 @util.propertycache
187 def _bookmarkcurrent(self):
173 def _bookmarkcurrent(self):
188 '''Get the current bookmark
174 return bookmarks.readcurrent(self)
189
190 If we use gittishsh branches we have a current bookmark that
191 we are on. This function returns the name of the bookmark. It
192 is stored in .hg/bookmarks.current
193 '''
194 mark = None
195 if os.path.exists(self.join('bookmarks.current')):
196 file = self.opener('bookmarks.current')
197 # No readline() in posixfile_nt, reading everything is cheap
198 mark = (file.readlines() or [''])[0]
199 if mark == '':
200 mark = None
201 file.close()
202 return mark
203
175
204 def rollback(self, dryrun=False):
176 def rollback(self, dryrun=False):
205 if os.path.exists(self.join('undo.bookmarks')):
177 if os.path.exists(self.join('undo.bookmarks')):
@@ -10,6 +10,40 b' from mercurial.node import nullid, nullr'
10 from mercurial import encoding
10 from mercurial import encoding
11 import os
11 import os
12
12
13 def read(repo):
14 '''Parse .hg/bookmarks file and return a dictionary
15
16 Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values
17 in the .hg/bookmarks file.
18 Read the file and return a (name=>nodeid) dictionary
19 '''
20 try:
21 bookmarks = {}
22 for line in repo.opener('bookmarks'):
23 sha, refspec = line.strip().split(' ', 1)
24 refspec = encoding.tolocal(refspec)
25 bookmarks[refspec] = repo.changelog.lookup(sha)
26 except:
27 pass
28 return bookmarks
29
30 def readcurrent(repo):
31 '''Get the current bookmark
32
33 If we use gittishsh branches we have a current bookmark that
34 we are on. This function returns the name of the bookmark. It
35 is stored in .hg/bookmarks.current
36 '''
37 mark = None
38 if os.path.exists(repo.join('bookmarks.current')):
39 file = repo.opener('bookmarks.current')
40 # No readline() in posixfile_nt, reading everything is cheap
41 mark = (file.readlines() or [''])[0]
42 if mark == '':
43 mark = None
44 file.close()
45 return mark
46
13 def write(repo):
47 def write(repo):
14 '''Write bookmarks
48 '''Write bookmarks
15
49
General Comments 0
You need to be logged in to leave comments. Login now