Mercurial > hg
annotate rust/hg-core/src/dirstate/entry.rs @ 48398:111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
This will be used to support the `mtime-second-ambiguous` flag from dirstate
v2. See format documentation for details.
For now, we only make it possible to store the information, no other logic have
been added.
Differential Revision: https://phab.mercurial-scm.org/D11842
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 24 Nov 2021 04:40:00 +0100 |
parents | 434de12918fd |
children | af303ae33cd7 |
rev | line source |
---|---|
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
1 use crate::dirstate_tree::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::convert::{TryFrom, TryInto}; |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
5 use std::fs; |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
6 use std::io; |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
7 use std::time::{SystemTime, UNIX_EPOCH}; |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
8 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
9 #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
10 pub enum EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
11 Normal, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
12 Added, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
13 Removed, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
14 Merged, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
15 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
16 |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
17 /// `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
|
18 /// |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
19 /// 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
|
20 /// 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
|
21 #[derive(Debug, Copy, Clone)] |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
22 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
|
23 pub(crate) flags: Flags, |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
24 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
|
25 mtime: Option<TruncatedTimestamp>, |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
26 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
27 |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
28 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
|
29 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
|
30 const WDIR_TRACKED = 1 << 0; |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
38 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
39 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
40 /// 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
|
41 #[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
|
42 pub struct TruncatedTimestamp { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
43 truncated_seconds: u32, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
44 /// 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
|
45 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
|
46 second_ambiguous: bool, |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
47 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
48 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
49 impl TruncatedTimestamp { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
50 /// 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
|
51 /// 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
|
52 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
53 /// 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 ) -> Self { |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
59 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
|
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 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
|
62 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
|
63 second_ambiguous, |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
64 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
65 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
66 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
67 /// 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
|
68 /// expcted range. |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
69 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
|
70 truncated_seconds: u32, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
71 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
|
72 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
|
73 ) -> Result<Self, DirstateV2ParseError> { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
74 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
|
75 && 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
|
76 { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
77 Ok(Self { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
78 truncated_seconds, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
79 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
|
80 second_ambiguous, |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
81 }) |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
82 } else { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
83 Err(DirstateV2ParseError) |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
84 } |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
85 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
86 |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
87 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
|
88 #[cfg(unix)] |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
89 { |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
90 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
|
91 let seconds = metadata.mtime(); |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
92 // 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
|
93 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
|
94 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
|
95 } |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
96 #[cfg(not(unix))] |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
97 { |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
98 metadata.modified().map(Self::from) |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
99 } |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
100 } |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
101 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
102 /// 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
|
103 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
|
104 self.truncated_seconds |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
105 } |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
106 |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
107 /// 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
|
108 /// 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
|
109 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
110 /// 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
|
111 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
|
112 self.nanoseconds |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
113 } |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
114 |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
115 /// 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
|
116 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
117 /// 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
|
118 /// 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
|
119 /// 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
|
120 /// 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
|
121 /// 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
|
122 /// |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
123 /// 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
|
124 /// 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
|
125 /// 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
|
126 /// |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
127 /// 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
|
128 /// 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
|
129 /// 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
|
130 /// 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
|
131 /// negatives. |
48257
f45d35950db6
dirstate: rename a `very_likely_equal` method to `likely_equal`
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
132 pub fn likely_equal(self, other: Self) -> bool { |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
133 self.truncated_seconds == other.truncated_seconds |
48262
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
134 && (self.nanoseconds == other.nanoseconds |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
135 || self.nanoseconds == 0 |
68bb472aee9c
dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
48260
diff
changeset
|
136 || other.nanoseconds == 0) |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
137 } |
48218
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
138 |
48257
f45d35950db6
dirstate: rename a `very_likely_equal` method to `likely_equal`
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
139 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
|
140 self, |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
141 metadata: &fs::Metadata, |
15dedc0c5c35
status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
142 ) -> 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
|
143 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
|
144 } |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
145 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
146 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
147 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
|
148 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
|
149 // 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
|
150 // 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
|
151 // 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
|
152 // 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
|
153 let seconds; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
154 let nanoseconds; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
155 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
|
156 Ok(duration) => { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
157 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
|
158 nanoseconds = duration.subsec_nanos(); |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
159 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
160 Err(error) => { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
161 // `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
|
162 // 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
|
163 // 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
|
164 let negative = error.duration(); |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
165 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
|
166 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
|
167 if negative_nanos == 0 { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
168 seconds = -negative_secs; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
169 nanoseconds = 0; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
170 } else { |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
171 // 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
|
172 // 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
|
173 // `(-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
|
174 seconds = -1 - negative_secs; |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
175 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
|
176 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
177 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
178 }; |
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
|
179 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
|
180 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
181 } |
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48164
diff
changeset
|
182 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
183 const NSEC_PER_SEC: u32 = 1_000_000_000; |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
184 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
|
185 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
186 pub const MTIME_UNSET: i32 = -1; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
187 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
188 /// 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
|
189 /// 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
|
190 /// merge. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
191 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
|
192 /// 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
|
193 /// dirstate v1 format. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
194 pub const SIZE_NON_NORMAL: i32 = -1; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
195 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
196 impl 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
|
197 pub fn from_v2_data( |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
198 wdir_tracked: bool, |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
199 p1_tracked: bool, |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
200 p2_info: bool, |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
201 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
|
202 mtime: Option<TruncatedTimestamp>, |
48253
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
203 fallback_exec: Option<bool>, |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
204 fallback_symlink: Option<bool>, |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
205 ) -> Self { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
206 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
|
207 // 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
|
208 assert!(mode & !RANGE_MASK_31BIT == 0); |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
209 assert!(size & !RANGE_MASK_31BIT == 0); |
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
210 } |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
211 let mut flags = Flags::empty(); |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
212 flags.set(Flags::WDIR_TRACKED, wdir_tracked); |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 if exec { |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
218 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
|
219 } |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
220 } |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
221 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
|
222 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
|
223 if exec { |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
224 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
|
225 } |
948570aa7630
dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48252
diff
changeset
|
226 } |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
227 Self { |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
228 flags, |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
229 mode_size, |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
230 mtime, |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
231 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
232 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
233 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
234 pub fn from_v1_data( |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
235 state: EntryState, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
236 mode: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
237 size: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
238 mtime: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
239 ) -> Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
240 match state { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
241 EntryState::Normal => { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
242 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
|
243 Self { |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
244 // 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
|
245 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
|
246 mode_size: None, |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
247 mtime: None, |
da304f78a0e1
dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48157
diff
changeset
|
248 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
249 } 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
|
250 Self { |
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
251 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
|
252 mode_size: None, |
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
253 mtime: None, |
898de425bcd6
dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48159
diff
changeset
|
254 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
255 } else if mtime == MTIME_UNSET { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
256 // 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
|
257 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
|
258 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
|
259 Self { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
260 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
|
261 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
|
262 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
263 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
264 } else { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
265 // 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 ) |
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48392
diff
changeset
|
272 .unwrap(); |
48163
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
273 Self { |
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
274 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
|
275 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
|
276 mtime: Some(mtime), |
d0081dbca442
dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48161
diff
changeset
|
277 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
278 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
279 } |
48156
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
280 EntryState::Added => Self { |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
281 flags: Flags::WDIR_TRACKED, |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
282 mode_size: None, |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
283 mtime: None, |
d342815ff827
dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48155
diff
changeset
|
284 }, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
285 EntryState::Removed => Self { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
286 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
|
287 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
|
288 } 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
|
289 // 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
|
290 Flags::P2_INFO |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
291 } else { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
292 Flags::P1_TRACKED |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
293 }, |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
294 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
|
295 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
296 }, |
48154
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
297 EntryState::Merged => Self { |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
298 flags: Flags::WDIR_TRACKED |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
299 | 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
|
300 | 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
|
301 mode_size: None, |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
302 mtime: None, |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
303 }, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
304 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
305 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
306 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
307 /// 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
|
308 /// |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
309 /// `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
|
310 /// `SIZE_FROM_OTHER_PARENT` |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
311 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
|
312 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
|
313 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
314 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
315 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
|
316 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
|
317 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
318 |
48143
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
319 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
|
320 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
|
321 } |
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
322 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
323 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
|
324 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
|
325 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
326 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
327 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
|
328 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
|
329 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
330 |
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
|
331 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
|
332 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
|
333 } |
fb3b41d583c2
dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48139
diff
changeset
|
334 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
335 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
|
336 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
|
337 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
338 |
48086
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
339 pub fn maybe_clean(&self) -> bool { |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
340 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
|
341 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
342 } 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
|
343 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
344 } 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
|
345 false |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
346 } else { |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
347 true |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
348 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
349 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
350 |
48087
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
351 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
|
352 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
|
353 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
|
354 ) |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
355 } |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
356 |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
357 /// Returns `(wdir_tracked, p1_tracked, p2_info, mode_size, mtime)` |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
358 pub(crate) fn v2_data( |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
359 &self, |
48254
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
360 ) -> ( |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
361 bool, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
362 bool, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
363 bool, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
364 Option<(u32, u32)>, |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
365 Option<TruncatedTimestamp>, |
48254
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
366 Option<bool>, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
367 Option<bool>, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
368 ) { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
369 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
|
370 // TODO: return an Option instead? |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
371 panic!("Accessing v1_state of an untracked DirstateEntry") |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
372 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
373 let wdir_tracked = self.flags.contains(Flags::WDIR_TRACKED); |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
374 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
|
375 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
|
376 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
|
377 let mtime = self.mtime; |
48254
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
378 ( |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
379 wdir_tracked, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
380 p1_tracked, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
381 p2_info, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
382 mode_size, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
383 mtime, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
384 self.get_fallback_exec(), |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
385 self.get_fallback_symlink(), |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
386 ) |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
387 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
388 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
389 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
|
390 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
|
391 // 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
|
392 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
|
393 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
394 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
395 EntryState::Removed |
48152
8f88307f8e07
dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48150
diff
changeset
|
396 } else if self |
8f88307f8e07
dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48150
diff
changeset
|
397 .flags |
8f88307f8e07
dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48150
diff
changeset
|
398 .contains(Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_INFO) |
8f88307f8e07
dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48150
diff
changeset
|
399 { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
400 EntryState::Merged |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
401 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
402 EntryState::Added |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
403 } else { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
404 EntryState::Normal |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
405 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
406 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
407 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
408 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
|
409 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
|
410 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
|
411 } else { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
412 0 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
413 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
414 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
415 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
416 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
|
417 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
|
418 // 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
|
419 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
|
420 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
421 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
|
422 && 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
|
423 { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
424 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
|
425 } 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
|
426 SIZE_FROM_OTHER_PARENT |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
427 } else if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
428 0 |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
429 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
430 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
|
431 } 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
|
432 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
|
433 } else { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
434 SIZE_NON_NORMAL |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
435 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
436 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
437 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
438 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
|
439 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
|
440 // 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
|
441 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
|
442 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
443 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
444 0 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
445 } 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
|
446 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
|
447 } 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
|
448 MTIME_UNSET |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
449 } else if let Some(mtime) = self.mtime { |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
450 i32::try_from(mtime.truncated_seconds()).unwrap() |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
451 } else { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
452 MTIME_UNSET |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
453 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
454 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
455 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
456 // 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
|
457 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
|
458 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
|
459 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
460 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
461 // 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
|
462 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
|
463 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
|
464 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
465 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
466 // 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
|
467 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
|
468 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
|
469 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
470 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
471 // 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
|
472 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
|
473 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
|
474 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
475 |
48252
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
476 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
|
477 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
|
478 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
|
479 } else { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
480 None |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
481 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
482 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
483 |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
484 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
|
485 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
|
486 None => { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
487 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
|
488 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
|
489 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 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
|
494 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
495 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
496 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
497 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
498 |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
499 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
|
500 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
|
501 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
|
502 } else { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
503 None |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
504 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
505 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
506 |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
507 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
|
508 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
|
509 None => { |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
510 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
|
511 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
|
512 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
513 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
|
514 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
|
515 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
|
516 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
|
517 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
518 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
519 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
520 } |
602c8e8411f5
dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48218
diff
changeset
|
521 |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
522 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
|
523 self.mtime |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
524 } |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
525 |
48134
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
532 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
533 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
534 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
|
535 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
|
536 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
537 |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
538 pub fn set_clean( |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
539 &mut self, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
540 mode: u32, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
541 size: u32, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
542 mtime: TruncatedTimestamp, |
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48259
diff
changeset
|
543 ) { |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 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
|
548 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
549 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
550 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
|
551 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
|
552 // `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
|
553 // 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
|
554 // |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
555 // 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
|
556 // broad. |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
557 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
|
558 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
559 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
560 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
|
561 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
|
562 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
|
563 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
|
564 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
565 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
566 /// 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
|
567 /// in the dirstate-v1 format. |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
568 /// |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
569 /// 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
|
570 /// 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
|
571 /// 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
|
572 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
|
573 ( |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 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
|
578 ) |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
579 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
580 |
48061
060cd909439f
dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48051
diff
changeset
|
581 pub(crate) fn is_from_other_parent(&self) -> bool { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
582 self.state() == EntryState::Normal |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
583 && self.size() == SIZE_FROM_OTHER_PARENT |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
584 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
585 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
586 // TODO: other platforms |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
587 #[cfg(unix)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
588 pub fn mode_changed( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
589 &self, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
590 filesystem_metadata: &std::fs::Metadata, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
591 ) -> bool { |
48345
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
592 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
|
593 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
|
594 dirstate_exec_bit != fs_exec_bit |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
595 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
596 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
597 /// 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
|
598 /// `DirstateMapMethods::debug_iter`. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
599 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
|
600 (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
|
601 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
602 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
603 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
604 impl EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
605 pub fn is_tracked(self) -> bool { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
606 use EntryState::*; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
607 match self { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
608 Normal | Added | Merged => true, |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
609 Removed => false, |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
610 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
611 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
612 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
613 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
614 impl TryFrom<u8> for EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
615 type Error = HgError; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
616 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
617 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
|
618 match value { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
619 b'n' => Ok(EntryState::Normal), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
620 b'a' => Ok(EntryState::Added), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
621 b'r' => Ok(EntryState::Removed), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
622 b'm' => Ok(EntryState::Merged), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
623 _ => Err(HgError::CorruptedRepository(format!( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
624 "Incorrect dirstate entry state {}", |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
625 value |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
626 ))), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
627 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
628 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
629 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
630 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
631 impl Into<u8> for EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
632 fn into(self) -> u8 { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
633 match self { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
634 EntryState::Normal => b'n', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
635 EntryState::Added => b'a', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
636 EntryState::Removed => b'r', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
637 EntryState::Merged => b'm', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
638 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
639 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
640 } |
48345
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
641 |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
642 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
|
643 |
d5a91701f7dc
rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents:
48263
diff
changeset
|
644 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
|
645 // 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
|
646 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
|
647 (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
|
648 } |