add filter path arguments to clone library functions

Summary:
# Problem

The `eden clone` and `hg clone` command currently allow you to specify that you want to use FilteredFS, but they don't allow you to specify the filter to active after the clone completes. Instead, the user has to manually set the filter themselves by running `hg filteredfs enable {path_to_filter}`.

This is annoying for many reasons, and it prevents us from easily rolling out filters on Sandcastle/ODs.

# Solution

We should allow users to pass in the Filter they want to enable at clone time. This will allow them to skip the `hg filteredfs enable {path_to_filter}` step. Even better, we'll allow passing this filter via an Hg Config. That way we can easily enable FilteredFS + use a specific filter just by setting a config value.

# This diff

All of these should take an optional filter_path argument. This will be used by clone to set the active filter at clone time.

Reviewed By: jdelliot

Differential Revision: D53599527

fbshipit-source-id: c6573cd4886620a21471101e5cc2151e815de7f1
This commit is contained in:
Michael Cuevas 2024-02-12 13:40:38 -08:00 committed by Facebook GitHub Bot
parent f333975578
commit adf6f65063
2 changed files with 19 additions and 8 deletions

View File

@ -598,7 +598,11 @@ class EdenInstance(AbstractEdenInstance):
return mount_points
def clone(
self, checkout_config: CheckoutConfig, path: str, snapshot_id: str
self,
checkout_config: CheckoutConfig,
path: str,
snapshot_id: str,
filter_path: Optional[str] = None,
) -> None:
if path in self._get_directory_map():
raise Exception(
@ -620,7 +624,7 @@ Do you want to run `eden mount %s` instead?"""
checkout = EdenCheckout(self, Path(path), Path(client_dir))
if snapshot_id:
if checkout_config.scm_type == "filteredhg":
filtered_root_id = util.create_filtered_rootid(snapshot_id)
filtered_root_id = util.create_filtered_rootid(snapshot_id, filter_path)
checkout.save_snapshot(filtered_root_id)
else:
checkout.save_snapshot(snapshot_id.encode())
@ -638,7 +642,7 @@ Do you want to run `eden mount %s` instead?"""
with self.get_thrift_client_legacy() as client:
client.mount(mount_info)
self._post_clone_checkout_setup(checkout, snapshot_id)
self._post_clone_checkout_setup(checkout, snapshot_id, filter_path)
# Add mapping of mount path to client directory in config.json
self._add_path_to_directory_map(Path(path), os.path.basename(client_dir))
@ -731,7 +735,10 @@ Do you want to run `eden mount %s` instead?"""
raise
def _post_clone_checkout_setup(
self, checkout: "EdenCheckout", commit_id: str
self,
checkout: "EdenCheckout",
commit_id: str,
filter_path: Optional[str] = None,
) -> None:
# First, check to see if the post-clone setup has been run successfully
# before.
@ -740,7 +747,7 @@ Do you want to run `eden mount %s` instead?"""
if is_initial_mount and checkout.get_config().scm_type in HG_REPO_TYPES:
from . import hg_util
hg_util.setup_hg_dir(checkout, commit_id)
hg_util.setup_hg_dir(checkout, commit_id, filter_path)
clone_success_path.touch()

View File

@ -10,7 +10,7 @@ import binascii
import os
import typing
from pathlib import Path
from typing import BinaryIO, Dict, Tuple
from typing import BinaryIO, Dict, Optional, Tuple
import eden.dirstate
@ -27,7 +27,9 @@ portablefilenames = ignore
"""
def setup_hg_dir(checkout: EdenCheckout, commit_id: str) -> None:
def setup_hg_dir(
checkout: EdenCheckout, commit_id: str, filter_path: Optional[str] = None
) -> None:
checkout_hg_dir = checkout.hg_dot_path
try:
checkout_hg_dir.mkdir()
@ -70,7 +72,9 @@ def setup_hg_dir(checkout: EdenCheckout, commit_id: str) -> None:
# If the checkout is using FilteredFS, we need to write an initial
# .hg/sparse file that indicates no filter is active.
if checkout.get_config().scm_type == "filteredhg":
(checkout_hg_dir / "sparse").write_text("")
(checkout_hg_dir / "sparse").write_text(
filter_path if filter_path is not None else ""
)
def get_backing_hg_dir(checkout: EdenCheckout) -> Path: