changeset 50512:a32d739b0ffb

store: make `walk` return an entry for phase if requested so Instead of having dedicated code in the streamclone code, we should have the store deal with advertising the data it contains.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 21 May 2023 02:15:04 +0200
parents c847a3e82056
children 5a62d56e3955
files hgext/remotefilelog/remotefilelogserver.py mercurial/store.py mercurial/streamclone.py
diffstat 3 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/remotefilelog/remotefilelogserver.py	Mon May 22 10:20:24 2023 +0100
+++ b/hgext/remotefilelog/remotefilelogserver.py	Sun May 21 02:15:04 2023 +0200
@@ -145,7 +145,7 @@
     )
 
     # don't clone filelogs to shallow clients
-    def _walkstreamfiles(orig, repo, matcher=None):
+    def _walkstreamfiles(orig, repo, matcher=None, phase=False):
         if state.shallowremote:
             # if we are shallow ourselves, stream our local commits
             if shallowutil.isenabled(repo):
@@ -200,7 +200,7 @@
                 _(b"Cannot clone from a shallow repo to a full repo.")
             )
         else:
-            for x in orig(repo, matcher):
+            for x in orig(repo, matcher, phase=phase):
                 yield x
 
     extensions.wrapfunction(streamclone, b'_walkstreamfiles', _walkstreamfiles)
--- a/mercurial/store.py	Mon May 22 10:20:24 2023 +0100
+++ b/mercurial/store.py	Sun May 21 02:15:04 2023 +0200
@@ -685,7 +685,7 @@
                     details=file_details,
                 )
 
-    def top_entries(self) -> Generator[BaseStoreEntry, None, None]:
+    def top_entries(self, phase=False) -> Generator[BaseStoreEntry, None, None]:
         files = reversed(self._walk(b'', False))
 
         changelogs = collections.defaultdict(dict)
@@ -725,11 +725,18 @@
                     target_id=b'',
                     details=file_details,
                 )
+        if phase and self.vfs.exists(b'phaseroots'):
+            yield SimpleStoreEntry(
+                entry_path=b'phaseroots',
+                is_volatile=True,
+            )
 
-    def walk(self, matcher=None) -> Generator[BaseStoreEntry, None, None]:
+    def walk(
+        self, matcher=None, phase=False
+    ) -> Generator[BaseStoreEntry, None, None]:
         """return files related to data storage (ie: revlogs)
 
-        yields (file_type, unencoded, size)
+        yields instance from BaseStoreEntry subclasses
 
         if a matcher is passed, storage files of only those tracked paths
         are passed with matches the matcher
@@ -737,7 +744,7 @@
         # yield data files first
         for x in self.data_entries(matcher):
             yield x
-        for x in self.top_entries():
+        for x in self.top_entries(phase=phase):
             yield x
 
     def copylist(self):
--- a/mercurial/streamclone.py	Mon May 22 10:20:24 2023 +0100
+++ b/mercurial/streamclone.py	Sun May 21 02:15:04 2023 +0200
@@ -241,8 +241,8 @@
 
 
 # This is it's own function so extensions can override it.
-def _walkstreamfiles(repo, matcher=None):
-    return repo.store.walk(matcher)
+def _walkstreamfiles(repo, matcher=None, phase=False):
+    return repo.store.walk(matcher, phase=phase)
 
 
 def generatev1(repo):
@@ -679,7 +679,8 @@
     if includes or excludes:
         matcher = narrowspec.match(repo.root, includes, excludes)
 
-    for entry in _walkstreamfiles(repo, matcher):
+    phase = not repo.publishing()
+    for entry in _walkstreamfiles(repo, matcher, phase=phase):
         for f in entry.files():
             file_size = f.file_size(repo.store.vfs)
             if file_size:
@@ -688,10 +689,6 @@
                     ft = _filefull
                 entries.append((_srcstore, f.unencoded_path, ft, file_size))
                 totalfilesize += file_size
-    for name in _walkstreamfullstorefiles(repo):
-        if repo.svfs.exists(name):
-            totalfilesize += repo.svfs.lstat(name).st_size
-            entries.append((_srcstore, name, _filefull, None))
     if includeobsmarkers and repo.svfs.exists(b'obsstore'):
         totalfilesize += repo.svfs.lstat(b'obsstore').st_size
         entries.append((_srcstore, b'obsstore', _filefull, None))