Mercurial > public > mercurial-scm > hg-stable
diff mercurial/bookmarks.py @ 48055:62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
For backups for instance. Merging bookmarks is not a useful behavior
in that case.
Differential Revision: https://phab.mercurial-scm.org/D11490
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Wed, 22 Sep 2021 17:14:54 -0400 |
parents | 353718f741a8 |
children | 4d2ab365699e |
line wrap: on
line diff
--- a/mercurial/bookmarks.py Thu Sep 23 09:42:20 2021 -0700 +++ b/mercurial/bookmarks.py Wed Sep 22 17:14:54 2021 -0400 @@ -680,8 +680,25 @@ return books -def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()): - ui.debug(b"checking for updated bookmarks\n") +def mirroring_remote(ui, repo, remotemarks): + """computes the bookmark changes that set the local bookmarks to + remotemarks""" + changed = [] + localmarks = repo._bookmarks + for (b, id) in pycompat.iteritems(remotemarks): + if id != localmarks.get(b, None) and id in repo: + changed.append((b, id, ui.debug, _(b"updating bookmark %s\n") % b)) + for b in localmarks: + if b not in remotemarks: + changed.append( + (b, None, ui.debug, _(b"removing bookmark %s\n") % b) + ) + return changed + + +def merging_from_remote(ui, repo, remotemarks, path, explicit=()): + """computes the bookmark changes that merge remote bookmarks into the + local bookmarks, based on comparebookmarks""" localmarks = repo._bookmarks ( addsrc, @@ -752,6 +769,15 @@ _(b"remote bookmark %s points to locally missing %s\n") % (b, hex(scid)[:12]) ) + return changed + + +def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()): + ui.debug(b"checking for updated bookmarks\n") + if ui.configbool(b'bookmarks', b'mirror'): + changed = mirroring_remote(ui, repo, remotemarks) + else: + changed = merging_from_remote(ui, repo, remotemarks, path, explicit) if changed: tr = trfunc() @@ -760,7 +786,7 @@ for b, node, writer, msg in sorted(changed, key=key): changes.append((b, node)) writer(msg) - localmarks.applychanges(repo, tr, changes) + repo._bookmarks.applychanges(repo, tr, changes) def incoming(ui, repo, peer):