comparison hgext/bookmarks.py @ 7250:352627bcafc3

bookmarks: Remove trailing space
author Joel Rosdahl <joel@rosdahl.net>
date Sat, 25 Oct 2008 16:29:58 +0200
parents 135003a470f3
children 444d88175e33
comparison
equal deleted inserted replaced
7241:421f4cbddd68 7250:352627bcafc3
21 import mercurial, mercurial.localrepo, mercurial.repair, os 21 import mercurial, mercurial.localrepo, mercurial.repair, os
22 22
23 23
24 def parse(repo): 24 def parse(repo):
25 '''Parse .hg/bookmarks file and return a dictionary 25 '''Parse .hg/bookmarks file and return a dictionary
26 26
27 Bookmarks are stored as {HASH}\s{NAME}\n (localtags format) 27 Bookmarks are stored as {HASH}\s{NAME}\n (localtags format)
28 values in the .hg/bookmarks file. 28 values in the .hg/bookmarks file.
29 They are read by the parse() method and returned as a dictionary with 29 They are read by the parse() method and returned as a dictionary with
30 name => hash values. 30 name => hash values.
31 31
32 The parsed dictionary is cached until a write() operation is done. 32 The parsed dictionary is cached until a write() operation is done.
33 ''' 33 '''
34 try: 34 try:
35 if repo._bookmarks: 35 if repo._bookmarks:
36 return repo._bookmarks 36 return repo._bookmarks
42 pass 42 pass
43 return repo._bookmarks 43 return repo._bookmarks
44 44
45 def write(repo, refs): 45 def write(repo, refs):
46 '''Write bookmarks 46 '''Write bookmarks
47 47
48 Write the given bookmark => hash dictionary to the .hg/bookmarks file 48 Write the given bookmark => hash dictionary to the .hg/bookmarks file
49 in a format equal to those of localtags. 49 in a format equal to those of localtags.
50 50
51 We also store a backup of the previous state in undo.bookmarks that 51 We also store a backup of the previous state in undo.bookmarks that
52 can be copied back on rollback. 52 can be copied back on rollback.
57 file.write("%s %s\n" % (hex(node), refspec)) 57 file.write("%s %s\n" % (hex(node), refspec))
58 file.close() 58 file.close()
59 59
60 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, move=None): 60 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, move=None):
61 '''mercurial bookmarks 61 '''mercurial bookmarks
62 62
63 Bookmarks are pointer to certain commits that move when commiting. 63 Bookmarks are pointer to certain commits that move when commiting.
64 Bookmarks are local. They can be renamed, copied and deleted. 64 Bookmarks are local. They can be renamed, copied and deleted.
65 It is possible to use bookmark names in 'hg merge' and 'hg update' to 65 It is possible to use bookmark names in 'hg merge' and 'hg update' to
66 update to a given bookmark. 66 update to a given bookmark.
67 67
68 You can use 'hg bookmark [NAME]' to set a bookmark on the current tip 68 You can use 'hg bookmark [NAME]' to set a bookmark on the current tip
69 with the given name. If you specify a second [NAME] the bookmark is 69 with the given name. If you specify a second [NAME] the bookmark is
70 set to the bookmark that has that name. You can also pass revision 70 set to the bookmark that has that name. You can also pass revision
71 identifiers to set bookmarks too. 71 identifiers to set bookmarks too.
72 ''' 72 '''
81 raise util.Abort(_("a bookmark of the same name already exists")) 81 raise util.Abort(_("a bookmark of the same name already exists"))
82 marks[mark] = marks[move] 82 marks[mark] = marks[move]
83 del marks[move] 83 del marks[move]
84 write(repo, marks) 84 write(repo, marks)
85 return 85 return
86 86
87 if delete: 87 if delete:
88 if mark == None: 88 if mark == None:
89 raise util.Abort(_("bookmark name required")) 89 raise util.Abort(_("bookmark name required"))
90 if mark not in marks: 90 if mark not in marks:
91 raise util.Abort(_("a bookmark of this name does not exists")) 91 raise util.Abort(_("a bookmark of this name does not exists"))
96 if mark != None: 96 if mark != None:
97 if mark.strip().count("\n") > 0: 97 if mark.strip().count("\n") > 0:
98 raise Exception("bookmark cannot contain newlines") 98 raise Exception("bookmark cannot contain newlines")
99 if mark in marks and not force: 99 if mark in marks and not force:
100 raise util.Abort(_("a bookmark of the same name already exists")) 100 raise util.Abort(_("a bookmark of the same name already exists"))
101 if ((mark in repo.branchtags() or mark == repo.dirstate.branch()) 101 if ((mark in repo.branchtags() or mark == repo.dirstate.branch())
102 and not force): 102 and not force):
103 raise util.Abort(_("a bookmark cannot have the name of an existing branch")) 103 raise util.Abort(_("a bookmark cannot have the name of an existing branch"))
104 if rev: 104 if rev:
105 marks[mark] = repo.lookup(rev) 105 marks[mark] = repo.lookup(rev)
106 else: 106 else:
160 160
161 class bookmark_repo(repo.__class__): 161 class bookmark_repo(repo.__class__):
162 def rollback(self): 162 def rollback(self):
163 if os.path.exists(self.join('undo.bookmarks')): 163 if os.path.exists(self.join('undo.bookmarks')):
164 util.rename(self.join('undo.bookmarks'), self.join('bookmarks')) 164 util.rename(self.join('undo.bookmarks'), self.join('bookmarks'))
165 return super(bookmark_repo, self).rollback() 165 return super(bookmark_repo, self).rollback()
166 166
167 def lookup(self, key): 167 def lookup(self, key):
168 if self._bookmarks is None: 168 if self._bookmarks is None:
169 self._bookmarks = parse(self) 169 self._bookmarks = parse(self)
170 if key in self._bookmarks: 170 if key in self._bookmarks: