Skip to content

Commit ff99a18

Browse files
committed
Merge branch 'fix-1096'
2 parents 1f9aca5 + 203d69c commit ff99a18

File tree

31 files changed

+420
-335
lines changed

31 files changed

+420
-335
lines changed

examples/ls-tree.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
use std::io::{stdout, Write};
22

33
use clap::Parser;
4-
use gix::{
5-
bstr::BString,
6-
objs::tree::{EntryMode, EntryMode::Tree},
7-
traverse::tree::Recorder,
8-
ObjectId,
9-
};
4+
use gix::{bstr::BString, objs::tree::EntryMode, traverse::tree::Recorder, ObjectId};
105

116
fn main() {
127
let args = Args::parse_from(gix::env::args_os());
@@ -43,14 +38,14 @@ fn run(args: Args) -> anyhow::Result<()> {
4338
recorder
4439
.records
4540
.into_iter()
46-
.filter(|entry| args.tree_recursing || args.tree_only || entry.mode != Tree)
47-
.filter(|entry| !args.tree_only || (entry.mode == Tree))
41+
.filter(|entry| args.tree_recursing || args.tree_only || entry.mode.is_no_tree())
42+
.filter(|entry| !args.tree_only || (entry.mode.is_tree()))
4843
.map(|entry| Entry::new(entry.mode, entry.oid, entry.filepath))
4944
.collect::<Vec<_>>()
5045
} else {
5146
tree.iter()
5247
.filter_map(|res| res.ok().map(|entry| entry.inner)) // dropping errors silently
53-
.filter(|entry| !args.tree_only || (entry.mode == Tree))
48+
.filter(|entry| !args.tree_only || (entry.mode.is_tree()))
5449
.map(|entry| Entry::new(entry.mode, entry.oid.to_owned(), entry.filename.to_owned()))
5550
.collect::<Vec<_>>()
5651
};
@@ -60,8 +55,8 @@ fn run(args: Args) -> anyhow::Result<()> {
6055
writeln!(
6156
out,
6257
"{:06o} {:4} {} {}",
63-
entry.kind as u16,
64-
entry.kind.as_str(),
58+
*entry.mode,
59+
entry.mode.as_str(),
6560
entry.hash,
6661
entry.path
6762
)?;
@@ -71,13 +66,13 @@ fn run(args: Args) -> anyhow::Result<()> {
7166
}
7267

7368
struct Entry {
74-
kind: EntryMode,
69+
mode: EntryMode,
7570
hash: ObjectId,
7671
path: BString,
7772
}
7873

7974
impl Entry {
80-
fn new(kind: EntryMode, hash: ObjectId, path: BString) -> Self {
81-
Self { kind, hash, path }
75+
fn new(mode: EntryMode, hash: ObjectId, path: BString) -> Self {
76+
Self { mode, hash, path }
8277
}
8378
}

gitoxide-core/src/repository/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn stream(
4040
for (path, content) in files {
4141
stream.add_entry(gix::worktree::stream::AdditionalEntry {
4242
id: gix::hash::Kind::Sha1.null(),
43-
mode: gix::object::tree::EntryMode::Blob,
43+
mode: gix::object::tree::EntryKind::Blob.into(),
4444
relative_path: path.into(),
4545
source: gix::worktree::stream::entry::Source::Memory(content.into()),
4646
});

gitoxide-core/src/repository/tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ mod entries {
8989
}
9090

9191
fn visit_nontree(&mut self, entry: &EntryRef<'_>) -> Action {
92-
use gix::objs::tree::EntryMode::*;
9392
let size = self
9493
.repo
9594
.and_then(|repo| repo.find_object(entry.oid).map(|o| o.data.len()).ok());
@@ -100,7 +99,8 @@ mod entries {
10099
self.stats.num_bytes += size as u64;
101100
}
102101

103-
match entry.mode {
102+
use gix::object::tree::EntryKind::*;
103+
match entry.mode.kind() {
104104
Commit => self.stats.num_submodules += 1,
105105
Blob => self.stats.num_blobs += 1,
106106
BlobExecutable => self.stats.num_blobs_exec += 1,
@@ -184,11 +184,11 @@ fn format_entry(
184184
filename: &gix::bstr::BStr,
185185
size: Option<usize>,
186186
) -> std::io::Result<()> {
187-
use gix::objs::tree::EntryMode::*;
187+
use gix::objs::tree::EntryKind::*;
188188
writeln!(
189189
out,
190190
"{} {}{} {}",
191-
match entry.mode {
191+
match entry.mode.kind() {
192192
Tree => "TREE",
193193
Blob => "BLOB",
194194
BlobExecutable => " EXE",

gix-archive/src/write.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,19 @@ fn append_zip_entry<W: std::io::Write + std::io::Seek>(
169169
.compression_level(compression_level)
170170
.large_file(entry.bytes_remaining().map_or(true, |len| len > u32::MAX as usize))
171171
.last_modified_time(mtime)
172-
.unix_permissions(if matches!(entry.mode, gix_object::tree::EntryMode::BlobExecutable) {
173-
0o755
174-
} else {
175-
0o644
176-
});
172+
.unix_permissions(if entry.mode.is_executable() { 0o755 } else { 0o644 });
177173
let path = add_prefix(entry.relative_path(), tree_prefix).into_owned();
178-
match entry.mode {
179-
gix_object::tree::EntryMode::Blob | gix_object::tree::EntryMode::BlobExecutable => {
174+
match entry.mode.kind() {
175+
gix_object::tree::EntryKind::Blob | gix_object::tree::EntryKind::BlobExecutable => {
180176
ar.start_file(path.to_string(), file_opts)
181177
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
182178
std::io::copy(&mut entry, ar)?;
183179
}
184-
gix_object::tree::EntryMode::Tree | gix_object::tree::EntryMode::Commit => {
180+
gix_object::tree::EntryKind::Tree | gix_object::tree::EntryKind::Commit => {
185181
ar.add_directory(path.to_string(), file_opts)
186182
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
187183
}
188-
gix_object::tree::EntryMode::Link => {
184+
gix_object::tree::EntryKind::Link => {
189185
use bstr::ByteSlice;
190186
std::io::copy(&mut entry, buf)?;
191187
ar.add_symlink(path.to_string(), buf.as_bstr().to_string(), file_opts)
@@ -206,18 +202,14 @@ fn append_tar_entry<W: std::io::Write>(
206202
let mut header = tar::Header::new_gnu();
207203
header.set_mtime(mtime_seconds_since_epoch as u64);
208204
header.set_entry_type(tar_entry_type(entry.mode));
209-
header.set_mode(if matches!(entry.mode, gix_object::tree::EntryMode::BlobExecutable) {
210-
0o755
211-
} else {
212-
0o644
213-
});
205+
header.set_mode(if entry.mode.is_executable() { 0o755 } else { 0o644 });
214206
buf.clear();
215207
std::io::copy(&mut entry, buf)?;
216208

217209
let path = gix_path::from_bstr(add_prefix(entry.relative_path(), opts.tree_prefix.as_ref()));
218210
header.set_size(buf.len() as u64);
219211

220-
if entry.mode == gix_object::tree::EntryMode::Link {
212+
if entry.mode.is_link() {
221213
use bstr::ByteSlice;
222214
let target = gix_path::from_bstr(buf.as_bstr());
223215
header.set_entry_type(tar::EntryType::Symlink);
@@ -231,13 +223,13 @@ fn append_tar_entry<W: std::io::Write>(
231223

232224
#[cfg(any(feature = "tar", feature = "tar_gz"))]
233225
fn tar_entry_type(mode: gix_object::tree::EntryMode) -> tar::EntryType {
234-
use gix_object::tree::EntryMode;
226+
use gix_object::tree::EntryKind;
235227
use tar::EntryType;
236-
match mode {
237-
EntryMode::Tree | EntryMode::Commit => EntryType::Directory,
238-
EntryMode::Blob => EntryType::Regular,
239-
EntryMode::BlobExecutable => EntryType::Regular,
240-
EntryMode::Link => EntryType::Link,
228+
match mode.kind() {
229+
EntryKind::Tree | EntryKind::Commit => EntryType::Directory,
230+
EntryKind::Blob => EntryType::Regular,
231+
EntryKind::BlobExecutable => EntryType::Regular,
232+
EntryKind::Link => EntryType::Link,
241233
}
242234
}
243235

gix-archive/tests/archive.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod from_tree {
88

99
use gix_archive::Format;
1010
use gix_attributes::glob::pattern::Case;
11-
use gix_object::tree::EntryMode;
11+
use gix_object::tree::EntryKind;
1212
use gix_testtools::bstr::ByteSlice;
1313
use gix_worktree::stack::state::attributes::Source;
1414

@@ -22,32 +22,32 @@ mod from_tree {
2222
let mut stream = gix_worktree_stream::Stream::from_read(std::io::Cursor::new(buf));
2323
let mut paths_and_modes = Vec::new();
2424
while let Some(mut entry) = stream.next_entry().expect("entry retrieval does not fail") {
25-
paths_and_modes.push((entry.relative_path().to_owned(), entry.mode, entry.id));
25+
paths_and_modes.push((entry.relative_path().to_owned(), entry.mode.kind(), entry.id));
2626
let mut buf = Vec::new();
2727
entry.read_to_end(&mut buf).expect("stream can always be read");
2828
}
2929

3030
let expected_link_mode = if cfg!(windows) {
31-
EntryMode::Blob
31+
EntryKind::Blob
3232
} else {
33-
EntryMode::Link
33+
EntryKind::Link
3434
};
3535
let expected_exe_mode = if cfg!(windows) {
36-
EntryMode::Blob
36+
EntryKind::Blob
3737
} else {
38-
EntryMode::BlobExecutable
38+
EntryKind::BlobExecutable
3939
};
4040
assert_eq!(
4141
paths_and_modes,
4242
&[
4343
(
4444
".gitattributes".into(),
45-
EntryMode::Blob,
45+
EntryKind::Blob,
4646
hex_to_id("45c160c35c17ad264b96431cceb9793160396e99")
4747
),
4848
(
4949
"a".into(),
50-
EntryMode::Blob,
50+
EntryKind::Blob,
5151
hex_to_id("45b983be36b73c0788dc9cbcb76cbb80fc7bb057")
5252
),
5353
(
@@ -61,7 +61,7 @@ mod from_tree {
6161
),
6262
(
6363
"dir/b".into(),
64-
EntryMode::Blob,
64+
EntryKind::Blob,
6565
hex_to_id("ab4a98190cf776b43cb0fe57cef231fb93fd07e6")
6666
),
6767
(
@@ -71,7 +71,7 @@ mod from_tree {
7171
),
7272
(
7373
"extra-file".into(),
74-
EntryMode::Blob,
74+
EntryKind::Blob,
7575
hex_to_id("0000000000000000000000000000000000000000")
7676
),
7777
(
@@ -81,7 +81,7 @@ mod from_tree {
8181
),
8282
(
8383
"extra-dir-empty".into(),
84-
EntryMode::Tree,
84+
EntryKind::Tree,
8585
hex_to_id("0000000000000000000000000000000000000000")
8686
),
8787
(

gix-diff/src/tree/changes.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,8 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>(
250250
queue: &mut VecDeque<TreeInfoPair>,
251251
delegate: &mut R,
252252
) -> Result<(), Error> {
253-
use gix_object::tree::EntryMode::*;
254-
match (lhs.mode, rhs.mode) {
255-
(Tree, Tree) => {
253+
match (lhs.mode.is_tree(), rhs.mode.is_tree()) {
254+
(true, true) => {
256255
delegate.push_back_tracked_path_component(lhs.filename);
257256
if lhs.oid != rhs.oid
258257
&& delegate
@@ -268,7 +267,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>(
268267
}
269268
queue.push_back((Some(lhs.oid.to_owned()), Some(rhs.oid.to_owned())));
270269
}
271-
(_, Tree) => {
270+
(_, true) => {
272271
delegate.push_back_tracked_path_component(lhs.filename);
273272
if delegate
274273
.visit(Change::Deletion {
@@ -290,7 +289,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>(
290289
};
291290
queue.push_back((None, Some(rhs.oid.to_owned())));
292291
}
293-
(Tree, _) => {
292+
(true, _) => {
294293
delegate.push_back_tracked_path_component(lhs.filename);
295294
if delegate
296295
.visit(Change::Deletion {
@@ -312,9 +311,9 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>(
312311
};
313312
queue.push_back((Some(lhs.oid.to_owned()), None));
314313
}
315-
(lhs_non_tree, rhs_non_tree) => {
314+
(false, false) => {
316315
delegate.push_path_component(lhs.filename);
317-
debug_assert!(lhs_non_tree.is_no_tree() && rhs_non_tree.is_no_tree());
316+
debug_assert!(lhs.mode.is_no_tree() && lhs.mode.is_no_tree());
318317
if lhs.oid != rhs.oid
319318
&& delegate
320319
.visit(Change::Modification {
@@ -342,7 +341,7 @@ fn peekable<I: Iterator>(iter: I) -> IteratorType<I> {
342341
mod tests {
343342
use std::cmp::Ordering;
344343

345-
use gix_object::tree::EntryMode;
344+
use gix_object::tree::EntryKind;
346345

347346
use super::*;
348347

@@ -351,25 +350,25 @@ mod tests {
351350
let null = gix_hash::ObjectId::null(gix_hash::Kind::Sha1);
352351
let actual = compare(
353352
&EntryRef {
354-
mode: EntryMode::Blob,
353+
mode: EntryKind::Blob.into(),
355354
filename: "plumbing-cli.rs".into(),
356355
oid: &null,
357356
},
358357
&EntryRef {
359-
mode: EntryMode::Tree,
358+
mode: EntryKind::Tree.into(),
360359
filename: "plumbing".into(),
361360
oid: &null,
362361
},
363362
);
364363
assert_eq!(actual, Ordering::Less);
365364
let actual = compare(
366365
&EntryRef {
367-
mode: EntryMode::Tree,
366+
mode: EntryKind::Tree.into(),
368367
filename: "plumbing-cli.rs".into(),
369368
oid: &null,
370369
},
371370
&EntryRef {
372-
mode: EntryMode::Blob,
371+
mode: EntryKind::Blob.into(),
373372
filename: "plumbing".into(),
374373
oid: &null,
375374
},

0 commit comments

Comments
 (0)