Mercurial > hg
annotate rust/hg-core/src/dirstate/entry.rs @ 52302:db065b33fa56
rust-dirstate: merge `dirstate_tree` module into `dirstate`
The historical reasonning for `dirstate_tree` existing in the first place is
that a new approach was needed for the tree-like dirstate and it was easier
to start somewhat fresh. Now that the former dirstate is (long) gone, we
can merge those two modules to avoid the confusion that even the module
creators sometimes get.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 04 Nov 2024 11:00:58 +0100 |
parents | 0529e1a468dd |
children |
rev | line source |
---|---|
52302
db065b33fa56
rust-dirstate: merge `dirstate_tree` module into `dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
52055
diff
changeset
|
1 use crate::dirstate::on_disk::DirstateV2ParseError; |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
2 use crate::errors::HgError; |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
3 use bitflags::bitflags; |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
4 use std::fs; |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
5 use std::io; |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
6 use std::time::{SystemTime, UNIX_EPOCH}; |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
7 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
8 #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
9 pub enum EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
10 Normal, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
11 Added, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
12 Removed, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
13 Merged, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
14 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
15 |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
16 /// `size` and `mtime.seconds` are truncated to 31 bits. |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
17 /// |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
18 /// TODO: double-check status algorithm correctness for files |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
19 /// larger than 2 GiB or modified after 2038. |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
20 #[derive(Debug, Copy, Clone)] |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
21 pub struct DirstateEntry { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
22 pub(crate) flags: Flags, |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
23 mode_size: Option<(u32, u32)>, |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
24 mtime: Option<TruncatedTimestamp>, |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
25 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
26 |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
27 bitflags! { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
28 pub(crate) struct Flags: u8 { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
29 const WDIR_TRACKED = 1 << 0; |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
30 const P1_TRACKED = 1 << 1; |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
31 const P2_INFO = 1 << 2; |
48252
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
32 const HAS_FALLBACK_EXEC = 1 << 3; |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
33 const FALLBACK_EXEC = 1 << 4; |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
34 const HAS_FALLBACK_SYMLINK = 1 << 5; |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
35 const FALLBACK_SYMLINK = 1 << 6; |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
36 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
37 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
38 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
39 /// A Unix timestamp with nanoseconds precision |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
40 #[derive(Debug, Copy, Clone)] |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
41 pub struct TruncatedTimestamp { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
42 truncated_seconds: u32, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
43 /// Always in the `0 .. 1_000_000_000` range. |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
44 nanoseconds: u32, |
48401
995aaacb12d7
dirstate-item: make sure we set the mtime-second-ambiguous on v2 write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48400
diff
changeset
|
45 /// TODO this should be in DirstateEntry, but the current code needs |
995aaacb12d7
dirstate-item: make sure we set the mtime-second-ambiguous on v2 write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48400
diff
changeset
|
46 /// refactoring to use DirstateEntry instead of TruncatedTimestamp for |
995aaacb12d7
dirstate-item: make sure we set the mtime-second-ambiguous on v2 write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48400
diff
changeset
|
47 /// comparison. |
995aaacb12d7
dirstate-item: make sure we set the mtime-second-ambiguous on v2 write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48400
diff
changeset
|
48 pub second_ambiguous: bool, |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
49 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
50 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
51 impl TruncatedTimestamp { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
52 /// Constructs from a timestamp potentially outside of the supported range, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
53 /// and truncate the seconds components to its lower 31 bits. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
54 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
55 /// Panics if the nanoseconds components is not in the expected range. |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
56 pub fn new_truncate( |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
57 seconds: i64, |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
58 nanoseconds: u32, |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
59 second_ambiguous: bool, |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
60 ) -> Self { |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
61 assert!(nanoseconds < NSEC_PER_SEC); |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
62 Self { |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
63 truncated_seconds: seconds as u32 & RANGE_MASK_31BIT, |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
64 nanoseconds, |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
65 second_ambiguous, |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
66 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
67 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
68 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
69 /// Construct from components. Returns an error if they are not in the |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
70 /// expcted range. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
71 pub fn from_already_truncated( |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
72 truncated_seconds: u32, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
73 nanoseconds: u32, |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
74 second_ambiguous: bool, |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
75 ) -> Result<Self, DirstateV2ParseError> { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
76 if truncated_seconds & !RANGE_MASK_31BIT == 0 |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
77 && nanoseconds < NSEC_PER_SEC |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
78 { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
79 Ok(Self { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
80 truncated_seconds, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
81 nanoseconds, |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
82 second_ambiguous, |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
83 }) |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
84 } else { |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49139
diff
changeset
|
85 Err(DirstateV2ParseError::new("when reading datetime")) |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
86 } |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
87 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
88 |
48443
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
89 /// Returns a `TruncatedTimestamp` for the modification time of `metadata`. |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
90 /// |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
91 /// Propagates errors from `std` on platforms where modification time |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
92 /// is not available at all. |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
93 pub fn for_mtime_of(metadata: &fs::Metadata) -> io::Result<Self> { |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
94 #[cfg(unix)] |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
95 { |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
96 use std::os::unix::fs::MetadataExt; |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
97 let seconds = metadata.mtime(); |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
98 // i64Â -> u32 with value always in the `0 .. NSEC_PER_SEC` range |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
99 let nanoseconds = metadata.mtime_nsec().try_into().unwrap(); |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
100 Ok(Self::new_truncate(seconds, nanoseconds, false)) |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
101 } |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
102 #[cfg(not(unix))] |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
103 { |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
104 metadata.modified().map(Self::from) |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
105 } |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
106 } |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
107 |
48443
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
108 /// Like `for_mtime_of`, but may return `None` or a value with |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
109 /// `second_ambiguous` set if the mtime is not "reliable". |
48422
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
110 /// |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
111 /// A modification time is reliable if it is older than `boundary` (or |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
112 /// sufficiently in the future). |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
113 /// |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
114 /// Otherwise a concurrent modification might happens with the same mtime. |
48443
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
115 pub fn for_reliable_mtime_of( |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
116 metadata: &fs::Metadata, |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
117 boundary: &Self, |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
118 ) -> io::Result<Option<Self>> { |
52055
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
119 Ok(Self::for_mtime_of(metadata)?.for_reliable_mtime_of_self(boundary)) |
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
120 } |
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
121 |
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
122 /// See [`Self::for_reliable_mtime_of`] |
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
123 pub fn for_reliable_mtime_of_self(&self, boundary: &Self) -> Option<Self> { |
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
124 let mut new = *self; |
48422
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
125 // If the mtime of the ambiguous file is younger (or equal) to the |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
126 // starting point of the `status` walk, we cannot garantee that |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
127 // another, racy, write will not happen right after with the same mtime |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
128 // and we cannot cache the information. |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
129 // |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
130 // However if the mtime is far away in the future, this is likely some |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
131 // mismatch between the current clock and previous file system |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
132 // operation. So mtime more than one days in the future are considered |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
133 // fine. |
52055
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
134 let reliable = if self.truncated_seconds == boundary.truncated_seconds |
48443
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
135 { |
52055
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
136 new.second_ambiguous = true; |
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
137 self.nanoseconds != 0 |
48422
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
138 && boundary.nanoseconds != 0 |
52055
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
139 && self.nanoseconds < boundary.nanoseconds |
48422
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
140 } else { |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
141 // `truncated_seconds` is less than 2**31, |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
142 // so this does not overflow `u32`: |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
143 let one_day_later = boundary.truncated_seconds + 24 * 3600; |
52055
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
144 self.truncated_seconds < boundary.truncated_seconds |
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
145 || self.truncated_seconds > one_day_later |
48443
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
146 }; |
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
147 if reliable { |
52055
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
148 Some(new) |
48443
112184713852
rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents:
48422
diff
changeset
|
149 } else { |
52055
0529e1a468dd
rust-dirstate: make the reliable timestamp comparison more usable from outside
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
150 None |
48422
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
151 } |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
152 } |
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
153 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
154 /// The lower 31 bits of the number of seconds since the epoch. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
155 pub fn truncated_seconds(&self) -> u32 { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
156 self.truncated_seconds |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
157 } |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
158 |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
159 /// The sub-second component of this timestamp, in nanoseconds. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
160 /// Always in the `0 .. 1_000_000_000` range. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
161 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
162 /// This timestamp is after `(seconds, 0)` by this many nanoseconds. |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
163 pub fn nanoseconds(&self) -> u32 { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
164 self.nanoseconds |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
165 } |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
166 |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
167 /// Returns whether two timestamps are equal modulo 2**31 seconds. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
168 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
169 /// If this returns `true`, the original values converted from `SystemTime` |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
170 /// or given to `new_truncate` were very likely equal. A false positive is |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
171 /// possible if they were exactly a multiple of 2**31 seconds apart (around |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
172 /// 68 years). This is deemed very unlikely to happen by chance, especially |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
173 /// on filesystems that support sub-second precision. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
174 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
175 /// If someone is manipulating the modification times of some files to |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
176 /// intentionally make `hg status` return incorrect results, not truncating |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
177 /// wouldn’t help much since they can set exactly the expected timestamp. |
48262
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
178 /// |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
179 /// Sub-second precision is ignored if it is zero in either value. |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
180 /// Some APIs simply return zero when more precision is not available. |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
181 /// When comparing values from different sources, if only one is truncated |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
182 /// in that way, doing a simple comparison would cause many false |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
183 /// negatives. |
48257
f45d35950db6
dirstate: rename a `very_likely_equal` method to `likely_equal`
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
184 pub fn likely_equal(self, other: Self) -> bool { |
48399
af303ae33cd7
dirstate-item: implement the comparison logic for mtime-second-ambiguous
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
185 if self.truncated_seconds != other.truncated_seconds { |
af303ae33cd7
dirstate-item: implement the comparison logic for mtime-second-ambiguous
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
186 false |
af303ae33cd7
dirstate-item: implement the comparison logic for mtime-second-ambiguous
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
187 } else if self.nanoseconds == 0 || other.nanoseconds == 0 { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49919
diff
changeset
|
188 !self.second_ambiguous |
48399
af303ae33cd7
dirstate-item: implement the comparison logic for mtime-second-ambiguous
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
189 } else { |
af303ae33cd7
dirstate-item: implement the comparison logic for mtime-second-ambiguous
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
190 self.nanoseconds == other.nanoseconds |
af303ae33cd7
dirstate-item: implement the comparison logic for mtime-second-ambiguous
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
191 } |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
192 } |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
193 |
48257
f45d35950db6
dirstate: rename a `very_likely_equal` method to `likely_equal`
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
194 pub fn likely_equal_to_mtime_of( |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
195 self, |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
196 metadata: &fs::Metadata, |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
197 ) -> io::Result<bool> { |
48257
f45d35950db6
dirstate: rename a `very_likely_equal` method to `likely_equal`
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
198 Ok(self.likely_equal(Self::for_mtime_of(metadata)?)) |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
199 } |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
200 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
201 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
202 impl From<SystemTime> for TruncatedTimestamp { |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
203 fn from(system_time: SystemTime) -> Self { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
204 // On Unix, `SystemTime` is a wrapper for the `timespec` C struct: |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
205 // https://www.gnu.org/software/libc/manual/html_node/Time-Types.html#index-struct-timespec |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
206 // We want to effectively access its fields, but the Rust standard |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
207 // library does not expose them. The best we can do is: |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
208 let seconds; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
209 let nanoseconds; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
210 match system_time.duration_since(UNIX_EPOCH) { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
211 Ok(duration) => { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
212 seconds = duration.as_secs() as i64; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
213 nanoseconds = duration.subsec_nanos(); |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
214 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
215 Err(error) => { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
216 // `system_time` is before `UNIX_EPOCH`. |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
217 // We need to undo this algorithm: |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
218 // https://github.com/rust-lang/rust/blob/6bed1f0bc3cc50c10aab26d5f94b16a00776b8a5/library/std/src/sys/unix/time.rs#L40-L41 |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
219 let negative = error.duration(); |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
220 let negative_secs = negative.as_secs() as i64; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
221 let negative_nanos = negative.subsec_nanos(); |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
222 if negative_nanos == 0 { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
223 seconds = -negative_secs; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
224 nanoseconds = 0; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
225 } else { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
226 // For example if `system_time` was 4.3Â seconds before |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
227 // the Unix epoch we get a Duration that represents |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
228 // `(-4, -0.3)` but we want `(-5, +0.7)`: |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
229 seconds = -1 - negative_secs; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
230 nanoseconds = NSEC_PER_SEC - negative_nanos; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
231 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
232 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
233 }; |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
234 Self::new_truncate(seconds, nanoseconds, false) |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
235 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
236 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
237 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
238 const NSEC_PER_SEC: u32 = 1_000_000_000; |
48422
000130cfafb6
rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents:
48401
diff
changeset
|
239 pub const RANGE_MASK_31BIT: u32 = 0x7FFF_FFFF; |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
240 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
241 pub const MTIME_UNSET: i32 = -1; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
242 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
243 /// A `DirstateEntry` with a size of `-2` means that it was merged from the |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
244 /// other parent. This allows revert to pick the right status back during a |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
245 /// merge. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
246 pub const SIZE_FROM_OTHER_PARENT: i32 = -2; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
247 /// A special value used for internal representation of special case in |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
248 /// dirstate v1 format. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
249 pub const SIZE_NON_NORMAL: i32 = -1; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
250 |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
251 #[derive(Debug, Default, Copy, Clone)] |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
252 pub struct DirstateV2Data { |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
253 pub wc_tracked: bool, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
254 pub p1_tracked: bool, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
255 pub p2_info: bool, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
256 pub mode_size: Option<(u32, u32)>, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
257 pub mtime: Option<TruncatedTimestamp>, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
258 pub fallback_exec: Option<bool>, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
259 pub fallback_symlink: Option<bool>, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
260 } |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
261 |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
262 #[derive(Debug, Default, Copy, Clone)] |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
263 pub struct ParentFileData { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
264 pub mode_size: Option<(u32, u32)>, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
265 pub mtime: Option<TruncatedTimestamp>, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
266 } |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
267 |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
268 impl DirstateEntry { |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
269 pub fn from_v2_data(v2_data: DirstateV2Data) -> Self { |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
270 let DirstateV2Data { |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
271 wc_tracked, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
272 p1_tracked, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
273 p2_info, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
274 mode_size, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
275 mtime, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
276 fallback_exec, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
277 fallback_symlink, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
278 } = v2_data; |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
279 if let Some((mode, size)) = mode_size { |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
280 // TODO: return an error for out of range values? |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
281 assert!(mode & !RANGE_MASK_31BIT == 0); |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
282 assert!(size & !RANGE_MASK_31BIT == 0); |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
283 } |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
284 let mut flags = Flags::empty(); |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
285 flags.set(Flags::WDIR_TRACKED, wc_tracked); |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
286 flags.set(Flags::P1_TRACKED, p1_tracked); |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
287 flags.set(Flags::P2_INFO, p2_info); |
48253
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
288 if let Some(exec) = fallback_exec { |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
289 flags.insert(Flags::HAS_FALLBACK_EXEC); |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
290 if exec { |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
291 flags.insert(Flags::FALLBACK_EXEC); |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
292 } |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
293 } |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
294 if let Some(exec) = fallback_symlink { |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
295 flags.insert(Flags::HAS_FALLBACK_SYMLINK); |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
296 if exec { |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
297 flags.insert(Flags::FALLBACK_SYMLINK); |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
298 } |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
299 } |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
300 Self { |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
301 flags, |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
302 mode_size, |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
303 mtime, |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
304 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
305 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
306 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
307 pub fn from_v1_data( |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
308 state: EntryState, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
309 mode: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
310 size: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
311 mtime: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
312 ) -> Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
313 match state { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
314 EntryState::Normal => { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
315 if size == SIZE_FROM_OTHER_PARENT { |
48158
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
316 Self { |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
317 // might be missing P1_TRACKED |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
318 flags: Flags::WDIR_TRACKED | Flags::P2_INFO, |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
319 mode_size: None, |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
320 mtime: None, |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
321 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
322 } else if size == SIZE_NON_NORMAL { |
48160
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
323 Self { |
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
324 flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, |
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
325 mode_size: None, |
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
326 mtime: None, |
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
327 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
328 } else if mtime == MTIME_UNSET { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
329 // TODO:Â return an error for negative values? |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
330 let mode = u32::try_from(mode).unwrap(); |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
331 let size = u32::try_from(size).unwrap(); |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
332 Self { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
333 flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
334 mode_size: Some((mode, size)), |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
335 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
336 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
337 } else { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
338 // TODO:Â return an error for negative values? |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
339 let mode = u32::try_from(mode).unwrap(); |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
340 let size = u32::try_from(size).unwrap(); |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
341 let mtime = u32::try_from(mtime).unwrap(); |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
342 let mtime = TruncatedTimestamp::from_already_truncated( |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
343 mtime, 0, false, |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
344 ) |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
345 .unwrap(); |
48163
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
346 Self { |
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
347 flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, |
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
348 mode_size: Some((mode, size)), |
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
349 mtime: Some(mtime), |
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
350 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
351 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
352 } |
48156
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
353 EntryState::Added => Self { |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
354 flags: Flags::WDIR_TRACKED, |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
355 mode_size: None, |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
356 mtime: None, |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
357 }, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
358 EntryState::Removed => Self { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
359 flags: if size == SIZE_NON_NORMAL { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
360 Flags::P1_TRACKED | Flags::P2_INFO |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
361 } else if size == SIZE_FROM_OTHER_PARENT { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
362 // We don’t know if P1_TRACKED should be set (file history) |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
363 Flags::P2_INFO |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
364 } else { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
365 Flags::P1_TRACKED |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
366 }, |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
367 mode_size: None, |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
368 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
369 }, |
48154
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
370 EntryState::Merged => Self { |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
371 flags: Flags::WDIR_TRACKED |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
372 | Flags::P1_TRACKED // might not be true because of rename ? |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
373 | Flags::P2_INFO, // might not be true because of rename ? |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
374 mode_size: None, |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
375 mtime: None, |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
376 }, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
377 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
378 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
379 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
380 /// Creates a new entry in "removed" state. |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
381 /// |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
382 /// `size` is expected to be zero, `SIZE_NON_NORMAL`, or |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
383 /// `SIZE_FROM_OTHER_PARENT` |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
384 pub fn new_removed(size: i32) -> Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
385 Self::from_v1_data(EntryState::Removed, 0, size, 0) |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
386 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
387 |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49043
diff
changeset
|
388 pub fn new_tracked() -> Self { |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
389 let data = DirstateV2Data { |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
390 wc_tracked: true, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
391 ..Default::default() |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
392 }; |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
393 Self::from_v2_data(data) |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49043
diff
changeset
|
394 } |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49043
diff
changeset
|
395 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
396 pub fn tracked(&self) -> bool { |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
397 self.flags.contains(Flags::WDIR_TRACKED) |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
398 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
399 |
48143
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
400 pub fn p1_tracked(&self) -> bool { |
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
401 self.flags.contains(Flags::P1_TRACKED) |
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
402 } |
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
403 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
404 fn in_either_parent(&self) -> bool { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
405 self.flags.intersects(Flags::P1_TRACKED | Flags::P2_INFO) |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
406 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
407 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
408 pub fn removed(&self) -> bool { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
409 self.in_either_parent() && !self.flags.contains(Flags::WDIR_TRACKED) |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
410 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
411 |
48142
fb3b41d583c2
dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48139
diff
changeset
|
412 pub fn p2_info(&self) -> bool { |
fb3b41d583c2
dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48139
diff
changeset
|
413 self.flags.contains(Flags::WDIR_TRACKED | Flags::P2_INFO) |
fb3b41d583c2
dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48139
diff
changeset
|
414 } |
fb3b41d583c2
dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48139
diff
changeset
|
415 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
416 pub fn added(&self) -> bool { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
417 self.flags.contains(Flags::WDIR_TRACKED) && !self.in_either_parent() |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
418 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
419 |
49138
c6c1caf28349
rust-dirstate-entry: add `modified` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
420 pub fn modified(&self) -> bool { |
c6c1caf28349
rust-dirstate-entry: add `modified` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
421 self.flags |
c6c1caf28349
rust-dirstate-entry: add `modified` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
422 .contains(Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_INFO) |
c6c1caf28349
rust-dirstate-entry: add `modified` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
423 } |
c6c1caf28349
rust-dirstate-entry: add `modified` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
424 |
48086
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
425 pub fn maybe_clean(&self) -> bool { |
49918
4158608f7786
rust-clippy: tell clippy we care about keeping those `if` clauses separate
Raphaël Gomès <rgomes@octobus.net>
parents:
49631
diff
changeset
|
426 #[allow(clippy::if_same_then_else)] |
49919
bd42bd6eae45
rust-clippy: tell clippy we want to keep those clauses separate
Raphaël Gomès <rgomes@octobus.net>
parents:
49918
diff
changeset
|
427 #[allow(clippy::needless_bool)] |
48086
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
428 if !self.flags.contains(Flags::WDIR_TRACKED) { |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
429 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
430 } else if !self.flags.contains(Flags::P1_TRACKED) { |
48086
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
431 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
432 } else if self.flags.contains(Flags::P2_INFO) { |
48086
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
433 false |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
434 } else { |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
435 true |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
436 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
437 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
438 |
48087
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
439 pub fn any_tracked(&self) -> bool { |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
440 self.flags.intersects( |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
441 Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_INFO, |
48087
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
442 ) |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
443 } |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
444 |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
445 pub(crate) fn v2_data(&self) -> DirstateV2Data { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
446 if !self.any_tracked() { |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
447 // TODO: return an Option instead? |
49043
362312d61020
rust-dirstate-entry: fix typo in panic message
Raphaël Gomès <rgomes@octobus.net>
parents:
48443
diff
changeset
|
448 panic!("Accessing v2_data of an untracked DirstateEntry") |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
449 } |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
450 let wc_tracked = self.flags.contains(Flags::WDIR_TRACKED); |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
451 let p1_tracked = self.flags.contains(Flags::P1_TRACKED); |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
452 let p2_info = self.flags.contains(Flags::P2_INFO); |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
453 let mode_size = self.mode_size; |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
454 let mtime = self.mtime; |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
455 DirstateV2Data { |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
456 wc_tracked, |
48254
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
457 p1_tracked, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
458 p2_info, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
459 mode_size, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
460 mtime, |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
461 fallback_exec: self.get_fallback_exec(), |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
462 fallback_symlink: self.get_fallback_symlink(), |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
463 } |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
464 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
465 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
466 fn v1_state(&self) -> EntryState { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
467 if !self.any_tracked() { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
468 // TODO: return an Option instead? |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
469 panic!("Accessing v1_state of an untracked DirstateEntry") |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
470 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
471 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
472 EntryState::Removed |
49138
c6c1caf28349
rust-dirstate-entry: add `modified` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
473 } else if self.modified() { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
474 EntryState::Merged |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
475 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
476 EntryState::Added |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
477 } else { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
478 EntryState::Normal |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
479 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
480 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
481 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
482 fn v1_mode(&self) -> i32 { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
483 if let Some((mode, _size)) = self.mode_size { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
484 i32::try_from(mode).unwrap() |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
485 } else { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
486 0 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
487 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
488 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
489 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
490 fn v1_size(&self) -> i32 { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
491 if !self.any_tracked() { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
492 // TODO: return an Option instead? |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
493 panic!("Accessing v1_size of an untracked DirstateEntry") |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
494 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
495 if self.removed() |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
496 && self.flags.contains(Flags::P1_TRACKED | Flags::P2_INFO) |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
497 { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
498 SIZE_NON_NORMAL |
48149
6ac2b417d5d7
dirstate-item: directly use `p2_info` in `v1_size`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48143
diff
changeset
|
499 } else if self.flags.contains(Flags::P2_INFO) { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
500 SIZE_FROM_OTHER_PARENT |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
501 } else if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
502 0 |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
503 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
504 SIZE_NON_NORMAL |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
505 } else if let Some((_mode, size)) = self.mode_size { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
506 i32::try_from(size).unwrap() |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
507 } else { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
508 SIZE_NON_NORMAL |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
509 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
510 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
511 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
512 fn v1_mtime(&self) -> i32 { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
513 if !self.any_tracked() { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
514 // TODO: return an Option instead? |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
515 panic!("Accessing v1_mtime of an untracked DirstateEntry") |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
516 } |
49918
4158608f7786
rust-clippy: tell clippy we care about keeping those `if` clauses separate
Raphaël Gomès <rgomes@octobus.net>
parents:
49631
diff
changeset
|
517 |
4158608f7786
rust-clippy: tell clippy we care about keeping those `if` clauses separate
Raphaël Gomès <rgomes@octobus.net>
parents:
49631
diff
changeset
|
518 #[allow(clippy::if_same_then_else)] |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
519 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
520 0 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
521 } else if self.flags.contains(Flags::P2_INFO) { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
522 MTIME_UNSET |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
523 } else if !self.flags.contains(Flags::P1_TRACKED) { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
524 MTIME_UNSET |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
525 } else if let Some(mtime) = self.mtime { |
48400
0b3f3a3ca50a
dirstate-item: ignore mtime to write v1 when `mtime-second-ambiguous` is set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48399
diff
changeset
|
526 if mtime.second_ambiguous { |
0b3f3a3ca50a
dirstate-item: ignore mtime to write v1 when `mtime-second-ambiguous` is set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48399
diff
changeset
|
527 MTIME_UNSET |
0b3f3a3ca50a
dirstate-item: ignore mtime to write v1 when `mtime-second-ambiguous` is set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48399
diff
changeset
|
528 } else { |
0b3f3a3ca50a
dirstate-item: ignore mtime to write v1 when `mtime-second-ambiguous` is set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48399
diff
changeset
|
529 i32::try_from(mtime.truncated_seconds()).unwrap() |
0b3f3a3ca50a
dirstate-item: ignore mtime to write v1 when `mtime-second-ambiguous` is set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48399
diff
changeset
|
530 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
531 } else { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
532 MTIME_UNSET |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
533 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
534 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
535 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
536 // TODO: return `Option<EntryState>`? None when `!self.any_tracked` |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
537 pub fn state(&self) -> EntryState { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
538 self.v1_state() |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
539 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
540 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
541 // TODO: return Option? |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
542 pub fn mode(&self) -> i32 { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
543 self.v1_mode() |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
544 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
545 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
546 // TODO: return Option? |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
547 pub fn size(&self) -> i32 { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
548 self.v1_size() |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
549 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
550 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
551 // TODO: return Option? |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
552 pub fn mtime(&self) -> i32 { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
553 self.v1_mtime() |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
554 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
555 |
48252
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
556 pub fn get_fallback_exec(&self) -> Option<bool> { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
557 if self.flags.contains(Flags::HAS_FALLBACK_EXEC) { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
558 Some(self.flags.contains(Flags::FALLBACK_EXEC)) |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
559 } else { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
560 None |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
561 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
562 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
563 |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
564 pub fn set_fallback_exec(&mut self, value: Option<bool>) { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
565 match value { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
566 None => { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
567 self.flags.remove(Flags::HAS_FALLBACK_EXEC); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
568 self.flags.remove(Flags::FALLBACK_EXEC); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
569 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
570 Some(exec) => { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
571 self.flags.insert(Flags::HAS_FALLBACK_EXEC); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
572 if exec { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
573 self.flags.insert(Flags::FALLBACK_EXEC); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
574 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
575 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
576 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
577 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
578 |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
579 pub fn get_fallback_symlink(&self) -> Option<bool> { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
580 if self.flags.contains(Flags::HAS_FALLBACK_SYMLINK) { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
581 Some(self.flags.contains(Flags::FALLBACK_SYMLINK)) |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
582 } else { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
583 None |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
584 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
585 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
586 |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
587 pub fn set_fallback_symlink(&mut self, value: Option<bool>) { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
588 match value { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
589 None => { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
590 self.flags.remove(Flags::HAS_FALLBACK_SYMLINK); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
591 self.flags.remove(Flags::FALLBACK_SYMLINK); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
592 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
593 Some(symlink) => { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
594 self.flags.insert(Flags::HAS_FALLBACK_SYMLINK); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
595 if symlink { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
596 self.flags.insert(Flags::FALLBACK_SYMLINK); |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
597 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
598 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
599 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
600 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
601 |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
602 pub fn truncated_mtime(&self) -> Option<TruncatedTimestamp> { |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
603 self.mtime |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
604 } |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
605 |
48134
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
606 pub fn drop_merge_data(&mut self) { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
607 if self.flags.contains(Flags::P2_INFO) { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
608 self.flags.remove(Flags::P2_INFO); |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
609 self.mode_size = None; |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
610 self.mtime = None; |
48134
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
611 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
612 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
613 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
614 pub fn set_possibly_dirty(&mut self) { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
615 self.mtime = None |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
616 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
617 |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
618 pub fn set_clean( |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
619 &mut self, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
620 mode: u32, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
621 size: u32, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
622 mtime: TruncatedTimestamp, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
623 ) { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
624 let size = size & RANGE_MASK_31BIT; |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
625 self.flags.insert(Flags::WDIR_TRACKED | Flags::P1_TRACKED); |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
626 self.mode_size = Some((mode, size)); |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
627 self.mtime = Some(mtime); |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
628 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
629 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
630 pub fn set_tracked(&mut self) { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
631 self.flags.insert(Flags::WDIR_TRACKED); |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
632 // `set_tracked` is replacing various `normallookup` call. So we mark |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
633 // the files as needing lookup |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
634 // |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
635 // Consider dropping this in the future in favor of something less |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
636 // broad. |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
637 self.mtime = None; |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
638 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
639 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
640 pub fn set_untracked(&mut self) { |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
641 self.flags.remove(Flags::WDIR_TRACKED); |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
642 self.mode_size = None; |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
643 self.mtime = None; |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
644 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
645 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
646 /// Returns `(state, mode, size, mtime)` for the puprose of serialization |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
647 /// in the dirstate-v1 format. |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
648 /// |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
649 /// This includes marker values such as `mtime == -1`. In the future we may |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
650 /// want to not represent these cases that way in memory, but serialization |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
651 /// will need to keep the same format. |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
652 pub fn v1_data(&self) -> (u8, i32, i32, i32) { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
653 ( |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
654 self.v1_state().into(), |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
655 self.v1_mode(), |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
656 self.v1_size(), |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
657 self.v1_mtime(), |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
658 ) |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
659 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
660 |
48061
060cd909439f
dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48051
diff
changeset
|
661 pub(crate) fn is_from_other_parent(&self) -> bool { |
49139
7241b3721ba5
rust-dirstatemap: stop using `.state` in `is_from_other_parent`
Raphaël Gomès <rgomes@octobus.net>
parents:
49138
diff
changeset
|
662 self.flags.contains(Flags::WDIR_TRACKED | Flags::P2_INFO) |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
663 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
664 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
665 // TODO: other platforms |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
666 #[cfg(unix)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
667 pub fn mode_changed( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
668 &self, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
669 filesystem_metadata: &std::fs::Metadata, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
670 ) -> bool { |
48345
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
671 let dirstate_exec_bit = (self.mode() as u32 & EXEC_BIT_MASK) != 0; |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
672 let fs_exec_bit = has_exec_bit(filesystem_metadata); |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
673 dirstate_exec_bit != fs_exec_bit |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
674 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
675 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
676 /// Returns a `(state, mode, size, mtime)` tuple as for |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
677 /// `DirstateMapMethods::debug_iter`. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
678 pub fn debug_tuple(&self) -> (u8, i32, i32, i32) { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
679 (self.state().into(), self.mode(), self.size(), self.mtime()) |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
680 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
681 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
682 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
683 impl EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
684 pub fn is_tracked(self) -> bool { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
685 use EntryState::*; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
686 match self { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
687 Normal | Added | Merged => true, |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
688 Removed => false, |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
689 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
690 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
691 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
692 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
693 impl TryFrom<u8> for EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
694 type Error = HgError; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
695 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
696 fn try_from(value: u8) -> Result<Self, Self::Error> { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
697 match value { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
698 b'n' => Ok(EntryState::Normal), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
699 b'a' => Ok(EntryState::Added), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
700 b'r' => Ok(EntryState::Removed), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
701 b'm' => Ok(EntryState::Merged), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
702 _ => Err(HgError::CorruptedRepository(format!( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
703 "Incorrect dirstate entry state {}", |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
704 value |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
705 ))), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
706 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
707 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
708 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
709 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49919
diff
changeset
|
710 impl From<EntryState> for u8 { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49919
diff
changeset
|
711 fn from(val: EntryState) -> Self { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49919
diff
changeset
|
712 match val { |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
713 EntryState::Normal => b'n', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
714 EntryState::Added => b'a', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
715 EntryState::Removed => b'r', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
716 EntryState::Merged => b'm', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
717 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
718 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
719 } |
48345
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
720 |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
721 const EXEC_BIT_MASK: u32 = 0o100; |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
722 |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
723 pub fn has_exec_bit(metadata: &std::fs::Metadata) -> bool { |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
724 // TODO: How to handle executable permissions on Windows? |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
725 use std::os::unix::fs::MetadataExt; |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
726 (metadata.mode() & EXEC_BIT_MASK) != 0 |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
727 } |