summaryrefslogtreecommitdiffstats
path: root/src/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs38
1 files changed, 10 insertions, 28 deletions
diff --git a/src/git.rs b/src/git.rs
index 5ee41dd..a14ac50 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -14,10 +14,10 @@ pub fn git(cwd: Option<&Path>, args: &[&str]) -> Result<String> {
cmd.env("GIT_CONFIG_NOSYSTEM", "1");
cmd.env("LC_ALL", "C");
let out = cmd.output().map_err(|e| Error::git(format!("git {args:?}: {e}")))?;
- ok(out, args)
+ ok(&out, args)
}
-fn ok(out: Output, args: &[&str]) -> Result<String> {
+fn ok(out: &Output, args: &[&str]) -> Result<String> {
if !out.status.success() {
return Err(Error::git(format!(
"git {args:?} exited {}: {}",
@@ -35,11 +35,7 @@ fn git_ok(cwd: Option<&Path>, args: &[&str]) -> bool {
pub fn ls_remote_head(url: &str) -> Result<Option<String>> {
match git(None, &["ls-remote", url, "HEAD"]) {
Ok(out) => {
- let sha = out
- .split_whitespace()
- .next()
- .filter(|s| s.len() >= 7)
- .map(|s| s.to_string());
+ let sha = out.split_whitespace().next().filter(|s| s.len() >= 7).map(std::string::ToString::to_string);
Ok(sha)
}
Err(e) if is_missing_remote(&e) => Ok(None),
@@ -49,11 +45,9 @@ pub fn ls_remote_head(url: &str) -> Result<Option<String>> {
pub fn ls_remote_ref(url: &str, refname: &str) -> Result<Option<String>> {
match git(None, &["ls-remote", url, refname]) {
- Ok(out) => Ok(out
- .lines()
- .next()
- .and_then(|l| l.split_whitespace().next())
- .map(|s| s.to_string())),
+ Ok(out) => {
+ Ok(out.lines().next().and_then(|l| l.split_whitespace().next()).map(std::string::ToString::to_string))
+ }
Err(e) if is_missing_remote(&e) => Ok(None),
Err(e) => Err(e),
}
@@ -85,10 +79,7 @@ pub fn clone_bare(url: &str, dest: &Path) -> Result<()> {
if let Some(parent) = dest.parent() {
std::fs::create_dir_all(parent)?;
}
- git(
- None,
- &["clone", "--quiet", "--bare", url, &dest.display().to_string()],
- )?;
+ git(None, &["clone", "--quiet", "--bare", url, &dest.display().to_string()])?;
Ok(())
}
@@ -180,12 +171,7 @@ pub fn cat_file_batch(mirror: &Path, oids: &[String]) -> Result<BTreeMap<String,
stdout.read_exact(&mut newline)?;
out.insert(id, body);
}
- _ => {
- return Err(Error::git(format!(
- "unreadable cat-file header {:?}",
- header.trim_end()
- )))
- }
+ _ => return Err(Error::git(format!("unreadable cat-file header {:?}", header.trim_end()))),
}
}
@@ -215,15 +201,11 @@ pub fn materialize(mirror: &Path, commit: &str, dest: &Path) -> Result<()> {
.output()
.map_err(|e| Error::git(e.to_string()))?;
if !out.status.success() {
- return Err(Error::git(format!(
- "git archive {commit}: {}",
- String::from_utf8_lossy(&out.stderr).trim()
- )));
+ return Err(Error::git(format!("git archive {commit}: {}", String::from_utf8_lossy(&out.stderr).trim())));
}
let mut ar = tar::Archive::new(std::io::Cursor::new(&out.stdout));
ar.set_preserve_permissions(true);
- ar.unpack(dest)
- .map_err(|e| Error::git(format!("unpack {commit}: {e}")))?;
+ ar.unpack(dest).map_err(|e| Error::git(format!("unpack {commit}: {e}")))?;
Ok(())
}