From 8c524fee48ae0501f36abf9ad1100a50580b5141 Mon Sep 17 00:00:00 2001 From: Alessandro Ottaviano Date: Tue, 3 Nov 2026 01:54:40 -0500 Subject: [PATCH 1/2] feat: share git checkouts across projects with `checkout_store` --- CHANGELOG.md | 1 + book/src/configuration.md | 6 ++++++ src/cli.rs | 1 + src/config.rs | 11 +++++++++++ src/sess.rs | 16 ++++++++++++++-- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4009b90..5c579471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - script: Upgrade the templating engine from Tera 1 to Tera 2. Custom templates passed to `bender script template --template` may need updating. See the [Tera migration guide](https://github.com/Keats/tera/blob/master/MIGRATION.md) for the full list. The output of all built-in formats is unchanged. ### Added +- Add `checkout_store` config field to share git checkouts across projects, one per dependency URL and locked revision. - script: expose `all_headers` to templates — the fine-grained, transitive, deduplicated set of header files Slang resolved via `` `include `` for the kept trees. Populated whenever the Slang pass runs (`--top`/`--trim-incdirs`/`--broken`/`--encrypted`). ### Changed diff --git a/book/src/configuration.md b/book/src/configuration.md index 2102ccde..ca735588 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -36,6 +36,12 @@ Optional override for the directory that holds the bare git repositories and the > **Note:** Bender versions before 0.32 silently ignore this field and fall back to their per-project default, so it is safe to ship in a shared configuration that mixed bender versions may read. +### `checkout_store` +Optional directory of git checkouts shared across projects. Each git dependency is checked out once per URL and locked revision, at `/-//`, and every project locked to that revision uses that checkout instead of its own. Unless `db_dir` is set, the bare repositories the checkouts borrow their objects from live under `/git/db/`. Treat the checkouts as read-only; use `bender clone` to modify a dependency. Projects with a [`workspace.checkout_dir`](./manifest.md) keep their own checkouts. +- **Config Key:** `checkout_store` +- **Default:** unset (checkouts follow `database`). +- **Example:** `checkout_store: /var/cache/bender_checkouts` + ### `git` The command or path used to invoke Git. - **Config Key:** `git` diff --git a/src/cli.rs b/src/cli.rs index b16e6f30..e37c8ea8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -528,6 +528,7 @@ fn load_config(from: &Path, warn_config_loaded: bool) -> Result { db_dir: std::env::var("BENDER_DB_DIR") .ok() .filter(|s| !s.is_empty()), + checkout_store: None, git: Some("git".into()), overrides: None, plugins: None, diff --git a/src/config.rs b/src/config.rs index b150f659..3f074168 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1620,6 +1620,9 @@ pub struct Config { /// these two specific paths; checkouts and everything else still derive /// from `database`. pub db_dir: Option, + /// Optional directory of git checkouts shared across projects, one per + /// dependency URL and revision. + pub checkout_store: Option, /// The git command or path to the binary. pub git: String, /// The dependency overrides. @@ -1641,6 +1644,8 @@ pub struct PartialConfig { pub database: Option, /// Optional override for the bare-repo and lock directory. pub db_dir: Option, + /// Optional directory of shared git checkouts. + pub checkout_store: Option, /// The git command or path to the binary. pub git: Option, /// The dependency overrides. @@ -1667,6 +1672,7 @@ impl PrefixPaths for PartialConfig { Ok(PartialConfig { database: self.database.prefix_paths(prefix)?, db_dir: self.db_dir.prefix_paths(prefix)?, + checkout_store: self.checkout_store.prefix_paths(prefix)?, overrides: self.overrides.prefix_paths(prefix)?, plugins: self.plugins.prefix_paths(prefix)?, ..self @@ -1679,6 +1685,7 @@ impl Merge for PartialConfig { PartialConfig { database: self.database.or(other.database), db_dir: self.db_dir.or(other.db_dir), + checkout_store: self.checkout_store.or(other.checkout_store), git: self.git.or(other.git), overrides: match (self.overrides, other.overrides) { (Some(o), None) | (None, Some(o)) => Some(o), @@ -1724,6 +1731,10 @@ impl Validate for PartialConfig { Some(d) => Some(env_path_from_string(&d)?), None => None, }, + checkout_store: self + .checkout_store + .map(|d| env_path_from_string(&d)) + .transpose()?, git: match self.git { Some(git) => git, None => bail!("Git command or path to binary not configured"), diff --git a/src/sess.rs b/src/sess.rs index 272933d0..ffe374c0 100644 --- a/src/sess.rs +++ b/src/sess.rs @@ -503,6 +503,16 @@ impl<'ctx> Session<'ctx> { pub fn get_package_path(&self, dep_id: DependencyRef) -> PathBuf { let dep = self.dependency(dep_id); + // With a checkout store, a git dependency's checkout is keyed by its + // URL and locked revision, so every project on that revision shares it. + if let (Some(store), DependencySource::Git(url), Some(rev), None) = ( + &self.config.checkout_store, + &dep.source, + &dep.revision, + &self.manifest.workspace.checkout_dir, + ) { + return store.join(self.git_db_name(&dep.name, url)).join(rev); + } self.get_depsource_path(&dep.name, &dep.source) } @@ -586,12 +596,14 @@ impl<'ctx> Session<'ctx> { /// The directory under which bare git databases and lock files live. /// /// Uses `db_dir` if configured (the recommended way to share bare repos - /// across projects without relocating checkouts), otherwise falls back to - /// `database`. + /// across projects without relocating checkouts), otherwise + /// `checkout_store`, whose checkouts borrow objects from these repos, and + /// falls back to `database`. pub fn db_parent(&self) -> &Path { self.config .db_dir .as_deref() + .or(self.config.checkout_store.as_deref()) .unwrap_or(&self.config.database) } } From 9a5621ec87d5aeb16626916f7f25a8ebfdcc8112 Mon Sep 17 00:00:00 2001 From: Alessandro Ottaviano Date: Tue, 3 Nov 2026 01:55:14 -0500 Subject: [PATCH 2/2] changelog: Link the `checkout_store` entry to its PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c579471..1ad05210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - script: Upgrade the templating engine from Tera 1 to Tera 2. Custom templates passed to `bender script template --template` may need updating. See the [Tera migration guide](https://github.com/Keats/tera/blob/master/MIGRATION.md) for the full list. The output of all built-in formats is unchanged. ### Added -- Add `checkout_store` config field to share git checkouts across projects, one per dependency URL and locked revision. +- Add `checkout_store` config field to share git checkouts across projects, one per dependency URL and locked revision (https://github.com/pulp-platform/bender/pull/376). - script: expose `all_headers` to templates — the fine-grained, transitive, deduplicated set of header files Slang resolved via `` `include `` for the kept trees. Populated whenever the Slang pass runs (`--top`/`--trim-incdirs`/`--broken`/`--encrypted`). ### Changed