Show More
@@ -7,9 +7,15 b'' | |||||
7 |
|
7 | |||
8 | from mercurial.i18n import _ |
|
8 | from mercurial.i18n import _ | |
9 | from mercurial.node import nullid, nullrev, bin, hex, short |
|
9 | from mercurial.node import nullid, nullrev, bin, hex, short | |
10 | from mercurial import encoding |
|
10 | from mercurial import encoding, util | |
11 | import os |
|
11 | import os | |
12 |
|
12 | |||
|
13 | def valid(mark): | |||
|
14 | for c in (':', '\0', '\n', '\r'): | |||
|
15 | if c in mark: | |||
|
16 | return False | |||
|
17 | return True | |||
|
18 | ||||
13 | def read(repo): |
|
19 | def read(repo): | |
14 | '''Parse .hg/bookmarks file and return a dictionary |
|
20 | '''Parse .hg/bookmarks file and return a dictionary | |
15 |
|
21 | |||
@@ -63,8 +69,14 b' def write(repo):' | |||||
63 |
|
69 | |||
64 | if repo._bookmarkcurrent not in refs: |
|
70 | if repo._bookmarkcurrent not in refs: | |
65 | setcurrent(repo, None) |
|
71 | setcurrent(repo, None) | |
|
72 | for mark in refs.keys(): | |||
|
73 | if not valid(mark): | |||
|
74 | raise util.Abort(_("bookmark '%s' contains illegal " | |||
|
75 | "character" % mark)) | |||
|
76 | ||||
66 | wlock = repo.wlock() |
|
77 | wlock = repo.wlock() | |
67 | try: |
|
78 | try: | |
|
79 | ||||
68 | file = repo.opener('bookmarks', 'w', atomictemp=True) |
|
80 | file = repo.opener('bookmarks', 'w', atomictemp=True) | |
69 | for refspec, node in refs.iteritems(): |
|
81 | for refspec, node in refs.iteritems(): | |
70 | file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec))) |
|
82 | file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec))) | |
@@ -97,6 +109,10 b' def setcurrent(repo, mark):' | |||||
97 | return |
|
109 | return | |
98 | if mark not in refs: |
|
110 | if mark not in refs: | |
99 | mark = '' |
|
111 | mark = '' | |
|
112 | if not valid(mark): | |||
|
113 | raise util.Abort(_("bookmark '%s' contains illegal " | |||
|
114 | "character" % mark)) | |||
|
115 | ||||
100 | wlock = repo.wlock() |
|
116 | wlock = repo.wlock() | |
101 | try: |
|
117 | try: | |
102 | file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
|
118 | file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
@@ -212,3 +212,10 b' bookmark name with whitespace only' | |||||
212 | $ hg bookmark ' ' |
|
212 | $ hg bookmark ' ' | |
213 | abort: bookmark names cannot consist entirely of whitespace |
|
213 | abort: bookmark names cannot consist entirely of whitespace | |
214 | [255] |
|
214 | [255] | |
|
215 | ||||
|
216 | invalid bookmark | |||
|
217 | ||||
|
218 | $ hg bookmark 'foo:bar' | |||
|
219 | abort: bookmark 'foo:bar' contains illegal character | |||
|
220 | [255] | |||
|
221 |
General Comments 0
You need to be logged in to leave comments.
Login now