Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49520d1

Browse files
committed
feat: gix tree entries with rev-spec support.
Previously it wanted a tree-id, now it can derive it itself.
1 parent a3c283f commit 49520d1

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

gitoxide-core/src/repository/tree.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{borrow::Cow, io};
22

33
use anyhow::bail;
44

5-
use gix::{prelude::ObjectIdExt, Tree};
5+
use gix::Tree;
66

77
use crate::OutputFormat;
88

@@ -176,13 +176,10 @@ pub fn entries(
176176
}
177177

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

188185
fn format_entry(

src/plumbing/options/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ pub mod tree {
253253
#[clap(long, short = 'e')]
254254
extended: bool,
255255

256-
/// The tree to traverse, or the tree at `HEAD` if unspecified.
256+
/// The revspec of the tree to traverse, or the tree at `HEAD` if unspecified.
257257
treeish: Option<String>,
258258
},
259259
/// Provide information about a tree.
260260
Info {
261261
/// Provide files size as well. This is expensive as the object is decoded entirely.
262262
#[clap(long, short = 'e')]
263263
extended: bool,
264-
/// The tree to traverse, or the tree at `HEAD` if unspecified.
264+
/// The revspec of the tree to traverse, or the tree at `HEAD` if unspecified.
265265
treeish: Option<String>,
266266
},
267267
}

0 commit comments

Comments
 (0)