[Commented On] D11991: lfs: take lock before writing requirements

baymax (Baymax, Your Personal Patch-care Companion) phabricator at mercurial-scm.org
Mon Jan 24 16:21:25 UTC 2022


baymax added a comment.
baymax updated this revision to Diff 31814.


  ✅ refresh by Heptapod after a successful CI run (🐙 💚)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11991?vs=31800&id=31814

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11991/new/

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

AFFECTED FILES
  hgext/lfs/__init__.py

CHANGE DETAILS

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -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(



To: marmoute, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220124/617412dc/attachment-0002.html>


More information about the Mercurial-patches mailing list