Skip to content

Commit

Permalink
feat: gix tree entries with rev-spec support.
Browse files Browse the repository at this point in the history
Previously it wanted a tree-id, now it can derive it itself.
  • Loading branch information
Byron committed Feb 22, 2023
1 parent a3c283f commit 49520d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions gitoxide-core/src/repository/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{borrow::Cow, io};

use anyhow::bail;

use gix::{prelude::ObjectIdExt, Tree};
use gix::Tree;

use crate::OutputFormat;

Expand Down Expand Up @@ -176,13 +176,10 @@ pub fn entries(
}

fn treeish_to_tree<'repo>(treeish: Option<&str>, repo: &'repo gix::Repository) -> anyhow::Result<Tree<'repo>> {
Ok(match treeish {
Some(hex) => gix::hash::ObjectId::from_hex(hex.as_bytes())
.map(|id| id.attach(repo))?
.object()?
.try_into_tree()?,
None => repo.head()?.peel_to_commit_in_place()?.tree()?,
})
let spec = treeish
.map(|spec| format!("{spec}^{{tree}}"))
.unwrap_or_else(|| "@^{tree}".into());
Ok(repo.rev_parse_single(spec.as_str())?.object()?.into_tree())
}

fn format_entry(
Expand Down
4 changes: 2 additions & 2 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ pub mod tree {
#[clap(long, short = 'e')]
extended: bool,

/// The tree to traverse, or the tree at `HEAD` if unspecified.
/// The revspec of the tree to traverse, or the tree at `HEAD` if unspecified.
treeish: Option<String>,
},
/// Provide information about a tree.
Info {
/// Provide files size as well. This is expensive as the object is decoded entirely.
#[clap(long, short = 'e')]
extended: bool,
/// The tree to traverse, or the tree at `HEAD` if unspecified.
/// The revspec of the tree to traverse, or the tree at `HEAD` if unspecified.
treeish: Option<String>,
},
}
Expand Down

0 comments on commit 49520d1

Please sign in to comment.