mercurial/bookmarks.py
changeset 42312 2b77183ac477
parent 42311 ec5bd3ab26bf
child 42325 526750cdd02d
equal deleted inserted replaced
42311:ec5bd3ab26bf 42312:2b77183ac477
   295     """
   295     """
   296     Get the active bookmark. We can have an active bookmark that updates
   296     Get the active bookmark. We can have an active bookmark that updates
   297     itself as we commit. This function returns the name of that bookmark.
   297     itself as we commit. This function returns the name of that bookmark.
   298     It is stored in .hg/bookmarks.current
   298     It is stored in .hg/bookmarks.current
   299     """
   299     """
   300     try:
   300     # No readline() in osutil.posixfile, reading everything is
   301         file = repo.vfs('bookmarks.current')
   301     # cheap.
   302     except IOError as inst:
   302     content = repo.vfs.tryread('bookmarks.current')
   303         if inst.errno != errno.ENOENT:
   303     mark = encoding.tolocal((content.splitlines() or [''])[0])
   304             raise
   304     if mark == '' or mark not in marks:
   305         return None
   305         mark = None
   306     try:
       
   307         # No readline() in osutil.posixfile, reading everything is
       
   308         # cheap.
       
   309         # Note that it's possible for readlines() here to raise
       
   310         # IOError, since we might be reading the active mark over
       
   311         # static-http which only tries to load the file when we try
       
   312         # to read from it.
       
   313         mark = encoding.tolocal((file.readlines() or [''])[0])
       
   314         if mark == '' or mark not in marks:
       
   315             mark = None
       
   316     except IOError as inst:
       
   317         if inst.errno != errno.ENOENT:
       
   318             raise
       
   319         return None
       
   320     finally:
       
   321         file.close()
       
   322     return mark
   306     return mark
   323 
   307 
   324 def activate(repo, mark):
   308 def activate(repo, mark):
   325     """
   309     """
   326     Set the given bookmark to be 'active', meaning that this bookmark will
   310     Set the given bookmark to be 'active', meaning that this bookmark will