|
1 |
| -use bitflags::bitflags; |
2 |
| - |
3 |
| -// TODO: we essentially treat this as an enum withj the only exception being |
4 |
| -// that `FILE_EXECUTABLE.contains(FILE)` works might want to turn this into an |
5 |
| -// enum proper |
6 |
| -bitflags! { |
7 |
| - /// The kind of file of an entry. |
8 |
| - #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
9 |
| - pub struct Mode: u32 { |
10 |
| - /// directory (only used for sparse checkouts), equivalent to a tree, which is _excluded_ from the index via |
11 |
| - /// cone-mode. |
12 |
| - const DIR = 0o040000; |
13 |
| - /// regular file |
14 |
| - const FILE = 0o100644; |
15 |
| - /// regular file, executable |
16 |
| - const FILE_EXECUTABLE = 0o100755; |
17 |
| - /// Symbolic link |
18 |
| - const SYMLINK = 0o120000; |
19 |
| - /// A git commit for submodules |
20 |
| - const COMMIT = 0o160000; |
21 |
| - } |
22 |
| -} |
| 1 | +use crate::entry::Mode; |
23 | 2 |
|
24 | 3 | #[cfg(unix)]
|
25 | 4 | /// Returns whether a a file has the executable permission set
|
26 |
| -pub fn is_executable(metadata: &std::fs::Metadata) -> bool { |
| 5 | +fn is_executable(metadata: &std::fs::Metadata) -> bool { |
27 | 6 | use std::os::unix::fs::MetadataExt;
|
28 | 7 | (metadata.mode() & 0o100) != 0
|
29 | 8 | }
|
30 | 9 |
|
31 | 10 | #[cfg(not(unix))]
|
32 | 11 | /// Returns whether a a file has the executable permission set
|
33 |
| -pub fn is_executable(_metadata: &std::fs::Metadata) -> bool { |
| 12 | +fn is_executable(_metadata: &std::fs::Metadata) -> bool { |
34 | 13 | false
|
35 | 14 | }
|
36 | 15 |
|
@@ -80,11 +59,16 @@ pub enum Change {
|
80 | 59 | }
|
81 | 60 |
|
82 | 61 | impl Change {
|
83 |
| - /// Applies this change to a `Mode` |
84 |
| - pub fn apply(self, mode: &mut Mode) { |
85 |
| - *mode = match self { |
| 62 | + /// Applies this change to a `Mode` by updating it in place |
| 63 | + pub fn update(self, mode: &mut Mode) { |
| 64 | + *mode = self.apply(*mode); |
| 65 | + } |
| 66 | + |
| 67 | + /// Applies this change to a `Mode` by updating it in place |
| 68 | + pub fn apply(self, mode: Mode) -> Mode { |
| 69 | + match self { |
86 | 70 | Change::Type { new_mode } => new_mode,
|
87 |
| - Change::ExecutableBit => match *mode { |
| 71 | + Change::ExecutableBit => match mode { |
88 | 72 | Mode::FILE => Mode::FILE_EXECUTABLE,
|
89 | 73 | Mode::FILE_EXECUTABLE => Mode::FILE,
|
90 | 74 | _ => unreachable!("invalid mode change: can't flip executable bit of {mode:?}"),
|
|
0 commit comments