Skip to content

Commit 08b89f0

Browse files
author
Stephan Dilly
committed
wip poc for fetching all branches
1 parent d285ec0 commit 08b89f0

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

Cargo.lock

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

asyncgit/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ keywords = ["git"]
1313

1414
[dependencies]
1515
scopetime = { path = "../scopetime", version = "0.1" }
16-
git2 = "0.13"
17-
# git2 = { path = "../../extern/git2-rs", features = ["vendored-openssl"]}
16+
# git2 = "0.13"
17+
git2 = { path = "../../extern/git2-rs", features = ["vendored-openssl"]}
1818
# git2 = { git="https://github.com/extrawurst/git2-rs.git", rev="fc13dcc", features = ["vendored-openssl"]}
1919
# pinning to vendored openssl, using the git2 feature this gets lost with new resolver
2020
openssl-sys = { version = '0.9', features= ["vendored"] }

asyncgit/src/fetch.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
error::{Error, Result},
33
sync::{
44
cred::BasicAuthCredential,
5-
remotes::{fetch, push::ProgressNotification},
5+
remotes::{fetch, fetch_all, push::ProgressNotification},
66
},
77
AsyncGitNotification, RemoteProgress, CWD,
88
};
@@ -90,6 +90,14 @@ impl AsyncFetch {
9090
arc_progress,
9191
);
9292

93+
fetch_all(
94+
CWD,
95+
"origin",
96+
params.basic_credential.clone(),
97+
Some(progress_sender.clone()),
98+
)
99+
.expect("");
100+
93101
let res = fetch(
94102
CWD,
95103
&params.branch,

asyncgit/src/sync/remotes/mod.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,39 @@ pub(crate) fn get_default_remote_in_repo(
7575
Err(Error::NoDefaultRemoteFound)
7676
}
7777

78+
///
79+
pub fn fetch_all(
80+
repo_path: &str,
81+
remote: &str,
82+
basic_credential: Option<BasicAuthCredential>,
83+
progress_sender: Option<Sender<ProgressNotification>>,
84+
) -> Result<()> {
85+
scope_time!("fetch_all");
86+
87+
let repo = utils::repo(repo_path)?;
88+
89+
let mut remote = repo.find_remote(remote)?;
90+
91+
let mut options = FetchOptions::new();
92+
let callbacks = Callbacks::new(
93+
progress_sender.clone(),
94+
basic_credential.clone(),
95+
);
96+
options.prune(git2::FetchPrune::On);
97+
options.remote_callbacks(callbacks.callbacks());
98+
remote.fetch_all(Some(&mut options), None)?;
99+
100+
Ok(())
101+
}
102+
78103
/// fetches from upstream/remote for `branch`
79104
pub(crate) fn fetch(
80105
repo_path: &str,
81106
branch: &str,
82107
basic_credential: Option<BasicAuthCredential>,
83108
progress_sender: Option<Sender<ProgressNotification>>,
84109
) -> Result<usize> {
85-
scope_time!("fetch_origin");
110+
scope_time!("fetch");
86111

87112
let repo = utils::repo(repo_path)?;
88113
let branch_ref = repo
@@ -97,6 +122,8 @@ pub(crate) fn fetch(
97122
let callbacks = Callbacks::new(progress_sender, basic_credential);
98123
options.remote_callbacks(callbacks.callbacks());
99124

125+
log::debug!("fetch: {}", branch);
126+
100127
remote.fetch(&[branch], Some(&mut options), None)?;
101128

102129
Ok(remote.stats().received_bytes())

0 commit comments

Comments
 (0)