Show More
@@ -33,24 +33,6 b' from mercurial.node import nullid, nullr' | |||||
33 | from mercurial import util, commands, localrepo, repair, extensions |
|
33 | from mercurial import util, commands, localrepo, repair, extensions | |
34 | import os |
|
34 | import os | |
35 |
|
35 | |||
36 | def parse(repo): |
|
|||
37 | '''Parse .hg/bookmarks file and return a dictionary |
|
|||
38 |
|
||||
39 | Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values |
|
|||
40 | in the .hg/bookmarks file. They are read by the parse() method and |
|
|||
41 | returned as a dictionary with name => hash values. |
|
|||
42 |
|
||||
43 | The parsed dictionary is cached until a write() operation is done. |
|
|||
44 | ''' |
|
|||
45 | try: |
|
|||
46 | bookmarks = {} |
|
|||
47 | for line in repo.opener('bookmarks'): |
|
|||
48 | sha, refspec = line.strip().split(' ', 1) |
|
|||
49 | bookmarks[refspec] = repo.lookup(sha) |
|
|||
50 | except: |
|
|||
51 | pass |
|
|||
52 | return bookmarks |
|
|||
53 |
|
||||
54 | def write(repo): |
|
36 | def write(repo): | |
55 | '''Write bookmarks |
|
37 | '''Write bookmarks | |
56 |
|
38 | |||
@@ -74,23 +56,6 b' def write(repo):' | |||||
74 | finally: |
|
56 | finally: | |
75 | wlock.release() |
|
57 | wlock.release() | |
76 |
|
58 | |||
77 | def current(repo): |
|
|||
78 | '''Get the current bookmark |
|
|||
79 |
|
||||
80 | If we use gittishsh branches we have a current bookmark that |
|
|||
81 | we are on. This function returns the name of the bookmark. It |
|
|||
82 | is stored in .hg/bookmarks.current |
|
|||
83 | ''' |
|
|||
84 | mark = None |
|
|||
85 | if os.path.exists(repo.join('bookmarks.current')): |
|
|||
86 | file = repo.opener('bookmarks.current') |
|
|||
87 | # No readline() in posixfile_nt, reading everything is cheap |
|
|||
88 | mark = (file.readlines() or [''])[0] |
|
|||
89 | if mark == '': |
|
|||
90 | mark = None |
|
|||
91 | file.close() |
|
|||
92 | return mark |
|
|||
93 |
|
||||
94 | def setcurrent(repo, mark): |
|
59 | def setcurrent(repo, mark): | |
95 | '''Set the name of the bookmark that we are currently on |
|
60 | '''Set the name of the bookmark that we are currently on | |
96 |
|
61 | |||
@@ -236,11 +201,38 b' def reposetup(ui, repo):' | |||||
236 |
|
201 | |||
237 | @util.propertycache |
|
202 | @util.propertycache | |
238 | def _bookmarks(self): |
|
203 | def _bookmarks(self): | |
239 | return parse(self) |
|
204 | '''Parse .hg/bookmarks file and return a dictionary | |
|
205 | ||||
|
206 | Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values | |||
|
207 | in the .hg/bookmarks file. They are read returned as a dictionary | |||
|
208 | with name => hash values. | |||
|
209 | ''' | |||
|
210 | try: | |||
|
211 | bookmarks = {} | |||
|
212 | for line in self.opener('bookmarks'): | |||
|
213 | sha, refspec = line.strip().split(' ', 1) | |||
|
214 | bookmarks[refspec] = super(bookmark_repo, self).lookup(sha) | |||
|
215 | except: | |||
|
216 | pass | |||
|
217 | return bookmarks | |||
240 |
|
218 | |||
241 | @util.propertycache |
|
219 | @util.propertycache | |
242 | def _bookmarkcurrent(self): |
|
220 | def _bookmarkcurrent(self): | |
243 |
|
|
221 | '''Get the current bookmark | |
|
222 | ||||
|
223 | If we use gittishsh branches we have a current bookmark that | |||
|
224 | we are on. This function returns the name of the bookmark. It | |||
|
225 | is stored in .hg/bookmarks.current | |||
|
226 | ''' | |||
|
227 | mark = None | |||
|
228 | if os.path.exists(self.join('bookmarks.current')): | |||
|
229 | file = self.opener('bookmarks.current') | |||
|
230 | # No readline() in posixfile_nt, reading everything is cheap | |||
|
231 | mark = (file.readlines() or [''])[0] | |||
|
232 | if mark == '': | |||
|
233 | mark = None | |||
|
234 | file.close() | |||
|
235 | return mark | |||
244 |
|
236 | |||
245 | def rollback(self): |
|
237 | def rollback(self): | |
246 | if os.path.exists(self.join('undo.bookmarks')): |
|
238 | if os.path.exists(self.join('undo.bookmarks')): |
General Comments 0
You need to be logged in to leave comments.
Login now