Patchwork D9822: upgrade: re-read current requirements after taking lock

login
register
mail settings
Submitter phabricator
Date Jan. 18, 2021, 3:19 p.m.
Message ID <differential-rev-PHID-DREV-dzebyoooqbj3wlpnoqkk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48133/
State Superseded
Headers show

Comments

phabricator - Jan. 18, 2021, 3:19 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Since we are writing to repository, it's better to re-read after taking the
  lock.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9822

AFFECTED FILES
  mercurial/upgrade.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -254,6 +254,19 @@ 
     current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
     try:
         wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
+        # some process might change the requirement in between, re-read
+        # and update current_requirements
+        locked_requirements = localrepo._readrequires(hgvfs, True)
+        if locked_requirements >= current_requirements and current_requirements >= locked_requirements:
+            removed = current_requirements - locked_requirements
+            # update current_requirements in place because it's passed
+            # as reference
+            current_requirements -= removed
+            current_requirements |= locked_requirements
+            diffrequires = current_requirements - store_requirements
+            # add share-safe requirement as it will mark the share as share-safe
+            diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
+            current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
         scmutil.writerequires(hgvfs, diffrequires)
         ui.warn(_(b'repository upgraded to use share-safe mode\n'))
     except error.LockError as e:
@@ -290,6 +303,17 @@ 
 
     try:
         wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
+        # some process might change the requirement in between, re-read
+        # and update current_requirements
+        locked_requirements = localrepo._readrequires(hgvfs, True)
+        if locked_requirements >= current_requirements and current_requirements >= locked_requirements:
+            removed = current_requirements - locked_requirements
+            # update current_requirements in place because it's passed
+            # as reference
+            current_requirements -= removed
+            current_requirements |= locked_requirements
+            current_requirements |= source_requirements
+            current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT)
         scmutil.writerequires(hgvfs, current_requirements)
         ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
     except error.LockError as e: