store: use StoreEntry API instead of parsing filename in largefile
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 15 May 2023 09:01:02 +0200
changeset 50488 b4a9c8f18928
parent 50487 92611344aec2
child 50489 2eb7f0b5a499
store: use StoreEntry API instead of parsing filename in largefile This is more explicit and more robust.
hgext/largefiles/lfutil.py
hgext/largefiles/reposetup.py
--- a/hgext/largefiles/lfutil.py	Mon May 15 09:00:46 2023 +0200
+++ b/hgext/largefiles/lfutil.py	Mon May 15 09:01:02 2023 +0200
@@ -551,11 +551,10 @@
 
 def islfilesrepo(repo):
     '''Return true if the repo is a largefile repo.'''
-    if b'largefiles' in repo.requirements and any(
-        shortnameslash in entry.unencoded_path
-        for entry in repo.store.datafiles()
-    ):
-        return True
+    if b'largefiles' in repo.requirements:
+        for entry in repo.store.datafiles():
+            if entry.is_revlog and shortnameslash in entry.target_id:
+                return True
 
     return any(openlfdirstate(repo.ui, repo, False))
 
--- a/hgext/largefiles/reposetup.py	Mon May 15 09:00:46 2023 +0200
+++ b/hgext/largefiles/reposetup.py	Mon May 15 09:01:02 2023 +0200
@@ -457,12 +457,16 @@
 
     def checkrequireslfiles(ui, repo, **kwargs):
         with repo.lock():
-            if b'largefiles' not in repo.requirements and any(
-                lfutil.shortname + b'/' in entry.unencoded_path
-                for entry in repo.store.datafiles()
-            ):
-                repo.requirements.add(b'largefiles')
-                scmutil.writereporequirements(repo)
+            if b'largefiles' in repo.requirements:
+                return
+            marker = lfutil.shortnameslash
+            for entry in repo.store.datafiles():
+                # XXX note that this match is not rooted and can wrongly match
+                # directory ending with ".hglf"
+                if entry.is_revlog and marker in entry.target_id:
+                    repo.requirements.add(b'largefiles')
+                    scmutil.writereporequirements(repo)
+                    break
 
     ui.setconfig(
         b'hooks', b'changegroup.lfiles', checkrequireslfiles, b'largefiles'