Show More
@@ -7,8 +7,8 | |||
|
7 | 7 | |
|
8 | 8 | from mercurial.i18n import _ |
|
9 | 9 | from mercurial.node import nullid, nullrev, bin, hex, short |
|
10 | from mercurial import encoding, util | |
|
11 | import os | |
|
10 | from mercurial import encoding, error, util | |
|
11 | import errno, os | |
|
12 | 12 | |
|
13 | 13 | def valid(mark): |
|
14 | 14 | for c in (':', '\0', '\n', '\r'): |
@@ -23,14 +23,18 def read(repo): | |||
|
23 | 23 | in the .hg/bookmarks file. |
|
24 | 24 | Read the file and return a (name=>nodeid) dictionary |
|
25 | 25 | ''' |
|
26 | bookmarks = {} | |
|
26 | 27 | try: |
|
27 | bookmarks = {} | |
|
28 | 28 | for line in repo.opener('bookmarks'): |
|
29 | 29 | sha, refspec = line.strip().split(' ', 1) |
|
30 | 30 | refspec = encoding.tolocal(refspec) |
|
31 | try: | |
|
31 | 32 | bookmarks[refspec] = repo.changelog.lookup(sha) |
|
32 | except IOError: | |
|
33 | except error.RepoLookupError: | |
|
33 | 34 | pass |
|
35 | except IOError, inst: | |
|
36 | if inst.errno != errno.ENOENT: | |
|
37 | raise | |
|
34 | 38 | return bookmarks |
|
35 | 39 | |
|
36 | 40 | def readcurrent(repo): |
@@ -41,12 +45,18 def readcurrent(repo): | |||
|
41 | 45 | is stored in .hg/bookmarks.current |
|
42 | 46 | ''' |
|
43 | 47 | mark = None |
|
44 | if os.path.exists(repo.join('bookmarks.current')): | |
|
48 | try: | |
|
45 | 49 | file = repo.opener('bookmarks.current') |
|
50 | except IOError, inst: | |
|
51 | if inst.errno != errno.ENOENT: | |
|
52 | raise | |
|
53 | return None | |
|
54 | try: | |
|
46 | 55 | # No readline() in posixfile_nt, reading everything is cheap |
|
47 | 56 | mark = encoding.tolocal((file.readlines() or [''])[0]) |
|
48 | 57 | if mark == '' or mark not in repo._bookmarks: |
|
49 | 58 | mark = None |
|
59 | finally: | |
|
50 | 60 | file.close() |
|
51 | 61 | return mark |
|
52 | 62 |
General Comments 0
You need to be logged in to leave comments.
Login now