upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr/fetch.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-09-12 16:54:52 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-09-12 16:54:52 +0100
commit5e958f48e58712736e6394f15b91997ba5231e01 (patch)
tree3eb7393eb4c4fcacfe7ca9791c7499cca1b36aa9 /src/bin/git_remote_nostr/fetch.rs
parentca33d4d2effff63986038c94e69a7484ddfa1839 (diff)
fix(remote): `push` status updates
push needs to use push_transfer_progress rather than transfer_progress
Diffstat (limited to 'src/bin/git_remote_nostr/fetch.rs')
-rw-r--r--src/bin/git_remote_nostr/fetch.rs68
1 files changed, 55 insertions, 13 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs
index 1e38e0e..59067fa 100644
--- a/src/bin/git_remote_nostr/fetch.rs
+++ b/src/bin/git_remote_nostr/fetch.rs
@@ -18,7 +18,7 @@ use ngit::{
18use crate::utils::{ 18use crate::utils::{
19 fetch_or_list_error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name, 19 fetch_or_list_error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name,
20 get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and, 20 get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and,
21 report_on_sideband_progress, report_on_transfer_progress, ProgressStatus, TransferDirection, 21 report_on_sideband_progress,
22}; 22};
23 23
24pub async fn run_fetch( 24pub async fn run_fetch(
@@ -172,6 +172,58 @@ fn fetch_from_git_server(
172 } 172 }
173} 173}
174 174
175enum ProgressStatus {
176 InProgress,
177 Complete,
178}
179
180#[allow(clippy::cast_precision_loss)]
181#[allow(clippy::float_cmp)]
182#[allow(clippy::needless_pass_by_value)]
183fn report_on_transfer_progress(
184 progress_stats: &git2::Progress<'_>,
185 term: &console::Term,
186 status: ProgressStatus,
187) {
188 let total = progress_stats.total_objects() as f64;
189 if total == 0.0 {
190 return;
191 }
192 let received = progress_stats.received_objects() as f64;
193 let percentage = (received / total) * 100.0;
194
195 // Get the total received bytes
196 let received_bytes = progress_stats.received_bytes() as f64;
197
198 // Determine whether to use KiB or MiB
199 let (size, unit) = if received_bytes >= (1024.0 * 1024.0) {
200 // Convert to MiB
201 (received_bytes / (1024.0 * 1024.0), "MiB")
202 } else {
203 // Convert to KiB
204 (received_bytes / 1024.0, "KiB")
205 };
206
207 // Format the output for receiving objects
208 if received < total || matches!(status, ProgressStatus::Complete) {
209 let _ = term.write_line(
210 format!(
211 "Receiving objects: {percentage:.0}% ({received}/{total}) {size:.2} {unit}, done.",
212 )
213 .as_str(),
214 );
215 }
216 if received == total || matches!(status, ProgressStatus::Complete) {
217 let indexed_deltas = progress_stats.indexed_deltas() as f64;
218 let total_deltas = progress_stats.total_deltas() as f64;
219 let percentage = (indexed_deltas / total_deltas) * 100.0;
220 let _ = term.write_line(
221 format!("Resolving deltas: {percentage:.0}% ({indexed_deltas}/{total_deltas}) done.")
222 .as_str(),
223 );
224 }
225}
226
175fn fetch_from_git_server_url( 227fn fetch_from_git_server_url(
176 git_repo: &Repository, 228 git_repo: &Repository,
177 oids: &[String], 229 oids: &[String],
@@ -193,12 +245,7 @@ fn fetch_from_git_server_url(
193 }); 245 });
194 remote_callbacks.transfer_progress(|stats| { 246 remote_callbacks.transfer_progress(|stats| {
195 let _ = term.clear_last_lines(1); 247 let _ = term.clear_last_lines(1);
196 report_on_transfer_progress( 248 report_on_transfer_progress(&stats, term, ProgressStatus::InProgress);
197 &stats,
198 term,
199 TransferDirection::Fetch,
200 ProgressStatus::InProgress,
201 );
202 true 249 true
203 }); 250 });
204 251
@@ -209,12 +256,7 @@ fn fetch_from_git_server_url(
209 term.write_line("")?; 256 term.write_line("")?;
210 git_server_remote.download(oids, Some(&mut fetch_options))?; 257 git_server_remote.download(oids, Some(&mut fetch_options))?;
211 258
212 report_on_transfer_progress( 259 report_on_transfer_progress(&git_server_remote.stats(), term, ProgressStatus::Complete);
213 &git_server_remote.stats(),
214 term,
215 TransferDirection::Fetch,
216 ProgressStatus::Complete,
217 );
218 260
219 git_server_remote.disconnect()?; 261 git_server_remote.disconnect()?;
220 Ok(()) 262 Ok(())