From cd6a2f78f127dbbfd04a4ea14bac415da9a1404d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 18 May 2021 20:47:25 -0700 Subject: [PATCH 1/2] Use git CLI to fetch a repo. --- src/git.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/git.rs b/src/git.rs index 5545142..443084c 100644 --- a/src/git.rs +++ b/src/git.rs @@ -7,7 +7,7 @@ use std::env; use std::path::Path; use chrono::{TimeZone, Utc}; -use failure::{bail, Error}; +use failure::{bail, Error, ResultExt}; use git2::build::RepoBuilder; use git2::{Commit as Git2Commit, Repository}; use log::debug; @@ -34,13 +34,20 @@ fn lookup_rev<'rev>(repo: &'rev Repository, rev: &str) -> Result Result { fn open(repo: &Path) -> Result { + eprintln!("refreshing repository at {:?}", repo); + // This uses the CLI because libgit2 is quite slow to fetch a large repository. + let status = std::process::Command::new("git") + .arg("fetch") + .current_dir(repo) + .status() + .context(format!( + "expected `git` command-line executable to be installed" + ))?; + if !status.success() { + bail!("git fetch failed exit status {}", status); + } eprintln!("opening existing repository at {:?}", repo); let repo = Repository::open(repo)?; - { - eprintln!("refreshing repository"); - let mut remote = repo.remote_anonymous(RUST_SRC_URL)?; - remote.fetch(&["master"], None, None)?; - } Ok(repo) } From 0f9331913cf1d895942f674f7b722212d40c027b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 2 Oct 2021 15:30:30 -0700 Subject: [PATCH 2/2] Make sure to fetch the correct remote. --- src/git.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/git.rs b/src/git.rs index 443084c..88af527 100644 --- a/src/git.rs +++ b/src/git.rs @@ -38,6 +38,7 @@ fn get_repo() -> Result { // This uses the CLI because libgit2 is quite slow to fetch a large repository. let status = std::process::Command::new("git") .arg("fetch") + .arg(RUST_SRC_URL) .current_dir(repo) .status() .context(format!(