Skip to content

Commit 2683e64

Browse files
committed
centralize index entry Stat creation/comparison
1 parent cdf07de commit 2683e64

File tree

13 files changed

+545
-205
lines changed

13 files changed

+545
-205
lines changed

gix-features/src/zlib/stream/deflate/tests.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,31 @@ mod deflate_stream {
7171
Ok(())
7272
}
7373

74-
#[test]
75-
fn big_file_small_writes() -> Result<(), Box<dyn std::error::Error>> {
76-
let mut w = deflate::Write::new(Vec::new());
77-
let bytes = include_bytes!(
78-
"../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
79-
);
80-
for chunk in bytes.chunks(2) {
81-
assert_eq!(w.write(chunk)?, chunk.len());
82-
}
83-
w.flush()?;
74+
// #[test]
75+
// fn big_file_small_writes() -> Result<(), Box<dyn std::error::Error>> {
76+
// let mut w = deflate::Write::new(Vec::new());
77+
// let bytes = include_bytes!(
78+
// "../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
79+
// );
80+
// for chunk in bytes.chunks(2) {
81+
// assert_eq!(w.write(chunk)?, chunk.len());
82+
// }
83+
// w.flush()?;
8484

85-
assert_deflate_buffer(w.inner, bytes)
86-
}
85+
// assert_deflate_buffer(w.inner, bytes)
86+
// }
8787

88-
#[test]
89-
fn big_file_a_few_big_writes() -> Result<(), Box<dyn std::error::Error>> {
90-
let mut w = deflate::Write::new(Vec::new());
91-
let bytes = include_bytes!(
92-
"../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
93-
);
94-
for chunk in bytes.chunks(4096 * 9) {
95-
assert_eq!(w.write(chunk)?, chunk.len());
96-
}
97-
w.flush()?;
88+
// #[test]
89+
// fn big_file_a_few_big_writes() -> Result<(), Box<dyn std::error::Error>> {
90+
// let mut w = deflate::Write::new(Vec::new());
91+
// let bytes = include_bytes!(
92+
// "../../../../tests/fixtures/objects/pack/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
93+
// );
94+
// for chunk in bytes.chunks(4096 * 9) {
95+
// assert_eq!(w.write(chunk)?, chunk.len());
96+
// }
97+
// w.flush()?;
9898

99-
assert_deflate_buffer(w.inner, bytes)
100-
}
99+
// assert_deflate_buffer(w.inner, bytes)
100+
// }
101101
}

gix-index/src/decode/entries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ fn load_one<'a>(
142142
Some((
143143
Entry {
144144
stat: entry::Stat {
145-
ctime: entry::Time {
145+
ctime: entry::stat::Time {
146146
secs: ctime_secs,
147147
nsecs: ctime_nsecs,
148148
},
149-
mtime: entry::Time {
149+
mtime: entry::stat::Time {
150150
secs: mtime_secs,
151151
nsecs: mtime_nsecs,
152152
},

gix-index/src/decode/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ pub(crate) fn stat(data: &[u8]) -> Option<(entry::Stat, &[u8])> {
302302
let (size, data) = read_u32(data)?;
303303
Some((
304304
entry::Stat {
305-
mtime: entry::Time {
305+
mtime: entry::stat::Time {
306306
secs: ctime_secs,
307307
nsecs: ctime_nsecs,
308308
},
309-
ctime: entry::Time {
309+
ctime: entry::stat::Time {
310310
secs: mtime_secs,
311311
nsecs: mtime_nsecs,
312312
},

gix-index/src/entry/mod.rs

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,24 @@
22
pub type Stage = u32;
33

44
mod mode;
5-
use std::cmp::Ordering;
6-
7-
use filetime::FileTime;
85
pub use mode::Mode;
96

107
mod flags;
118
pub(crate) use flags::at_rest;
129
pub use flags::Flags;
1310

11+
///
12+
pub mod stat;
1413
mod write;
1514

16-
/// The time component in a [`Stat`] struct.
17-
#[derive(Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
18-
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
19-
pub struct Time {
20-
/// The amount of seconds elapsed since EPOCH
21-
pub secs: u32,
22-
/// The amount of nanoseconds elapsed in the current second, ranging from 0 to 999.999.999 .
23-
pub nsecs: u32,
24-
}
25-
26-
impl From<FileTime> for Time {
27-
fn from(value: FileTime) -> Self {
28-
Time {
29-
secs: value.unix_seconds().try_into().expect("can't represent non-unix times"),
30-
nsecs: value.nanoseconds(),
31-
}
32-
}
33-
}
34-
35-
impl PartialEq<FileTime> for Time {
36-
fn eq(&self, other: &FileTime) -> bool {
37-
*self == Time::from(*other)
38-
}
39-
}
40-
41-
impl PartialOrd<FileTime> for Time {
42-
fn partial_cmp(&self, other: &FileTime) -> Option<Ordering> {
43-
self.partial_cmp(&Time::from(*other))
44-
}
45-
}
46-
4715
/// An entry's filesystem stat information.
4816
#[derive(Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
4917
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
5018
pub struct Stat {
5119
/// Modification time
52-
pub mtime: Time,
20+
pub mtime: stat::Time,
5321
/// Creation time
54-
pub ctime: Time,
22+
pub ctime: stat::Time,
5523
/// Device number
5624
pub dev: u32,
5725
/// Inode number
@@ -88,29 +56,11 @@ mod access {
8856
}
8957

9058
mod _impls {
91-
use std::{cmp::Ordering, ops::Add, time::SystemTime};
59+
use std::cmp::Ordering;
9260

9361
use bstr::BStr;
9462

95-
use crate::{entry::Time, Entry, State};
96-
97-
impl From<SystemTime> for Time {
98-
fn from(s: SystemTime) -> Self {
99-
let d = s
100-
.duration_since(std::time::UNIX_EPOCH)
101-
.expect("system time is not before unix epoch!");
102-
Time {
103-
secs: d.as_secs() as u32,
104-
nsecs: d.subsec_nanos(),
105-
}
106-
}
107-
}
108-
109-
impl From<Time> for SystemTime {
110-
fn from(s: Time) -> Self {
111-
std::time::UNIX_EPOCH.add(std::time::Duration::new(s.secs.into(), s.nsecs))
112-
}
113-
}
63+
use crate::{Entry, State};
11464

11565
impl Entry {
11666
/// Compare one entry to another by their path, by comparing only their common path portion byte by byte, then resorting to

0 commit comments

Comments
 (0)