git_lfs_transfer/config.rs
1use std::sync::Arc;
2use std::time::Duration;
3
4/// Optional URL transform applied to every action `href` returned by the
5/// batch endpoint before the transfer adapter dials it. Used to plumb
6/// `lfs.transfer.enablehrefrewrite` + `url.<base>.insteadOf` from the
7/// caller (which has the git-config context) down into the queue.
8pub type UrlRewriter = Arc<dyn Fn(&str) -> String + Send + Sync>;
9
10/// Tunables for the transfer queue.
11///
12/// Defaults aim at "sensible for a developer laptop on a corporate VPN" —
13/// not too aggressive on concurrency, generous retries for flaky links.
14/// Upstream Git LFS scales `concurrency` to CPU count (commit `aa08c37f`);
15/// we hard-code 8 for v0 and let callers override.
16#[derive(Clone)]
17pub struct TransferConfig {
18 /// Max number of concurrent in-flight transfers.
19 pub concurrency: usize,
20 /// Total attempts per object — including the first. So 3 means "try
21 /// once, then up to 2 retries".
22 pub max_attempts: u32,
23 /// Sleep before the first retry. Doubled before each subsequent retry,
24 /// capped at [`backoff_max`](Self::backoff_max).
25 pub initial_backoff: Duration,
26 /// Upper bound for exponential backoff between retries.
27 pub backoff_max: Duration,
28 /// Optional rewriter applied to every action URL before transfer.
29 /// `None` ⇒ use action URLs verbatim.
30 pub url_rewriter: Option<UrlRewriter>,
31 /// Max objects per `POST /objects/batch` call. The transfer queue
32 /// chunks the input list into runs of this size and issues one
33 /// batch API call per chunk. Default: 100 (matches upstream's
34 /// `lfs.transfer.batchSize` default). Values < 1 are clamped to 1.
35 pub batch_size: usize,
36}
37
38impl Default for TransferConfig {
39 fn default() -> Self {
40 Self {
41 concurrency: 8,
42 max_attempts: 3,
43 initial_backoff: Duration::from_millis(100),
44 backoff_max: Duration::from_secs(30),
45 url_rewriter: None,
46 batch_size: 100,
47 }
48 }
49}
50
51impl std::fmt::Debug for TransferConfig {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 f.debug_struct("TransferConfig")
54 .field("concurrency", &self.concurrency)
55 .field("max_attempts", &self.max_attempts)
56 .field("initial_backoff", &self.initial_backoff)
57 .field("backoff_max", &self.backoff_max)
58 .field("url_rewriter", &self.url_rewriter.as_ref().map(|_| "<fn>"))
59 .field("batch_size", &self.batch_size)
60 .finish()
61 }
62}