Skip to content

Commit d3c0bc6

Browse files
committed
basic infrastructure for delegate implementation (#427)
1 parent 1049b00 commit d3c0bc6

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

Diff for: gitoxide-core/src/repository/revision/explain.rs

+65-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,69 @@
1+
use git::revision::spec::parse::{delegate, Delegate};
12
use git_repository as git;
3+
use git_repository::bstr::BStr;
4+
use git_repository::hash::Prefix;
5+
use git_repository::revision::spec::parse::delegate::{PeelTo, ReflogLookup, SiblingBranch, Traversal};
6+
use git_repository::revision::spec::Kind;
27
use std::ffi::OsString;
38

4-
pub fn explain(
5-
_repo: git::Repository,
6-
_spec: OsString,
7-
mut _out: impl std::io::Write,
8-
mut _err: impl std::io::Write,
9-
) -> anyhow::Result<()> {
10-
Ok(())
9+
struct Explain<'a> {
10+
out: &'a mut dyn std::io::Write,
11+
}
12+
13+
impl<'a> delegate::Revision for Explain<'a> {
14+
fn find_ref(&mut self, name: &BStr) -> Option<()> {
15+
todo!()
16+
}
17+
18+
fn disambiguate_prefix(&mut self, prefix: Prefix) -> Option<()> {
19+
todo!()
20+
}
21+
22+
fn reflog(&mut self, query: ReflogLookup) -> Option<()> {
23+
todo!()
24+
}
25+
26+
fn nth_checked_out_branch(&mut self, branch_no: usize) -> Option<()> {
27+
todo!()
28+
}
29+
30+
fn sibling_branch(&mut self, kind: SiblingBranch) -> Option<()> {
31+
todo!()
32+
}
33+
}
34+
35+
impl<'a> delegate::Navigate for Explain<'a> {
36+
fn traverse(&mut self, kind: Traversal) -> Option<()> {
37+
todo!()
38+
}
39+
40+
fn peel_until(&mut self, kind: PeelTo<'_>) -> Option<()> {
41+
todo!()
42+
}
43+
44+
fn find(&mut self, regex: &BStr, negated: bool) -> Option<()> {
45+
todo!()
46+
}
47+
48+
fn index_lookup(&mut self, path: &BStr, stage: u8) -> Option<()> {
49+
todo!()
50+
}
51+
}
52+
53+
impl<'a> delegate::Kind for Explain<'a> {
54+
fn kind(&mut self, kind: Kind) -> Option<()> {
55+
todo!()
56+
}
57+
}
58+
59+
impl<'a> Delegate for Explain<'a> {
60+
fn done(&mut self) {
61+
todo!()
62+
}
63+
}
64+
65+
pub fn explain(_repo: git::Repository, spec: OsString, mut out: impl std::io::Write) -> anyhow::Result<()> {
66+
let mut explain = Explain { out: &mut out };
67+
let spec = git::path::os_str_into_bstr(&spec)?;
68+
git::revision::spec::parse(spec, &mut explain).map_err(anyhow::Error::from)
1169
}

Diff for: src/plumbing/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ pub fn main() -> Result<()> {
167167
progress,
168168
progress_keep_open,
169169
None,
170-
move |_progress, out, err| {
171-
core::repository::revision::explain(repository.into(), spec, out, err)
172-
},
170+
move |_progress, out, _err| core::repository::revision::explain(repository.into(), spec, out),
173171
),
174172
},
175173
repo::Subcommands::Commit { cmd } => match cmd {

0 commit comments

Comments
 (0)