mercurial/bookmarks.py
changeset 25100 d6e7ac651973
parent 25081 7642f119c2a2
child 25564 847fce27effc
equal deleted inserted replaced
25099:5e111215e38b 25100:d6e7ac651973
    20 
    20 
    21     This particular bmstore implementation stores bookmarks as
    21     This particular bmstore implementation stores bookmarks as
    22     {hash}\s{name}\n (the same format as localtags) in
    22     {hash}\s{name}\n (the same format as localtags) in
    23     .hg/bookmarks. The mapping is stored as {name: nodeid}.
    23     .hg/bookmarks. The mapping is stored as {name: nodeid}.
    24 
    24 
    25     This class does NOT handle the "current" bookmark state at this
    25     This class does NOT handle the "active" bookmark state at this
    26     time.
    26     time.
    27     """
    27     """
    28 
    28 
    29     def __init__(self, repo):
    29     def __init__(self, repo):
    30         dict.__init__(self)
    30         dict.__init__(self)
   135     The name is recorded in .hg/bookmarks.current
   135     The name is recorded in .hg/bookmarks.current
   136     """
   136     """
   137     if mark not in repo._bookmarks:
   137     if mark not in repo._bookmarks:
   138         raise AssertionError('bookmark %s does not exist!' % mark)
   138         raise AssertionError('bookmark %s does not exist!' % mark)
   139 
   139 
   140     current = repo._activebookmark
   140     active = repo._activebookmark
   141     if current == mark:
   141     if active == mark:
   142         return
   142         return
   143 
   143 
   144     wlock = repo.wlock()
   144     wlock = repo.wlock()
   145     try:
   145     try:
   146         file = repo.vfs('bookmarks.current', 'w', atomictemp=True)
   146         file = repo.vfs('bookmarks.current', 'w', atomictemp=True)
   198 def calculateupdate(ui, repo, checkout):
   198 def calculateupdate(ui, repo, checkout):
   199     '''Return a tuple (targetrev, movemarkfrom) indicating the rev to
   199     '''Return a tuple (targetrev, movemarkfrom) indicating the rev to
   200     check out and where to move the active bookmark from, if needed.'''
   200     check out and where to move the active bookmark from, if needed.'''
   201     movemarkfrom = None
   201     movemarkfrom = None
   202     if checkout is None:
   202     if checkout is None:
   203         curmark = repo._activebookmark
   203         activemark = repo._activebookmark
   204         if isactivewdirparent(repo):
   204         if isactivewdirparent(repo):
   205             movemarkfrom = repo['.'].node()
   205             movemarkfrom = repo['.'].node()
   206         elif curmark:
   206         elif activemark:
   207             ui.status(_("updating to active bookmark %s\n") % curmark)
   207             ui.status(_("updating to active bookmark %s\n") % activemark)
   208             checkout = curmark
   208             checkout = activemark
   209     return (checkout, movemarkfrom)
   209     return (checkout, movemarkfrom)
   210 
   210 
   211 def update(repo, parents, node):
   211 def update(repo, parents, node):
   212     deletefrom = parents
   212     deletefrom = parents
   213     marks = repo._bookmarks
   213     marks = repo._bookmarks
   214     update = False
   214     update = False
   215     cur = repo._activebookmark
   215     active = repo._activebookmark
   216     if not cur:
   216     if not active:
   217         return False
   217         return False
   218 
   218 
   219     if marks[cur] in parents:
   219     if marks[active] in parents:
   220         new = repo[node]
   220         new = repo[node]
   221         divs = [repo[b] for b in marks
   221         divs = [repo[b] for b in marks
   222                 if b.split('@', 1)[0] == cur.split('@', 1)[0]]
   222                 if b.split('@', 1)[0] == active.split('@', 1)[0]]
   223         anc = repo.changelog.ancestors([new.rev()])
   223         anc = repo.changelog.ancestors([new.rev()])
   224         deletefrom = [b.node() for b in divs if b.rev() in anc or b == new]
   224         deletefrom = [b.node() for b in divs if b.rev() in anc or b == new]
   225         if validdest(repo, repo[marks[cur]], new):
   225         if validdest(repo, repo[marks[active]], new):
   226             marks[cur] = new.node()
   226             marks[active] = new.node()
   227             update = True
   227             update = True
   228 
   228 
   229     if deletedivergent(repo, deletefrom, cur):
   229     if deletedivergent(repo, deletefrom, active):
   230         update = True
   230         update = True
   231 
   231 
   232     if update:
   232     if update:
   233         marks.write()
   233         marks.write()
   234     return update
   234     return update