Skip to content

Commit

Permalink
A basic implementation of rev-list without anything fancy
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 31, 2022
1 parent 992bfe5 commit 791dd66
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
* **mailmap**
* [x] **entries** - display all entries of the aggregated mailmap git would use for substitution
* **revision**
* [x] **list** - list plain revision hashes from a starting point, similar to a very simple version of `git rev-list`.
* [x] **explain** - show what would be done while parsing a revision specification like `HEAD~1`
* [x] **resolve** - show which objects a revspec resolves to, similar to `git rev-parse` but faster and with much better error handling
* [x] **previous-branches** - list all previously checked out branches, powered by the ref-log.
Expand Down
27 changes: 27 additions & 0 deletions gitoxide-core/src/repository/revision/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use anyhow::{bail, Context};
use git_repository as git;
use std::ffi::OsString;

use crate::OutputFormat;

pub fn list(
mut repo: git::Repository,
spec: OsString,
mut out: impl std::io::Write,
format: OutputFormat,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("Only human output is currently supported");
}
repo.object_cache_size_if_unset(4 * 1024 * 1024);

let spec = git::path::os_str_into_bstr(&spec)?;
let id = repo
.rev_parse(spec)?
.single()
.context("Only single revisions are currently supported")?;
for commit in id.ancestors().all()? {
writeln!(out, "{}", commit?.to_hex())?;
}
Ok(())
}
4 changes: 3 additions & 1 deletion gitoxide-core/src/repository/revision/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod list;
pub use list::list;
mod explain;
pub use explain::explain;

pub mod resolve;
pub use resolve::function::resolve;

mod previous_branches;
pub use previous_branches::function as previous_branches;
pub use previous_branches::previous_branches;
6 changes: 5 additions & 1 deletion gitoxide-core/src/repository/revision/previous_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use git_repository as git;

use crate::OutputFormat;

pub fn function(repo: git::Repository, mut out: impl std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
pub fn previous_branches(
repo: git::Repository,
mut out: impl std::io::Write,
format: OutputFormat,
) -> anyhow::Result<()> {
let branches = repo
.head()?
.prior_checked_out_branches()?
Expand Down
10 changes: 10 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ pub fn main() -> Result<()> {
},
),
Subcommands::Revision(cmd) => match cmd {
revision::Subcommands::List { spec } => prepare_and_run(
"revision-list",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
core::repository::revision::list(repository(Mode::Lenient)?, spec, out, format)
},
),
revision::Subcommands::PreviousBranches => prepare_and_run(
"revision-previousbranches",
verbose,
Expand Down
3 changes: 3 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ pub mod revision {
#[derive(Debug, clap::Subcommand)]
#[clap(visible_alias = "rev", visible_alias = "r")]
pub enum Subcommands {
/// List all commits reachable from the given rev-spec.
#[clap(visible_alias = "l")]
List { spec: std::ffi::OsString },
/// Provide the revision specification like `@~1` to explain.
#[clap(visible_alias = "e")]
Explain { spec: std::ffi::OsString },
Expand Down

0 comments on commit 791dd66

Please sign in to comment.