Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
916c3f1
perf(install): fetch monorepo subdirectory deps as pin trees + exact …
danielmeppiel Nov 24, 2026
0e9436d
docs(changelog): #5377 fragment
danielmeppiel Nov 24, 2026
361b9a3
fix(install): sparse fetch checks cone directory names, case parity, …
danielmeppiel Nov 24, 2026
da2ba7d
test(install): sparse cone and attribute differential cells live unde…
danielmeppiel Nov 24, 2026
34f13bb
test(install): the moved sparse cells are component tests
danielmeppiel Nov 24, 2026
4a42f17
test(install): sparse cells assert observable outcomes (git's on-disk…
danielmeppiel Nov 24, 2026
0511910
fix(install): key the verdict record on APM_NO_INPROCESS_SPARSE
danielmeppiel Nov 24, 2026
46e3a6a
style(install): rewrap the verdict env comment to keep verdict_record…
danielmeppiel Nov 24, 2026
b855a25
Merge branch 'main' of github.com:microsoft/apm into perf/inprocess-s…
danielmeppiel Nov 24, 2026
b7c8f7b
perf(install): sparse fetch carries A' (#5353) on the caps GET and bo…
danielmeppiel Nov 24, 2026
c828b3e
fix(install): the sparse fetch drops the credential on every path
danielmeppiel Nov 24, 2026
f9a40cf
Merge branch 'main' of github.com:microsoft/apm into perf/inprocess-s…
danielmeppiel Nov 24, 2026
9ae2a68
fix(install): the sparse caps GET verifies through _requests_verify (…
danielmeppiel Nov 24, 2026
6d19e85
fix(install): sparse caps GET streams under a cap; cone attributes re…
danielmeppiel Nov 25, 2026
a81928f
fix(install): cone attributes refuse any whitespace git does not spli…
danielmeppiel Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5377.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `apm install` fetches github.com monorepo subdirectory dependencies as pinned trees plus only the needed files: about 2x less CPU on Linux and macOS. (#5377)
4 changes: 2 additions & 2 deletions src/apm_cli/cache/cached_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ def validate_cached_links(repo: Path, paths: list[str] | None, env: dict[str, st
"""Validate the tracked links of a cached checkout, running Git inertly."""
from .checkout_verify import inprocess_verified

if not paths and inprocess_verified(repo, use="links"):
return # Written in-process, which refuses every link.
if inprocess_verified(repo, use="links"):
return # Written in-process, which refuses every link (in the cone, for a sparse landing).
from ..utils.git_sparse import validate_materialized_symlinks

validate_materialized_symlinks(
Expand Down
14 changes: 14 additions & 0 deletions src/apm_cli/cache/checkout_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ def state(self, path: str) -> dict[str, object] | None:
return state


class _FoldedAttributes(_Attributes):
"""``core.ignorecase`` matching: every pattern compiled case-insensitively (W3d U3)."""

def _load(self, directory: str) -> None:
fresh = directory not in self._rules
super()._load(directory)
rules = self._rules.get(directory)
if fresh and rules is not None:
self._rules[directory] = [
(anchored, re.compile(regex.pattern, re.IGNORECASE), attrs)
for anchored, regex, attrs in rules
]


def _accepted(attributes: _Attributes, attribute_path: str, blob: bytes) -> tuple[bytes, ...]:
"""The byte strings a pinned checkout may write for *blob* at *attribute_path*."""
state = attributes.state(attribute_path)
Expand Down
54 changes: 49 additions & 5 deletions src/apm_cli/cache/git_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import re
import subprocess
import time
from collections.abc import Callable
from pathlib import Path

from ..utils.atomic_io import atomic_write_text
Expand Down Expand Up @@ -463,7 +464,7 @@ def get_checkout(
url, ref, locked_sha=locked_sha, env=env, sparse_paths=sparse_paths
)
sha = checkout.parent.name
if not sparse_paths and inprocess_verified(checkout, sha, use="verify"):
if inprocess_verified(checkout, sha, use="verify"):
# The fresh landing: every byte was hashed to its object id as written.
return checkout
verify_env = git_subprocess_env(env)
Expand Down Expand Up @@ -561,6 +562,10 @@ def _get_checkout(
landed = self._inprocess_checkout(url, shard_key, sha, env=env)
if landed is not None:
return landed
if use_partial and not self._refresh:
landed = self._inprocess_sparse_checkout(url, shard_key, sha, sparse_paths, env=env)
if landed is not None:
return landed
self._ensure_bare_repo(url, shard_key, sha, env=env, partial=use_partial)
return self._create_checkout(
url,
Expand All @@ -571,19 +576,58 @@ def _get_checkout(
promisor_url=url if use_partial else None,
)

def _inprocess_sparse_checkout(
self,
url: str,
shard_key: str,
sha: str,
sparse_paths: list[str],
*,
env: dict[str, str] | None,
) -> Path | None:
"""Land a sparse checkout fetched in-process (pin trees + the cone's blobs), or ``None``."""
from .inprocess_fetch import fetch_sparse_worktree

cones = tuple(sorted({p.strip("/") for p in sparse_paths if p.strip("/")}))
return self._land_inprocess(
shard_key,
sha,
sparse_paths,
lambda staged, pins: fetch_sparse_worktree(url, sha, staged, env, pins, cones),
f"In-process sparse fetch: {_sanitize_url(url)} @ {sha[:12]}",
)

def _inprocess_checkout(
self, url: str, shard_key: str, sha: str, *, env: dict[str, str] | None
) -> Path | None:
"""Land a full checkout fetched in-process, or ``None`` to run git."""
from .inprocess_fetch import fetch_worktree

return self._land_inprocess(
shard_key,
sha,
None,
lambda staged, pins: fetch_worktree(url, sha, staged, env, pins),
f"In-process fetch: {_sanitize_url(url)} @ {sha[:12]}",
)

def _land_inprocess(
self,
shard_key: str,
sha: str,
sparse_paths: list[str] | None,
fetch: Callable[[Path, tuple[tuple[str, str], ...]], dict[str, tuple[str, bool]] | None],
note: str,
) -> Path | None:
"""Stage, fetch in process and land one checkout variant; ``None`` means run git."""
from ..utils.file_ops import robust_rmtree
from .checkout_verify import register_inprocess_manifest
from .inprocess_fetch import fetch_worktree

sha_parent = self._checkouts_root / shard_key / sha
ensure_path_within(sha_parent, self._checkouts_root)
sha_parent.mkdir(parents=True, exist_ok=True)
os.chmod(str(sha_parent), 0o700)
final_dir = sha_parent / _variant_key(None)
final_dir = sha_parent / _variant_key(sparse_paths)
lock = shard_lock(final_dir)
with lock:
if final_dir.exists():
Expand All @@ -592,12 +636,12 @@ def _inprocess_checkout(
ensure_path_within(staged, self._checkouts_root)
staged.mkdir(parents=True, exist_ok=True)
os.chmod(str(staged), 0o700)
files = fetch_worktree(url, sha, staged, env, _checkout_materialization_pins())
files = fetch(staged, _checkout_materialization_pins())
if files is None or not atomic_land(staged, final_dir, lock):
robust_rmtree(staged, ignore_errors=True)
return None
register_inprocess_manifest(final_dir, sha, files)
_log.debug("In-process fetch: %s @ %s", _sanitize_url(url), sha[:12])
_log.debug("%s", note)
return self._record_checkout_access(final_dir)

def _read_only_checkout(
Expand Down
Loading
Loading