1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! Native source selection and synchronous observer configuration.
use ControlFlow;
use ;
/// Work bounds and optional verified destination history for a local fetch.
///
/// Empty knowledge requests full history. The caller keeps verified history available through
/// installation; this request grants no retention against concurrent destination collection.
///
/// # Examples
///
/// ```
/// use std::sync::atomic::AtomicBool;
///
/// use girt::PackLimits;
/// use girt::fetch::{FetchLimits, KnownHistory, LocalFetchRequest};
/// # let (_directory, _, repo, _, _) = include!("../doctest/remote.rs");
/// # let commit = include!("../doctest/commit.rs");
/// # let tip = commit(&repo, &[], "Local work")?;
///
/// // A full transfer:
/// let full = LocalFetchRequest::new(FetchLimits::default());
/// assert!(full.known.is_none());
///
/// // An incremental one, excluding what the destination already has:
/// let objects = repo.objects(PackLimits::default())?;
/// let known = KnownHistory::new(
/// &objects,
/// &[tip],
/// FetchLimits::default(),
/// &AtomicBool::new(false),
/// )?;
/// let incremental = LocalFetchRequest::new(FetchLimits::default()).with_known(&known);
/// assert!(incremental.known.is_some());
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
type RemoteMessages<'a> = dyn FnMut + 'a;
/// Independent synchronous native-fetch notifications.
///
/// Each notification is optional; [`LocalFetchObserver::default`] observes nothing. Messages
/// are the source's informational text; construction reports reading and packing the source's
/// objects; validation reports checking them before installation.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
/// use std::sync::atomic::AtomicBool;
///
/// use girt::fetch::{
/// FetchLimits, FetchRequest, KnownHistory, LocalFetchObserver, LocalFetchProgress,
/// ValidationProgress,
/// };
/// use girt::refs::Reflog;
/// use girt::remote::Remote;
/// use girt::transport::TransportControl;
/// # let (_directory, upstream, repo, _, _) = include!("../doctest/remote.rs");
///
/// let mut packing = Vec::new();
/// let mut validation = Vec::new();
/// let mut on_construction = |progress: LocalFetchProgress| {
/// if let LocalFetchProgress::Packing { objects } = progress {
/// packing.push(objects);
/// }
/// };
/// let mut on_validation = |progress: ValidationProgress| validation.push(progress);
/// let observer = LocalFetchObserver::default()
/// .with_construction(&mut on_construction)
/// .with_validation(&mut on_validation);
///
/// let origin = Remote::find(repo.config(), b"origin")?.expect("configured");
/// let request = FetchRequest::prepare(
/// repo.clone(),
/// origin.fetch_refspecs().clone(),
/// BTreeSet::new(),
/// Reflog::Preserve,
/// )?;
/// let cancel = AtomicBool::new(false);
/// request.receive_local(
/// upstream.git_dir(),
/// &KnownHistory::default(),
/// FetchLimits::default(),
/// TransportControl::new(&cancel),
/// observer,
/// )?;
///
/// assert_eq!(packing.last(), Some(&(2, 2)));
/// let last = validation.last().expect("a pack was validated");
/// assert!(last.complete);
/// assert_eq!(last.objects, (2, 2));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Messages may cancel by returning `Break`. Construction and validation callbacks cannot undo
/// completed work; set the transport cancellation flag to stop at the next cooperative check.
/// Observers must return promptly. Completion never establishes installation or publication.