Mercurial > hg
comparison mercurial/bookmarks.py @ 27685:9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
When reading over static http, the file isn't actually opened until
the readlines() call, so we have to check for ENOENT IOErrors here
too. This is necessary so that we can use the bmstore everywhere for
managing the active bookmark, which will be true in the next change.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 01 Dec 2015 13:08:05 -0500 |
parents | 38024b75241a |
children | dad6404ccddb |
comparison
equal
deleted
inserted
replaced
27684:e9857fbfd072 | 27685:9fbae70faf65 |
---|---|
163 except IOError as inst: | 163 except IOError as inst: |
164 if inst.errno != errno.ENOENT: | 164 if inst.errno != errno.ENOENT: |
165 raise | 165 raise |
166 return None | 166 return None |
167 try: | 167 try: |
168 # No readline() in osutil.posixfile, reading everything is cheap | 168 # No readline() in osutil.posixfile, reading everything is |
169 # cheap. | |
170 # Note that it's possible for readlines() here to raise | |
171 # IOError, since we might be reading the active mark over | |
172 # static-http which only tries to load the file when we try | |
173 # to read from it. | |
169 mark = encoding.tolocal((file.readlines() or [''])[0]) | 174 mark = encoding.tolocal((file.readlines() or [''])[0]) |
170 if mark == '' or mark not in repo._bookmarks: | 175 if mark == '' or mark not in repo._bookmarks: |
171 mark = None | 176 mark = None |
177 except IOError as inst: | |
178 if inst.errno != errno.ENOENT: | |
179 raise | |
180 return None | |
172 finally: | 181 finally: |
173 file.close() | 182 file.close() |
174 return mark | 183 return mark |
175 | 184 |
176 def activate(repo, mark): | 185 def activate(repo, mark): |