# HG changeset patch # User Pierre-Yves David # Date 1439336711 25200 # Node ID 563ea14c62d4017c578c038279e9d1df05029363 # Parent 6fbe355884332557a217648217c2e295f5c12bb7 rebase: lock the repo during the full rebase operation Running `hg pull --rebase` would move bookmarks without any repository locking. So we now lock the repository. For good measure and avoiding sneaky race conditions, we lock the repository for the whole operation. There is no code change besides the indentation. diff -r 6fbe35588433 -r 563ea14c62d4 hgext/rebase.py --- a/hgext/rebase.py Tue Aug 11 16:26:12 2015 -0700 +++ b/hgext/rebase.py Tue Aug 11 16:45:11 2015 -0700 @@ -1026,40 +1026,46 @@ def pullrebase(orig, ui, repo, *args, **opts): 'Call rebase after pull if the latter has been invoked with --rebase' if opts.get('rebase'): - if opts.get('update'): - del opts['update'] - ui.debug('--update and --rebase are not compatible, ignoring ' - 'the update flag\n') + wlock = lock = None + try: + wlock = repo.wlock() + lock = repo.lock() + if opts.get('update'): + del opts['update'] + ui.debug('--update and --rebase are not compatible, ignoring ' + 'the update flag\n') - movemarkfrom = repo['.'].node() - revsprepull = len(repo) - origpostincoming = commands.postincoming - def _dummy(*args, **kwargs): - pass - commands.postincoming = _dummy - try: - orig(ui, repo, *args, **opts) + movemarkfrom = repo['.'].node() + revsprepull = len(repo) + origpostincoming = commands.postincoming + def _dummy(*args, **kwargs): + pass + commands.postincoming = _dummy + try: + orig(ui, repo, *args, **opts) + finally: + commands.postincoming = origpostincoming + revspostpull = len(repo) + if revspostpull > revsprepull: + # --rev option from pull conflict with rebase own --rev + # dropping it + if 'rev' in opts: + del opts['rev'] + # positional argument from pull conflicts with rebase's own + # --source. + if 'source' in opts: + del opts['source'] + rebase(ui, repo, **opts) + branch = repo[None].branch() + dest = repo[branch].rev() + if dest != repo['.'].rev(): + # there was nothing to rebase we force an update + hg.update(repo, dest) + if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): + ui.status(_("updating bookmark %s\n") + % repo._activebookmark) finally: - commands.postincoming = origpostincoming - revspostpull = len(repo) - if revspostpull > revsprepull: - # --rev option from pull conflict with rebase own --rev - # dropping it - if 'rev' in opts: - del opts['rev'] - # positional argument from pull conflicts with rebase's own - # --source. - if 'source' in opts: - del opts['source'] - rebase(ui, repo, **opts) - branch = repo[None].branch() - dest = repo[branch].rev() - if dest != repo['.'].rev(): - # there was nothing to rebase we force an update - hg.update(repo, dest) - if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): - ui.status(_("updating bookmark %s\n") - % repo._activebookmark) + release(lock, wlock) else: if opts.get('tool'): raise util.Abort(_('--tool can only be used with --rebase'))