changeset 48663:bf424fe4f814

lfs: take lock before writing requirements With `share-safe`, we will also write file in the store, so we take the store lock before writing requirements. Differential Revision: https://phab.mercurial-scm.org/D11991
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 07 Jan 2022 17:33:27 +0100
parents d7135d8e8998
children 497c2655c71e
files hgext/lfs/__init__.py
diffstat 1 files changed, 21 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/__init__.py	Tue Jan 11 06:32:18 2022 +0100
+++ b/hgext/lfs/__init__.py	Fri Jan 07 17:33:27 2022 +0100
@@ -257,25 +257,28 @@
     if b'lfs' not in repo.requirements:
 
         def checkrequireslfs(ui, repo, **kwargs):
-            if b'lfs' in repo.requirements:
-                return 0
+            with repo.lock():
+                if b'lfs' in repo.requirements:
+                    return 0
 
-            last = kwargs.get('node_last')
-            if last:
-                s = repo.set(b'%n:%n', bin(kwargs['node']), bin(last))
-            else:
-                s = repo.set(b'%n', bin(kwargs['node']))
-            match = repo._storenarrowmatch
-            for ctx in s:
-                # TODO: is there a way to just walk the files in the commit?
-                if any(
-                    ctx[f].islfs() for f in ctx.files() if f in ctx and match(f)
-                ):
-                    repo.requirements.add(b'lfs')
-                    repo.features.add(repository.REPO_FEATURE_LFS)
-                    scmutil.writereporequirements(repo)
-                    repo.prepushoutgoinghooks.add(b'lfs', wrapper.prepush)
-                    break
+                last = kwargs.get('node_last')
+                if last:
+                    s = repo.set(b'%n:%n', bin(kwargs['node']), bin(last))
+                else:
+                    s = repo.set(b'%n', bin(kwargs['node']))
+                match = repo._storenarrowmatch
+                for ctx in s:
+                    # TODO: is there a way to just walk the files in the commit?
+                    if any(
+                        ctx[f].islfs()
+                        for f in ctx.files()
+                        if f in ctx and match(f)
+                    ):
+                        repo.requirements.add(b'lfs')
+                        repo.features.add(repository.REPO_FEATURE_LFS)
+                        scmutil.writereporequirements(repo)
+                        repo.prepushoutgoinghooks.add(b'lfs', wrapper.prepush)
+                        break
 
         ui.setconfig(b'hooks', b'commit.lfs', checkrequireslfs, b'lfs')
         ui.setconfig(