summaryrefslogtreecommitdiffstats
path: root/src/git.rs
diff options
context:
space:
mode:
authordev <dev@localhost>2026-11-20 18:49:22 +0000
committerdev <dev@localhost>2026-11-20 18:49:22 +0000
commit6c4b4394bd8ddf28d130e87e0100349f13f6e912 (patch)
treeebba70a9a141d05cb0251663aaacea858ec79115 /src/git.rs
parent895f3547043def08f0822f936ae34458315f6982 (diff)
downloadaur-build-6c4b4394bd8ddf28d130e87e0100349f13f6e912.tar.gz
aur-build-6c4b4394bd8ddf28d130e87e0100349f13f6e912.zip
foundation, http: export what is used above you, and nothing else
The leaf modules were the widest liars. `git` exported 19 names of which 5 were named by nobody; `hash` exported a constant `EMPTY` that no code had ever referenced; `time` exported a virtual clock, an `advance` and a `wrap` whose only caller was a test that turned out not to exist. A leaf's interface is the whole contract the rest of the crate can rely on, and these interfaces were mostly decoration. Nine items were genuinely dead and are gone: `hash::EMPTY`, `git::{clone_source, count_commits, log_oneline, ls_remote_heads}`, `recipe::is_diffable`, `pkginfo::values_of`, `time::virtual_now`, and a free `time::advance` that had been shadowed by the `VirtualClock` method tests actually call. Eighteen more were used only inside their own module and are now private — `fetch`'s `Body` aside, which is the return type of a public parser and so is part of the interface whether or not anyone writes its name. http went 68 exported names to 27, and its last two glob re-exports (`pub(crate) use mutations::*; use pages::*;`) are explicit lists now. That makes the crate's glob count zero, so the allowlist in the architecture test is empty and can stay that way. Narrowing surfaced dead code that `pub` had been hiding, because a public item is presumed used and never questioned: `Req::query` and `Req::body` were parsed and stored and never read, `Res::found` had no callers, and `sse::FileBody` was a reader nobody constructed. All four are deleted rather than re-published to keep the warning quiet. git 19→14, hash 8→7, recipe 11→7, urlutil 2→1, config 35→31, pkgver 18→14, time 16→14, pkginfo 7→6, http 68→27. Crate totals: 585→516 pub, 219→115 dead, 4→0 globs. 281 passed / 0 failed, clippy -D warnings clean, release build clean, architecture 8/8.
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs42
1 files changed, 1 insertions, 41 deletions
diff --git a/src/git.rs b/src/git.rs
index a0e6489..5ee41dd 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -28,7 +28,7 @@ fn ok(out: Output, args: &[&str]) -> Result<String> {
Ok(String::from_utf8_lossy(&out.stdout).to_string())
}
-pub fn git_ok(cwd: Option<&Path>, args: &[&str]) -> bool {
+fn git_ok(cwd: Option<&Path>, args: &[&str]) -> bool {
git(cwd, args).is_ok()
}
@@ -47,18 +47,6 @@ pub fn ls_remote_head(url: &str) -> Result<Option<String>> {
}
}
-pub fn ls_remote_heads(url: &str) -> Result<Vec<(String, String)>> {
- let out = git(None, &["ls-remote", "--heads", url])?;
- let mut v = Vec::new();
- for line in out.lines() {
- let mut it = line.split_whitespace();
- if let (Some(sha), Some(name)) = (it.next(), it.next()) {
- v.push((name.to_string(), sha.to_string()));
- }
- }
- Ok(v)
-}
-
pub fn ls_remote_ref(url: &str, refname: &str) -> Result<Option<String>> {
match git(None, &["ls-remote", url, refname]) {
Ok(out) => Ok(out
@@ -239,40 +227,12 @@ pub fn materialize(mirror: &Path, commit: &str, dest: &Path) -> Result<()> {
Ok(())
}
-pub fn log_oneline(mirror: &Path, range: &str) -> Result<Vec<String>> {
- let out = git(Some(mirror), &["log", "--oneline", range])?;
- Ok(out.lines().map(|l| l.to_string()).collect())
-}
-
pub fn diff(mirror: &Path, range: &str, paths: &[&str]) -> Result<String> {
let mut args: Vec<&str> = vec!["diff", "--no-color", range, "--"];
args.extend(paths);
git(Some(mirror), &args)
}
-pub fn count_commits(mirror: &Path, range: &str) -> Result<usize> {
- let out = git(Some(mirror), &["rev-list", "--count", range])?;
- Ok(out.trim().parse().unwrap_or(0))
-}
-
-pub fn clone_source(url: &str, dest: &Path, depth: Option<usize>, branch: Option<&str>) -> Result<()> {
- if let Some(parent) = dest.parent() {
- std::fs::create_dir_all(parent)?;
- }
- let mut args: Vec<String> = vec!["clone".into(), "--quiet".into()];
- if let Some(d) = depth {
- args.push(format!("--depth={d}"));
- }
- if let Some(b) = branch {
- args.push(format!("--branch={b}"));
- }
- args.push(url.to_string());
- args.push(dest.display().to_string());
- let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
- git(None, &refs)?;
- Ok(())
-}
-
pub fn fetch_and_head(repo: &Path) -> Result<String> {
git(Some(repo), &["fetch", "--quiet", "--no-prune", "origin"])?;
head(repo)