Skip to content

Commit 14d6b8d

Browse files
authored
Merge pull request #1818 from EliahKagan/from-fs-doc
Expand `from_fs` doc
2 parents ffb73b5 + 426c669 commit 14d6b8d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

gix-index/src/entry/stat.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ impl Stat {
7575
}
7676
}
7777

78-
/// Creates stat information from the result of `symlink_metadata`.
78+
/// Creates stat information from file metadata.
79+
///
80+
/// The information passed to this function should originate from a function like
81+
/// `symlink_metadata`/`lstat` or `File::metadata`/`fstat`.
82+
///
83+
/// The data are adjusted for use in the index, using default values of fields that are not
84+
/// meaningful on the target operating system or that are unavailable, and truncating data
85+
/// where doing so does not lose essential information for keeping track of file status.
7986
pub fn from_fs(stat: &crate::fs::Metadata) -> Result<Stat, SystemTimeError> {
8087
let mtime = stat.modified().unwrap_or(std::time::UNIX_EPOCH);
8188
let ctime = stat.created().unwrap_or(std::time::UNIX_EPOCH);
@@ -88,23 +95,22 @@ impl Stat {
8895
ino: 0,
8996
uid: 0,
9097
gid: 0,
91-
// truncation to 32 bits is on purpose (git does the same).
98+
// Truncation to 32 bits is on purpose (git does the same).
9299
size: stat.len() as u32,
93100
};
94101
#[cfg(not(windows))]
95102
let res = {
96103
Stat {
97104
mtime: mtime.try_into().unwrap_or_default(),
98105
ctime: ctime.try_into().unwrap_or_default(),
99-
// truncating to 32 bits is fine here because
100-
// that's what the linux syscalls returns
101-
// just rust upcasts to 64 bits for some reason?
102-
// numbers this large are impractical anyway (that's a lot of hard-drives).
106+
// Truncating the device and inode numbers to 32 bits should be fine even on
107+
// targets where they are represented as 64 bits, since we do not use them
108+
// precisely for tracking changes and we do not map them back to the inode.
103109
dev: stat.dev() as u32,
104110
ino: stat.ino() as u32,
105111
uid: stat.uid(),
106112
gid: stat.gid(),
107-
// truncation to 32 bits is on purpose (git does the same).
113+
// Truncation to 32 bits is on purpose (git does the same).
108114
size: stat.len() as u32,
109115
}
110116
};

0 commit comments

Comments
 (0)