Mercurial > hg
comparison hgext/rebase.py @ 26029:563ea14c62d4 stable
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.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 11 Aug 2015 16:45:11 -0700 |
parents | 328739ea70c3 |
children | 927c0d84e09f |
comparison
equal
deleted
inserted
replaced
26028:6fbe35588433 | 26029:563ea14c62d4 |
---|---|
1024 | 1024 |
1025 | 1025 |
1026 def pullrebase(orig, ui, repo, *args, **opts): | 1026 def pullrebase(orig, ui, repo, *args, **opts): |
1027 'Call rebase after pull if the latter has been invoked with --rebase' | 1027 'Call rebase after pull if the latter has been invoked with --rebase' |
1028 if opts.get('rebase'): | 1028 if opts.get('rebase'): |
1029 if opts.get('update'): | 1029 wlock = lock = None |
1030 del opts['update'] | |
1031 ui.debug('--update and --rebase are not compatible, ignoring ' | |
1032 'the update flag\n') | |
1033 | |
1034 movemarkfrom = repo['.'].node() | |
1035 revsprepull = len(repo) | |
1036 origpostincoming = commands.postincoming | |
1037 def _dummy(*args, **kwargs): | |
1038 pass | |
1039 commands.postincoming = _dummy | |
1040 try: | 1030 try: |
1041 orig(ui, repo, *args, **opts) | 1031 wlock = repo.wlock() |
1032 lock = repo.lock() | |
1033 if opts.get('update'): | |
1034 del opts['update'] | |
1035 ui.debug('--update and --rebase are not compatible, ignoring ' | |
1036 'the update flag\n') | |
1037 | |
1038 movemarkfrom = repo['.'].node() | |
1039 revsprepull = len(repo) | |
1040 origpostincoming = commands.postincoming | |
1041 def _dummy(*args, **kwargs): | |
1042 pass | |
1043 commands.postincoming = _dummy | |
1044 try: | |
1045 orig(ui, repo, *args, **opts) | |
1046 finally: | |
1047 commands.postincoming = origpostincoming | |
1048 revspostpull = len(repo) | |
1049 if revspostpull > revsprepull: | |
1050 # --rev option from pull conflict with rebase own --rev | |
1051 # dropping it | |
1052 if 'rev' in opts: | |
1053 del opts['rev'] | |
1054 # positional argument from pull conflicts with rebase's own | |
1055 # --source. | |
1056 if 'source' in opts: | |
1057 del opts['source'] | |
1058 rebase(ui, repo, **opts) | |
1059 branch = repo[None].branch() | |
1060 dest = repo[branch].rev() | |
1061 if dest != repo['.'].rev(): | |
1062 # there was nothing to rebase we force an update | |
1063 hg.update(repo, dest) | |
1064 if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): | |
1065 ui.status(_("updating bookmark %s\n") | |
1066 % repo._activebookmark) | |
1042 finally: | 1067 finally: |
1043 commands.postincoming = origpostincoming | 1068 release(lock, wlock) |
1044 revspostpull = len(repo) | |
1045 if revspostpull > revsprepull: | |
1046 # --rev option from pull conflict with rebase own --rev | |
1047 # dropping it | |
1048 if 'rev' in opts: | |
1049 del opts['rev'] | |
1050 # positional argument from pull conflicts with rebase's own | |
1051 # --source. | |
1052 if 'source' in opts: | |
1053 del opts['source'] | |
1054 rebase(ui, repo, **opts) | |
1055 branch = repo[None].branch() | |
1056 dest = repo[branch].rev() | |
1057 if dest != repo['.'].rev(): | |
1058 # there was nothing to rebase we force an update | |
1059 hg.update(repo, dest) | |
1060 if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): | |
1061 ui.status(_("updating bookmark %s\n") | |
1062 % repo._activebookmark) | |
1063 else: | 1069 else: |
1064 if opts.get('tool'): | 1070 if opts.get('tool'): |
1065 raise util.Abort(_('--tool can only be used with --rebase')) | 1071 raise util.Abort(_('--tool can only be used with --rebase')) |
1066 orig(ui, repo, *args, **opts) | 1072 orig(ui, repo, *args, **opts) |
1067 | 1073 |