Mercurial > hg
comparison mercurial/bookmarks.py @ 13425:0fe36c347c00
bookmarks: forbid \0 \r \n : in bookmark names (BC)
We restrict : to 1. make it easer to convert bookmarks to git branches,
2. use : later for a syntax to push a local bookmark to a remote bookmark
of a different name. \0, \n, \r are fobbidden they are used to separate
bookmarks in the bookmark file.
This change breaks backward compatbility as ':' was an allowed character in
previous versions.
author | David Soria Parra <dsp@php.net> |
---|---|
date | Wed, 16 Feb 2011 18:36:45 +0100 |
parents | 5431b3f3e52e |
children | c631ac076375 |
comparison
equal
deleted
inserted
replaced
13424:08f9c587141f | 13425:0fe36c347c00 |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
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 | |
13 def valid(mark): | |
14 for c in (':', '\0', '\n', '\r'): | |
15 if c in mark: | |
16 return False | |
17 return True | |
12 | 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 |
16 Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values | 22 Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values |
61 bms = '' | 67 bms = '' |
62 repo.opener('undo.bookmarks', 'w').write(bms) | 68 repo.opener('undo.bookmarks', 'w').write(bms) |
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))) |
71 file.rename() | 83 file.rename() |
72 | 84 |
95 if (mark and mark not in refs and | 107 if (mark and mark not in refs and |
96 current and refs[current] == repo.changectx('.').node()): | 108 current and refs[current] == repo.changectx('.').node()): |
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) |
103 file.write(mark) | 119 file.write(mark) |
104 file.rename() | 120 file.rename() |