-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support minimal 'fetch' using
gitoxide
This most notably excludes: * progress * SSH name guessing * retry on spurious timeout/connection issues
- Loading branch information
Showing
4 changed files
with
185 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub use self::source::GitSource; | ||
pub use self::utils::{fetch, GitCheckout, GitDatabase, GitRemote}; | ||
mod oxide; | ||
mod source; | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//! This module contains all code sporting `gitoxide` for operations on `git` repositories and it mirrors | ||
//! `utils` closely for now. One day it can be renamed into `utils` once `git2` isn't required anymore. | ||
|
||
use crate::util::{network, Progress}; | ||
use crate::{CargoResult, Config}; | ||
use git_repository as git; | ||
use std::sync::atomic::AtomicBool; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
/// For the time being, `repo_path` makes it easy to instantiate a gitoxide repo just for fetching. | ||
/// In future this may change to be the gitoxide repository itself. | ||
pub fn with_retry_and_progress( | ||
repo_path: &std::path::Path, | ||
config: &Config, | ||
cb: &mut (dyn FnMut( | ||
&git::Repository, | ||
&AtomicBool, | ||
&mut git::progress::tree::Item, | ||
) -> CargoResult<()> | ||
+ Send), | ||
) -> CargoResult<()> { | ||
let repo = git::open_opts(repo_path, { | ||
let mut opts = git::open::Options::default(); | ||
// We need `git_binary` configuration as well for being able to see credential helpers | ||
// that are configured with the `git` installation itself. | ||
// However, this is slow on windows (~150ms) and most people won't need it as they use the | ||
// standard index which won't ever need authentication. | ||
// TODO: This is certainly something to make configurable, at the very least on windows. | ||
// Maybe it's also something that could be cached, all we need is the path to the configuration file | ||
// which usually doesn't change unless the installation changes. Maybe something keyed by the location of the | ||
// binary along with its fingerprint. | ||
opts.permissions.config = git::permissions::Config::all(); | ||
opts | ||
})?; | ||
|
||
let progress_root: Arc<git::progress::tree::Root> = git::progress::tree::root::Options { | ||
initial_capacity: 10, | ||
message_buffer_capacity: 10, | ||
} | ||
.into(); | ||
let mut progress = progress_root.add_child("operation"); | ||
|
||
// For decent interrupts of long-running computations and removal of temp files we should handle interrupts, and this | ||
// is an easy way to do that. We will remove them later. | ||
// We intentionally swallow errors here as if for some reason we can't register handlers, `cargo` will just work like before and | ||
// abort on signals. | ||
let _deregister_signal_handlers_on_drop = git::interrupt::init_handler(|| {}) | ||
.ok() | ||
.unwrap_or_default() | ||
.auto_deregister(); | ||
let should_interrupt = AtomicBool::new(false); | ||
let _progress_bar = Progress::new("Fetch", config); | ||
std::thread::scope(move |s| { | ||
s.spawn({ | ||
let root = Arc::downgrade(&progress_root); | ||
move || -> CargoResult<()> { | ||
let mut tasks = Vec::with_capacity(10); | ||
while let Some(root) = root.upgrade() { | ||
root.sorted_snapshot(&mut tasks); | ||
// dbg!(&tasks); | ||
std::thread::sleep(Duration::from_millis(300)); | ||
} | ||
Ok(()) | ||
} | ||
}); | ||
network::with_retry(config, || cb(&repo, &should_interrupt, &mut progress)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters