Mercurial > hg
comparison mercurial/bookmarks.py @ 17818:5023027240a1
bookmarks: use scmutil.checknewlabel
Validation is pulled up into the commands module to avoid an import
cycle.
author | Kevin Bullock <kbullock@ringworld.org> |
---|---|
date | Wed, 17 Oct 2012 17:23:39 -0500 |
parents | 19388ba75a06 |
children | 46e1a4e24225 |
comparison
equal
deleted
inserted
replaced
17817:b17be267b59c | 17818:5023027240a1 |
---|---|
7 | 7 |
8 from mercurial.i18n import _ | 8 from mercurial.i18n import _ |
9 from mercurial.node import hex | 9 from mercurial.node import hex |
10 from mercurial import encoding, error, util, obsolete, phases | 10 from mercurial import encoding, error, util, obsolete, phases |
11 import errno, os | 11 import errno, os |
12 | |
13 def checkvalid(mark): | |
14 for c in (':', '\0', '\n', '\r'): | |
15 if c in mark: | |
16 raise util.Abort(_("bookmark '%s' contains illegal " | |
17 "character" % mark)) | |
18 if mark in ['tip', '.', 'null']: | |
19 raise util.Abort(_('the name \'%s\' is reserved') % mark) | |
20 | 12 |
21 def read(repo): | 13 def read(repo): |
22 '''Parse .hg/bookmarks file and return a dictionary | 14 '''Parse .hg/bookmarks file and return a dictionary |
23 | 15 |
24 Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values | 16 Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values |
79 ''' | 71 ''' |
80 refs = repo._bookmarks | 72 refs = repo._bookmarks |
81 | 73 |
82 if repo._bookmarkcurrent not in refs: | 74 if repo._bookmarkcurrent not in refs: |
83 setcurrent(repo, None) | 75 setcurrent(repo, None) |
84 for mark in refs.keys(): | |
85 checkvalid(mark) | |
86 | 76 |
87 wlock = repo.wlock() | 77 wlock = repo.wlock() |
88 try: | 78 try: |
89 | 79 |
90 file = repo.opener('bookmarks', 'w', atomictemp=True) | 80 file = repo.opener('bookmarks', 'w', atomictemp=True) |
111 if current == mark: | 101 if current == mark: |
112 return | 102 return |
113 | 103 |
114 if mark not in repo._bookmarks: | 104 if mark not in repo._bookmarks: |
115 mark = '' | 105 mark = '' |
116 checkvalid(mark) | |
117 | 106 |
118 wlock = repo.wlock() | 107 wlock = repo.wlock() |
119 try: | 108 try: |
120 file = repo.opener('bookmarks.current', 'w', atomictemp=True) | 109 file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
121 file.write(encoding.fromlocal(mark)) | 110 file.write(encoding.fromlocal(mark)) |