Repository navigation
Expand file tree
/
Copy pathcommit.rs
More file actions
56 lines (53 loc) · 2.28 KB
/
Copy pathcommit.rs
File metadata and controls
56 lines (53 loc) · 2.28 KB
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
//! Explicit Commit over the existing daemon constructor/publication owner.
use super::WorkspaceApi;
use crate::OperationFailure;
use layerfs_bridge::control::{
CommitControl, ConflictReport, MergedCommit, Reply, Request, WorkspaceToken,
};
use layerfs_history::CommitOutcome;
/// The daemon's answer to one Workspace Commit.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum CommitReply {
/// Published against the head the Workspace was bound to, or forced.
Committed(Box<CommitOutcome>),
/// Merged with a moved head, then published.
Merged(Box<MergedCommit>),
/// Refused for conflicts; nothing was published.
Conflict(Box<ConflictReport>),
}
impl WorkspaceApi<'_> {
/// Requests one Commit and returns its original known publication/install result.
/// The daemon captures the Workspace's shared published frontier and constructs
/// it; this facade sends one request and infers nothing from the binding.
/// A merged publication returns its outcome; a conflict is unexpected here.
pub fn commit(
&mut self,
token: WorkspaceToken,
) -> Result<CommitOutcome, Box<OperationFailure>> {
let request = Request::Commit(CommitControl {
token,
force: false,
message: None,
});
match self.exchange(request.clone())? {
Reply::Committed(outcome) => Ok(outcome),
Reply::MergeCommitted(merged) => Ok(merged.outcome),
reply => Err(OperationFailure::unexpected(request, reply)),
}
}
/// Requests one Commit; `force` publishes over a moved head instead of
/// merging, and `agent` and `call` are recorded on the Commit. Returns the publication, the merged publication or the
/// conflict refusal.
pub fn commit_with(
&mut self,
control: CommitControl,
) -> Result<CommitReply, Box<OperationFailure>> {
let request = Request::Commit(control);
match self.exchange(request.clone())? {
Reply::Committed(outcome) => Ok(CommitReply::Committed(Box::new(outcome))),
Reply::MergeCommitted(merged) => Ok(CommitReply::Merged(merged)),
Reply::Conflict(report) => Ok(CommitReply::Conflict(report)),
reply => Err(OperationFailure::unexpected(request, reply)),
}
}
}