feat(api): extend commit and diff services with new functionality
- Add FindCommit, ListCommitsByOid, CommitIsAncestor RPCs to CommitService - Add CheckObjectsExist, CommitsByMessage, GetCommitStats RPCs to CommitService - Add LastCommitForPath, CountCommits, CountDivergingCommits RPCs to CommitService - Add RawDiff, RawPatch, FindChangedPaths RPCs to DiffService - Add FindMergeBase, WriteRef, SearchFilesByContent RPCs to RepositoryService - Add SearchFilesByName, ObjectsSize, RepositorySize RPCs to RepositoryService - Add FindLicense, OptimizeRepository, GetRawChanges RPCs to RepositoryService - Add FetchRemote, CreateRepositoryFromURL RPCs to RepositoryService - Implement server handlers for all new RPC methods - Add new modules for commit counting, finding, and querying features - Add new modules for diff changed paths and raw operations - Add new modules for refs and remote operations - Remove unnecessary comments from various source files - Update proto definitions with new message types and service methods
This commit is contained in:
+47
-43
@@ -12,48 +12,52 @@ impl GitBare {
|
||||
.object()?
|
||||
.try_into_commit()
|
||||
.map_err(|e| GitError::Gix(e.to_string()))?;
|
||||
let hex = commit.id.to_string();
|
||||
let tree_hex = commit.tree_id()?.to_string();
|
||||
let message = commit.message_raw()?.to_string();
|
||||
let (subject, body) = message
|
||||
.split_once('\n')
|
||||
.map(|(s, b)| (s.to_string(), b.trim_start_matches('\n').to_string()))
|
||||
.unwrap_or_else(|| (message.clone(), String::new()));
|
||||
let author_sig = commit.author().ok();
|
||||
let committer_sig = commit.committer().ok();
|
||||
Ok(Commit {
|
||||
oid: Some(self.oid_to_pb(hex.clone())),
|
||||
abbreviated_oid: commit
|
||||
.short_id()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|_| hex.chars().take(7).collect()),
|
||||
parent_oids: commit
|
||||
.parent_ids()
|
||||
.map(|p| self.oid_to_pb(p.to_string()))
|
||||
.collect(),
|
||||
tree_oid: Some(self.oid_to_pb(tree_hex)),
|
||||
author: author_sig.as_ref().map(gix_sig_to_pb),
|
||||
committer: committer_sig.as_ref().map(gix_sig_to_pb),
|
||||
subject,
|
||||
body,
|
||||
message,
|
||||
trailers: Vec::new(),
|
||||
signature: None,
|
||||
stats: None,
|
||||
authored_at: author_sig.as_ref().map(|s| prost_types::Timestamp {
|
||||
seconds: s.seconds(),
|
||||
nanos: 0,
|
||||
}),
|
||||
committed_at: committer_sig.as_ref().map(|s| prost_types::Timestamp {
|
||||
seconds: s.seconds(),
|
||||
nanos: 0,
|
||||
}),
|
||||
raw: if request.include_raw {
|
||||
commit.data.clone()
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
})
|
||||
Ok(commit_to_pb(self, &commit, request.include_raw))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn commit_to_pb(gb: &GitBare, commit: &gix::Commit<'_>, include_raw: bool) -> Commit {
|
||||
let hex = commit.id.to_string();
|
||||
let tree_hex = commit.tree_id().map(|t| t.to_string()).unwrap_or_default();
|
||||
let message = commit.message_raw().map(|m| m.to_string()).unwrap_or_default();
|
||||
let (subject, body) = message
|
||||
.split_once('\n')
|
||||
.map(|(s, b)| (s.to_string(), b.trim_start_matches('\n').to_string()))
|
||||
.unwrap_or_else(|| (message.clone(), String::new()));
|
||||
let author_sig = commit.author().ok();
|
||||
let committer_sig = commit.committer().ok();
|
||||
Commit {
|
||||
oid: Some(gb.oid_to_pb(hex.clone())),
|
||||
abbreviated_oid: commit
|
||||
.short_id()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|_| hex.chars().take(7).collect()),
|
||||
parent_oids: commit
|
||||
.parent_ids()
|
||||
.map(|p| gb.oid_to_pb(p.to_string()))
|
||||
.collect(),
|
||||
tree_oid: Some(gb.oid_to_pb(tree_hex)),
|
||||
author: author_sig.as_ref().map(gix_sig_to_pb),
|
||||
committer: committer_sig.as_ref().map(gix_sig_to_pb),
|
||||
subject,
|
||||
body,
|
||||
message,
|
||||
trailers: Vec::new(),
|
||||
signature: None,
|
||||
stats: None,
|
||||
authored_at: author_sig.as_ref().map(|s| prost_types::Timestamp {
|
||||
seconds: s.seconds(),
|
||||
nanos: 0,
|
||||
}),
|
||||
committed_at: committer_sig.as_ref().map(|s| prost_types::Timestamp {
|
||||
seconds: s.seconds(),
|
||||
nanos: 0,
|
||||
}),
|
||||
raw: if include_raw {
|
||||
commit.data.clone()
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +74,4 @@ pub(crate) fn gix_sig_to_pb(sig: &gix::actor::SignatureRef<'_>) -> crate::pb::Si
|
||||
}),
|
||||
timezone_offset: time.map(|t| t.offset / 60).unwrap_or(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user