mercurial/bookmarks.py
changeset 27186 34d26e22a2b0
parent 27185 d52765831086
child 27187 d9dcc5c09d77
equal deleted inserted replaced
27185:d52765831086 27186:34d26e22a2b0
    20     lock as lockmod,
    20     lock as lockmod,
    21     obsolete,
    21     obsolete,
    22     util,
    22     util,
    23 )
    23 )
    24 
    24 
       
    25 def _getbkfile(repo):
       
    26     """Hook so that extensions that mess with the store can hook bm storage.
       
    27 
       
    28     For core, this just handles wether we should see pending
       
    29     bookmarks or the committed ones. Other extensions (like share)
       
    30     may need to tweak this behavior further.
       
    31     """
       
    32     bkfile = None
       
    33     if 'HG_PENDING' in os.environ:
       
    34         try:
       
    35             bkfile = repo.vfs('bookmarks.pending')
       
    36         except IOError as inst:
       
    37             if inst.errno != errno.ENOENT:
       
    38                 raise
       
    39     if bkfile is None:
       
    40         bkfile = repo.vfs('bookmarks')
       
    41     return bkfile
       
    42 
       
    43 
    25 class bmstore(dict):
    44 class bmstore(dict):
    26     """Storage for bookmarks.
    45     """Storage for bookmarks.
    27 
    46 
    28     This object should do all bookmark reads and writes, so that it's
    47     This object should do all bookmark reads and writes, so that it's
    29     fairly simple to replace the storage underlying bookmarks without
    48     fairly simple to replace the storage underlying bookmarks without
    39 
    58 
    40     def __init__(self, repo):
    59     def __init__(self, repo):
    41         dict.__init__(self)
    60         dict.__init__(self)
    42         self._repo = repo
    61         self._repo = repo
    43         try:
    62         try:
    44             bkfile = self.getbkfile(repo)
    63             bkfile = _getbkfile(repo)
    45             for line in bkfile:
    64             for line in bkfile:
    46                 line = line.strip()
    65                 line = line.strip()
    47                 if not line:
    66                 if not line:
    48                     continue
    67                     continue
    49                 if ' ' not in line:
    68                 if ' ' not in line:
    57                 except LookupError:
    76                 except LookupError:
    58                     pass
    77                     pass
    59         except IOError as inst:
    78         except IOError as inst:
    60             if inst.errno != errno.ENOENT:
    79             if inst.errno != errno.ENOENT:
    61                 raise
    80                 raise
    62 
       
    63     def getbkfile(self, repo):
       
    64         """Hook so that extensions that mess with the store can hook bm storage.
       
    65 
       
    66         For core, this just handles wether we should see pending
       
    67         bookmarks or the committed ones. Other extensions (like share)
       
    68         may need to tweak this behavior further.
       
    69         """
       
    70         bkfile = None
       
    71         if 'HG_PENDING' in os.environ:
       
    72             try:
       
    73                 bkfile = repo.vfs('bookmarks.pending')
       
    74             except IOError as inst:
       
    75                 if inst.errno != errno.ENOENT:
       
    76                     raise
       
    77         if bkfile is None:
       
    78             bkfile = repo.vfs('bookmarks')
       
    79         return bkfile
       
    80 
    81 
    81     def recordchange(self, tr):
    82     def recordchange(self, tr):
    82         """record that bookmarks have been changed in a transaction
    83         """record that bookmarks have been changed in a transaction
    83 
    84 
    84         The transaction is then responsible for updating the file content."""
    85         The transaction is then responsible for updating the file content."""