annotate rust/hg-core/src/dirstate/entry.rs @ 48401:995aaacb12d7

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