Skip to content

Commit 433b409

Browse files
committed
fix: gix tree entries now uses a depth-first traversal.
This makes the result similar to `git ls-tree` in terms of ordering.
1 parent 201e853 commit 433b409

File tree

1 file changed

+12
-11
lines changed
  • gitoxide-core/src/repository

1 file changed

+12
-11
lines changed

gitoxide-core/src/repository/tree.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
use std::{borrow::Cow, io};
2-
31
use anyhow::bail;
42
use gix::Tree;
3+
use std::io::BufWriter;
4+
use std::{borrow::Cow, io};
55

66
use crate::OutputFormat;
77

88
mod entries {
9-
use std::collections::VecDeque;
10-
119
use gix::{
1210
bstr::{BStr, BString, ByteSlice, ByteVec},
1311
objs::tree::EntryRef,
1412
traverse::tree::visit::Action,
1513
};
14+
use std::collections::VecDeque;
1615

1716
use crate::repository::tree::format_entry;
1817

@@ -161,8 +160,9 @@ pub fn entries(
161160
let tree = treeish_to_tree(treeish, &repo)?;
162161

163162
if recursive {
164-
let mut delegate = entries::Traverse::new(extended.then_some(&repo), Some(&mut out));
165-
tree.traverse().breadthfirst(&mut delegate)?;
163+
let mut write = BufWriter::new(out);
164+
let mut delegate = entries::Traverse::new(extended.then_some(&repo), Some(&mut write));
165+
tree.traverse().depthfirst(&mut delegate)?;
166166
} else {
167167
for entry in tree.iter() {
168168
let entry = entry?;
@@ -190,9 +190,9 @@ fn format_entry(
190190
size: Option<u64>,
191191
) -> std::io::Result<()> {
192192
use gix::objs::tree::EntryKind::*;
193-
writeln!(
193+
write!(
194194
out,
195-
"{} {}{} {}",
195+
"{} {}{} ",
196196
match entry.mode.kind() {
197197
Tree => "TREE",
198198
Blob => "BLOB",
@@ -201,7 +201,8 @@ fn format_entry(
201201
Commit => "SUBM",
202202
},
203203
entry.oid,
204-
size.map_or_else(|| "".into(), |s| Cow::Owned(format!(" {s}"))),
205-
filename
206-
)
204+
size.map_or_else(|| "".into(), |s| Cow::Owned(format!(" {s}")))
205+
)?;
206+
out.write_all(filename)?;
207+
out.write_all(b"\n")
207208
}

0 commit comments

Comments
 (0)