mercurial/bookmarks.py
changeset 48033 62f325f9b347
parent 47188 353718f741a8
child 48242 4d2ab365699e
equal deleted inserted replaced
48032:12966768595a 48033:62f325f9b347
   678             node = None
   678             node = None
   679         books.append((bookmark, node))
   679         books.append((bookmark, node))
   680     return books
   680     return books
   681 
   681 
   682 
   682 
   683 def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()):
   683 def mirroring_remote(ui, repo, remotemarks):
   684     ui.debug(b"checking for updated bookmarks\n")
   684     """computes the bookmark changes that set the local bookmarks to
       
   685     remotemarks"""
       
   686     changed = []
       
   687     localmarks = repo._bookmarks
       
   688     for (b, id) in pycompat.iteritems(remotemarks):
       
   689         if id != localmarks.get(b, None) and id in repo:
       
   690             changed.append((b, id, ui.debug, _(b"updating bookmark %s\n") % b))
       
   691     for b in localmarks:
       
   692         if b not in remotemarks:
       
   693             changed.append(
       
   694                 (b, None, ui.debug, _(b"removing bookmark %s\n") % b)
       
   695             )
       
   696     return changed
       
   697 
       
   698 
       
   699 def merging_from_remote(ui, repo, remotemarks, path, explicit=()):
       
   700     """computes the bookmark changes that merge remote bookmarks into the
       
   701     local bookmarks, based on comparebookmarks"""
   685     localmarks = repo._bookmarks
   702     localmarks = repo._bookmarks
   686     (
   703     (
   687         addsrc,
   704         addsrc,
   688         adddst,
   705         adddst,
   689         advsrc,
   706         advsrc,
   750             explicit.remove(b)
   767             explicit.remove(b)
   751             ui.warn(
   768             ui.warn(
   752                 _(b"remote bookmark %s points to locally missing %s\n")
   769                 _(b"remote bookmark %s points to locally missing %s\n")
   753                 % (b, hex(scid)[:12])
   770                 % (b, hex(scid)[:12])
   754             )
   771             )
       
   772     return changed
       
   773 
       
   774 
       
   775 def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()):
       
   776     ui.debug(b"checking for updated bookmarks\n")
       
   777     if ui.configbool(b'bookmarks', b'mirror'):
       
   778         changed = mirroring_remote(ui, repo, remotemarks)
       
   779     else:
       
   780         changed = merging_from_remote(ui, repo, remotemarks, path, explicit)
   755 
   781 
   756     if changed:
   782     if changed:
   757         tr = trfunc()
   783         tr = trfunc()
   758         changes = []
   784         changes = []
   759         key = lambda t: (t[0], t[1] or b'')
   785         key = lambda t: (t[0], t[1] or b'')
   760         for b, node, writer, msg in sorted(changed, key=key):
   786         for b, node, writer, msg in sorted(changed, key=key):
   761             changes.append((b, node))
   787             changes.append((b, node))
   762             writer(msg)
   788             writer(msg)
   763         localmarks.applychanges(repo, tr, changes)
   789         repo._bookmarks.applychanges(repo, tr, changes)
   764 
   790 
   765 
   791 
   766 def incoming(ui, repo, peer):
   792 def incoming(ui, repo, peer):
   767     """Show bookmarks incoming from other to repo"""
   793     """Show bookmarks incoming from other to repo"""
   768     ui.status(_(b"searching for changed bookmarks\n"))
   794     ui.status(_(b"searching for changed bookmarks\n"))