Mercurial > hg
comparison mercurial/bookmarks.py @ 15887:12dea4d998ec
bookmarks: primarily use repo lock, not wlock
Bookmarks are repository data, not working directory data. Only the current
bookmark is working directory data.
Some lock shuffling is required to avoid lockout between the initial mock lock
and locking of the localrepo instance that is created after copying.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Fri, 13 Jan 2012 02:30:43 +0100 |
parents | 013688350c7d |
children | 60cb4f381a78 |
comparison
equal
deleted
inserted
replaced
15886:a5917346c72e | 15887:12dea4d998ec |
---|---|
82 for mark in refs.keys(): | 82 for mark in refs.keys(): |
83 if not valid(mark): | 83 if not valid(mark): |
84 raise util.Abort(_("bookmark '%s' contains illegal " | 84 raise util.Abort(_("bookmark '%s' contains illegal " |
85 "character" % mark)) | 85 "character" % mark)) |
86 | 86 |
87 wlock = repo.wlock() | 87 lock = repo.lock() |
88 try: | 88 try: |
89 | 89 |
90 file = repo.opener('bookmarks', 'w', atomictemp=True) | 90 file = repo.opener('bookmarks', 'w', atomictemp=True) |
91 for refspec, node in refs.iteritems(): | 91 for refspec, node in refs.iteritems(): |
92 file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec))) | 92 file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec))) |
97 os.utime(repo.sjoin('00changelog.i'), None) | 97 os.utime(repo.sjoin('00changelog.i'), None) |
98 except OSError: | 98 except OSError: |
99 pass | 99 pass |
100 | 100 |
101 finally: | 101 finally: |
102 wlock.release() | 102 lock.release() |
103 | 103 |
104 def setcurrent(repo, mark): | 104 def setcurrent(repo, mark): |
105 '''Set the name of the bookmark that we are currently on | 105 '''Set the name of the bookmark that we are currently on |
106 | 106 |
107 Set the name of the bookmark that we are on (hg update <bookmark>). | 107 Set the name of the bookmark that we are on (hg update <bookmark>). |
115 mark = '' | 115 mark = '' |
116 if not valid(mark): | 116 if not valid(mark): |
117 raise util.Abort(_("bookmark '%s' contains illegal " | 117 raise util.Abort(_("bookmark '%s' contains illegal " |
118 "character" % mark)) | 118 "character" % mark)) |
119 | 119 |
120 wlock = repo.wlock() | 120 lock = repo.lock() |
121 try: | 121 try: |
122 file = repo.opener('bookmarks.current', 'w', atomictemp=True) | 122 file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
123 file.write(encoding.fromlocal(mark)) | 123 file.write(encoding.fromlocal(mark)) |
124 file.close() | 124 file.close() |
125 finally: | 125 finally: |
126 wlock.release() | 126 lock.release() |
127 repo._bookmarkcurrent = mark | 127 repo._bookmarkcurrent = mark |
128 | 128 |
129 def updatecurrentbookmark(repo, oldnode, curbranch): | 129 def updatecurrentbookmark(repo, oldnode, curbranch): |
130 try: | 130 try: |
131 return update(repo, oldnode, repo.branchtags()[curbranch]) | 131 return update(repo, oldnode, repo.branchtags()[curbranch]) |
160 if '@' not in k and not k.endswith('@'): | 160 if '@' not in k and not k.endswith('@'): |
161 d[k] = hex(v) | 161 d[k] = hex(v) |
162 return d | 162 return d |
163 | 163 |
164 def pushbookmark(repo, key, old, new): | 164 def pushbookmark(repo, key, old, new): |
165 w = repo.wlock() | 165 lock = repo.lock() |
166 try: | 166 try: |
167 marks = repo._bookmarks | 167 marks = repo._bookmarks |
168 if hex(marks.get(key, '')) != old: | 168 if hex(marks.get(key, '')) != old: |
169 return False | 169 return False |
170 if new == '': | 170 if new == '': |
174 return False | 174 return False |
175 marks[key] = repo[new].node() | 175 marks[key] = repo[new].node() |
176 write(repo) | 176 write(repo) |
177 return True | 177 return True |
178 finally: | 178 finally: |
179 w.release() | 179 lock.release() |
180 | 180 |
181 def updatefromremote(ui, repo, remote, path): | 181 def updatefromremote(ui, repo, remote, path): |
182 ui.debug("checking for updated bookmarks\n") | 182 ui.debug("checking for updated bookmarks\n") |
183 rb = remote.listkeys('bookmarks') | 183 rb = remote.listkeys('bookmarks') |
184 changed = False | 184 changed = False |