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
162
163
164
165
166
167
168
169
170
171
use git_protocol::transport::client::Transport;
use crate::{
bstr::BString,
remote,
remote::{
fetch::{DryRun, RefMap},
ref_map, Connection,
},
Progress,
};
mod error;
pub use error::Error;
pub enum RefLogMessage {
Prefixed {
action: String,
},
Override {
message: BString,
},
}
impl RefLogMessage {
pub(crate) fn compose(&self, context: &str) -> BString {
match self {
RefLogMessage::Prefixed { action } => format!("{}: {}", action, context).into(),
RefLogMessage::Override { message } => message.to_owned(),
}
}
}
#[derive(Debug, Clone)]
pub enum Status {
NoChange,
Change {
write_pack_bundle: git_pack::bundle::write::Outcome,
update_refs: refs::update::Outcome,
},
DryRun {
update_refs: refs::update::Outcome,
},
}
#[derive(Debug, Clone)]
pub struct Outcome {
pub ref_map: RefMap,
pub status: Status,
}
pub mod negotiate;
pub mod prepare {
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Cannot perform a meaningful fetch operation without any configured ref-specs")]
MissingRefSpecs,
#[error(transparent)]
RefMap(#[from] crate::remote::ref_map::Error),
}
}
impl<'remote, 'repo, T, P> Connection<'remote, 'repo, T, P>
where
T: Transport,
P: Progress,
{
#[allow(clippy::result_large_err)]
pub fn prepare_fetch(mut self, options: ref_map::Options) -> Result<Prepare<'remote, 'repo, T, P>, prepare::Error> {
if self.remote.refspecs(remote::Direction::Fetch).is_empty() {
return Err(prepare::Error::MissingRefSpecs);
}
let ref_map = self.ref_map_inner(options)?;
Ok(Prepare {
con: Some(self),
ref_map,
dry_run: DryRun::No,
reflog_message: None,
})
}
}
impl<'remote, 'repo, T, P> Prepare<'remote, 'repo, T, P>
where
T: Transport,
{
pub fn ref_map(&self) -> &RefMap {
&self.ref_map
}
}
mod config;
mod receive_pack;
#[path = "update_refs/mod.rs"]
pub mod refs;
pub struct Prepare<'remote, 'repo, T, P>
where
T: Transport,
{
con: Option<Connection<'remote, 'repo, T, P>>,
ref_map: RefMap,
dry_run: DryRun,
reflog_message: Option<RefLogMessage>,
}
impl<'remote, 'repo, T, P> Prepare<'remote, 'repo, T, P>
where
T: Transport,
{
pub fn with_dry_run(mut self, enabled: bool) -> Self {
self.dry_run = enabled.then(|| DryRun::Yes).unwrap_or(DryRun::No);
self
}
pub fn with_reflog_message(mut self, reflog_message: RefLogMessage) -> Self {
self.reflog_message = reflog_message.into();
self
}
}
impl<'remote, 'repo, T, P> Drop for Prepare<'remote, 'repo, T, P>
where
T: Transport,
{
fn drop(&mut self) {
if let Some(mut con) = self.con.take() {
git_protocol::fetch::indicate_end_of_interaction(&mut con.transport).ok();
}
}
}