diff --git a/gitoxide-core/src/repository/commitgraph/list.rs b/gitoxide-core/src/repository/commitgraph/list.rs index c0d1182b819..aa203388cee 100644 --- a/gitoxide-core/src/repository/commitgraph/list.rs +++ b/gitoxide-core/src/repository/commitgraph/list.rs @@ -1,10 +1,10 @@ pub(crate) mod function { + use crate::repository::HexId; use crate::OutputFormat; use anyhow::{bail, Context}; use gix::odb::store::RefreshMode; use gix::revision::plumbing::Spec; use gix::{prelude::ObjectIdExt, revision::walk::Sorting}; - use std::fmt::Formatter; use std::{borrow::Cow, ffi::OsString}; pub fn list( @@ -70,23 +70,4 @@ pub(crate) mod function { .context("Need committish as starting point")? .id()) } - - struct HexId<'a>(gix::Id<'a>, bool); - - impl<'a> HexId<'a> { - pub fn new(id: gix::Id<'a>, long_hex: bool) -> Self { - HexId(id, long_hex) - } - } - - impl std::fmt::Display for HexId<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - let HexId(id, long_hex) = self; - if *long_hex { - id.fmt(f) - } else { - id.shorten_or_id().fmt(f) - } - } - } } diff --git a/gitoxide-core/src/repository/mod.rs b/gitoxide-core/src/repository/mod.rs index 5b51e5c1ac3..8158f7cf0b6 100644 --- a/gitoxide-core/src/repository/mod.rs +++ b/gitoxide-core/src/repository/mod.rs @@ -1,22 +1,9 @@ +use std::fmt::Formatter; use std::path::PathBuf; use anyhow::{Context as AnyhowContext, Result}; use gix::bstr::BString; -pub fn init(directory: Option) -> Result { - gix::create::into( - directory.unwrap_or_default(), - gix::create::Kind::WithWorktree, - gix::create::Options::default(), - ) - .with_context(|| "Repository initialization failed") -} - -pub enum PathsOrPatterns { - Paths(Box>), - Patterns(Vec), -} - #[cfg(feature = "archive")] pub mod archive; pub mod cat; @@ -60,3 +47,36 @@ pub mod submodule; pub mod tree; pub mod verify; pub mod worktree; + +pub fn init(directory: Option) -> Result { + gix::create::into( + directory.unwrap_or_default(), + gix::create::Kind::WithWorktree, + gix::create::Options::default(), + ) + .with_context(|| "Repository initialization failed") +} + +pub enum PathsOrPatterns { + Paths(Box>), + Patterns(Vec), +} + +struct HexId<'a>(gix::Id<'a>, bool); + +impl<'a> HexId<'a> { + pub fn new(id: gix::Id<'a>, long_hex: bool) -> Self { + HexId(id, long_hex) + } +} + +impl std::fmt::Display for HexId<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let HexId(id, long_hex) = self; + if *long_hex { + id.fmt(f) + } else { + id.shorten_or_id().fmt(f) + } + } +} diff --git a/gitoxide-core/src/repository/revision/list.rs b/gitoxide-core/src/repository/revision/list.rs index c47f1bc3b27..87997f41f27 100644 --- a/gitoxide-core/src/repository/revision/list.rs +++ b/gitoxide-core/src/repository/revision/list.rs @@ -7,6 +7,7 @@ pub struct Context { pub spec: OsString, pub format: OutputFormat, pub text: Format, + pub long_hashes: bool, } pub enum Format { @@ -16,7 +17,10 @@ pub enum Format { pub const PROGRESS_RANGE: std::ops::RangeInclusive = 0..=2; pub(crate) mod function { + use crate::repository::HexId; + use crate::{repository::revision::list::Format, OutputFormat}; use anyhow::{bail, Context}; + use gix::odb::store::RefreshMode; use gix::{hashtable::HashMap, revision::walk::Sorting, Progress}; use layout::{ backends::svg::SVGWriter, @@ -24,8 +28,6 @@ pub(crate) mod function { std_shapes::shapes::{Arrow, Element, ShapeKind}, }; - use crate::{repository::revision::list::Format, OutputFormat}; - pub fn list( mut repo: gix::Repository, mut progress: impl Progress, @@ -35,12 +37,14 @@ pub(crate) mod function { format, text, limit, + long_hashes, }: super::Context, ) -> anyhow::Result<()> { if format != OutputFormat::Human { bail!("Only human output is currently supported"); } repo.object_cache_size_if_unset(4 * 1024 * 1024); + repo.objects.refresh = RefreshMode::Never; let spec = gix::path::os_str_into_bstr(&spec)?; let id = repo @@ -101,7 +105,7 @@ pub(crate) mod function { writeln!( out, "{} {} {}", - commit.id().shorten_or_id(), + HexId::new(commit.id(), long_hashes), commit.commit_time.expect("traversal with date"), commit.parent_ids.len() )?; diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index aedee5cc052..fd88efa87a5 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -1148,7 +1148,12 @@ pub fn main() -> Result<()> { }, ), Subcommands::Revision(cmd) => match cmd { - revision::Subcommands::List { spec, svg, limit } => prepare_and_run( + revision::Subcommands::List { + spec, + svg, + limit, + long_hashes, + } => prepare_and_run( "revision-list", trace, auto_verbose, @@ -1164,6 +1169,7 @@ pub fn main() -> Result<()> { limit, spec, format, + long_hashes, text: svg.map_or(core::repository::revision::list::Format::Text, |path| { core::repository::revision::list::Format::Svg { path } }), diff --git a/src/plumbing/options/mod.rs b/src/plumbing/options/mod.rs index f0d02c2c6bc..de96b378c85 100644 --- a/src/plumbing/options/mod.rs +++ b/src/plumbing/options/mod.rs @@ -996,6 +996,9 @@ pub mod revision { /// List all commits reachable from the given rev-spec. #[clap(visible_alias = "l")] List { + /// Display long hashes, instead of expensively shortened versions for best performance. + #[clap(long, short = 'l')] + long_hashes: bool, /// How many commits to list at most. #[clap(long, short = 'l')] limit: Option,