Skip to content

Commit

Permalink
basic infrastructure for delegate implementation (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 14, 2022
1 parent 1049b00 commit d3c0bc6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
72 changes: 65 additions & 7 deletions gitoxide-core/src/repository/revision/explain.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,69 @@
use git::revision::spec::parse::{delegate, Delegate};
use git_repository as git;
use git_repository::bstr::BStr;
use git_repository::hash::Prefix;
use git_repository::revision::spec::parse::delegate::{PeelTo, ReflogLookup, SiblingBranch, Traversal};
use git_repository::revision::spec::Kind;
use std::ffi::OsString;

pub fn explain(
_repo: git::Repository,
_spec: OsString,
mut _out: impl std::io::Write,
mut _err: impl std::io::Write,
) -> anyhow::Result<()> {
Ok(())
struct Explain<'a> {
out: &'a mut dyn std::io::Write,
}

impl<'a> delegate::Revision for Explain<'a> {
fn find_ref(&mut self, name: &BStr) -> Option<()> {
todo!()
}

fn disambiguate_prefix(&mut self, prefix: Prefix) -> Option<()> {
todo!()
}

fn reflog(&mut self, query: ReflogLookup) -> Option<()> {
todo!()
}

fn nth_checked_out_branch(&mut self, branch_no: usize) -> Option<()> {
todo!()
}

fn sibling_branch(&mut self, kind: SiblingBranch) -> Option<()> {
todo!()
}
}

impl<'a> delegate::Navigate for Explain<'a> {
fn traverse(&mut self, kind: Traversal) -> Option<()> {
todo!()
}

fn peel_until(&mut self, kind: PeelTo<'_>) -> Option<()> {
todo!()
}

fn find(&mut self, regex: &BStr, negated: bool) -> Option<()> {
todo!()
}

fn index_lookup(&mut self, path: &BStr, stage: u8) -> Option<()> {
todo!()
}
}

impl<'a> delegate::Kind for Explain<'a> {
fn kind(&mut self, kind: Kind) -> Option<()> {
todo!()
}
}

impl<'a> Delegate for Explain<'a> {
fn done(&mut self) {
todo!()
}
}

pub fn explain(_repo: git::Repository, spec: OsString, mut out: impl std::io::Write) -> anyhow::Result<()> {
let mut explain = Explain { out: &mut out };
let spec = git::path::os_str_into_bstr(&spec)?;
git::revision::spec::parse(spec, &mut explain).map_err(anyhow::Error::from)
}
4 changes: 1 addition & 3 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, err| {
core::repository::revision::explain(repository.into(), spec, out, err)
},
move |_progress, out, _err| core::repository::revision::explain(repository.into(), spec, out),
),
},
repo::Subcommands::Commit { cmd } => match cmd {
Expand Down

0 comments on commit d3c0bc6

Please sign in to comment.