Mercurial > hg
annotate rust/hg-core/src/dirstate/entry.rs @ 48155:b2af515b4faf
dirstate-item: drop the legacy new_merged constructor
Nobody is calling it anymore. Its purposes has been filled.
Differential Revision: https://phab.mercurial-scm.org/D11599
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 01 Oct 2021 09:14:10 +0200 |
parents | 7a8c9869e4fe |
children | d342815ff827 |
rev | line source |
---|---|
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1 use crate::errors::HgError; |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
2 use bitflags::bitflags; |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
3 use std::convert::TryFrom; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
4 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
5 #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
6 pub enum EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
7 Normal, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
8 Added, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
9 Removed, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
10 Merged, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
11 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
12 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
13 /// The C implementation uses all signed types. This will be an issue |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
14 /// either when 4GB+ source files are commonplace or in 2038, whichever |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
15 /// comes first. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
16 #[derive(Debug, PartialEq, Copy, Clone)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
17 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
|
18 pub(crate) flags: Flags, |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
19 mode_size: Option<(i32, i32)>, |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
20 mtime: Option<i32>, |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
21 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
22 |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
23 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
|
24 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
|
25 const WDIR_TRACKED = 1 << 0; |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
26 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
|
27 const P2_INFO = 1 << 2; |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
28 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
29 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
30 |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
31 pub const V1_RANGEMASK: i32 = 0x7FFFFFFF; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
32 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
33 pub const MTIME_UNSET: i32 = -1; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
34 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
35 /// 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
|
36 /// 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
|
37 /// merge. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
38 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
|
39 /// 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
|
40 /// dirstate v1 format. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
41 pub const SIZE_NON_NORMAL: i32 = -1; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
42 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 p2_info: bool, |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
48 mode_size: Option<(i32, i32)>, |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
49 mtime: Option<i32>, |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
50 ) -> Self { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 flags.set(Flags::P2_INFO, p2_info); |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
55 Self { |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
56 flags, |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
57 mode_size, |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
58 mtime, |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
59 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
60 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
61 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
62 pub fn from_v1_data( |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
63 state: EntryState, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
64 mode: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
65 size: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
66 mtime: i32, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
67 ) -> Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
68 match state { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
69 EntryState::Normal => { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
70 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
|
71 Self::new_from_p2() |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
72 } else if size == SIZE_NON_NORMAL { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
73 Self::new_possibly_dirty() |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
74 } else if mtime == MTIME_UNSET { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
75 Self { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
76 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
|
77 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
|
78 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
79 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
80 } else { |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
81 Self::new_normal(mode, size, mtime) |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
82 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
83 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
84 EntryState::Added => Self::new_added(), |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
85 EntryState::Removed => Self { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
86 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
|
87 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
|
88 } 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
|
89 // 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
|
90 Flags::P2_INFO |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
91 } else { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
92 Flags::P1_TRACKED |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
93 }, |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
94 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
|
95 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
96 }, |
48154
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
97 EntryState::Merged => Self { |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
98 flags: Flags::WDIR_TRACKED |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
99 | 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
|
100 | 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
|
101 mode_size: None, |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
102 mtime: None, |
7a8c9869e4fe
dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48153
diff
changeset
|
103 }, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
104 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
105 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
106 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
107 pub fn new_from_p2() -> Self { |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
108 Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
109 // might be missing 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
|
110 flags: Flags::WDIR_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
|
111 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
|
112 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
113 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
114 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
115 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
116 pub fn new_possibly_dirty() -> Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
117 Self { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
118 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
|
119 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
|
120 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
121 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
122 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
123 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
124 pub fn new_added() -> Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
125 Self { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
126 flags: 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
|
127 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
|
128 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
129 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
130 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
131 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
132 pub fn new_normal(mode: i32, size: i32, mtime: i32) -> Self { |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
133 Self { |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
134 flags: 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
|
135 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
|
136 mtime: Some(mtime), |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
137 } |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
138 } |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
139 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
140 /// 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
|
141 /// |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
142 /// `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
|
143 /// `SIZE_FROM_OTHER_PARENT` |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
144 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
|
145 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
|
146 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
147 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
148 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
|
149 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
|
150 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
151 |
48143
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
152 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
|
153 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
|
154 } |
21542d4cb568
dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48142
diff
changeset
|
155 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
156 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
|
157 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
|
158 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
159 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
160 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
|
161 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
|
162 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
163 |
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
|
164 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
|
165 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
|
166 } |
fb3b41d583c2
dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48139
diff
changeset
|
167 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
168 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
|
169 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
|
170 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
171 |
48086
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
172 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
|
173 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
|
174 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
175 } 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
|
176 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
177 } 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
|
178 false |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
179 } else { |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
180 true |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
181 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
182 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
183 |
48087
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 ) |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
188 } |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
189 |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
190 /// 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
|
191 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
|
192 &self, |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
193 ) -> (bool, bool, bool, Option<(i32, i32)>, Option<i32>) { |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
194 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
|
195 // 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
|
196 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
|
197 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 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
|
202 let mtime = self.mtime; |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
203 (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
|
204 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
205 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
206 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
|
207 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
|
208 // 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
|
209 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
|
210 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
211 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
212 EntryState::Removed |
48152
8f88307f8e07
dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48150
diff
changeset
|
213 } else if self |
8f88307f8e07
dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48150
diff
changeset
|
214 .flags |
8f88307f8e07
dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48150
diff
changeset
|
215 .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
|
216 { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
217 EntryState::Merged |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
218 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
219 EntryState::Added |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
220 } else { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
221 EntryState::Normal |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
222 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
223 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
224 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
225 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
|
226 if let Some((mode, _size)) = self.mode_size { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
227 mode |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
228 } else { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
229 0 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
230 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
231 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
232 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
233 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
|
234 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
|
235 // 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
|
236 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
|
237 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
238 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
|
239 && 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
|
240 { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
241 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
|
242 } 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
|
243 SIZE_FROM_OTHER_PARENT |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
244 } else if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
245 0 |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
246 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
247 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
|
248 } else if let Some((_mode, size)) = self.mode_size { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
249 size |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
250 } else { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
251 SIZE_NON_NORMAL |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
252 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
253 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
254 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
255 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
|
256 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
|
257 // 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
|
258 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
|
259 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
260 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
261 0 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
262 } 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
|
263 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
|
264 } 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
|
265 MTIME_UNSET |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
266 } else { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
267 self.mtime.unwrap_or(MTIME_UNSET) |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
268 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
269 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
270 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
271 // 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
|
272 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
|
273 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
|
274 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
275 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
276 // 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
|
277 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
|
278 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
|
279 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
280 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
281 // 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
|
282 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
|
283 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
|
284 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
285 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
286 // 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
|
287 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
|
288 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
|
289 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
290 |
48134
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
297 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
298 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
299 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
|
300 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
|
301 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
302 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
303 pub fn set_clean(&mut self, mode: i32, size: i32, mtime: i32) { |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
308 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
309 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
|
310 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
|
311 // `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
|
312 // 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
|
313 // |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
314 // 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
|
315 // broad. |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
316 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
|
317 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
318 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 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
|
323 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
324 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
325 /// 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
|
326 /// in the dirstate-v1 format. |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
327 /// |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
328 /// 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
|
329 /// 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
|
330 /// 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
|
331 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
|
332 ( |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 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
|
337 ) |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
338 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
339 |
48061
060cd909439f
dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48051
diff
changeset
|
340 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
|
341 self.state() == EntryState::Normal |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
342 && self.size() == SIZE_FROM_OTHER_PARENT |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
343 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
344 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
345 // TODO: other platforms |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
346 #[cfg(unix)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
347 pub fn mode_changed( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
348 &self, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
349 filesystem_metadata: &std::fs::Metadata, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
350 ) -> bool { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
351 use std::os::unix::fs::MetadataExt; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
352 const EXEC_BIT_MASK: u32 = 0o100; |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
353 let dirstate_exec_bit = (self.mode() as u32) & EXEC_BIT_MASK; |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
354 let fs_exec_bit = filesystem_metadata.mode() & EXEC_BIT_MASK; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
355 dirstate_exec_bit != fs_exec_bit |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
356 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
357 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
358 /// 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
|
359 /// `DirstateMapMethods::debug_iter`. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
360 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
|
361 (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
|
362 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
363 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
364 pub fn mtime_is_ambiguous(&self, now: i32) -> bool { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
365 self.state() == EntryState::Normal && self.mtime() == now |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
366 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
367 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
368 pub fn clear_ambiguous_mtime(&mut self, now: i32) -> bool { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
369 let ambiguous = self.mtime_is_ambiguous(now); |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
370 if ambiguous { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
371 // The file was last modified "simultaneously" with the current |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
372 // write to dirstate (i.e. within the same second for file- |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
373 // systems with a granularity of 1 sec). This commonly happens |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
374 // for at least a couple of files on 'update'. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
375 // The user could change the file without changing its size |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
376 // within the same second. Invalidate the file's mtime in |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
377 // dirstate, forcing future 'status' calls to compare the |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
378 // contents of the file if the size is the same. This prevents |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
379 // mistakenly treating such files as clean. |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
380 self.set_possibly_dirty() |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
381 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
382 ambiguous |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
383 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
384 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
385 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
386 impl EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
387 pub fn is_tracked(self) -> bool { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
388 use EntryState::*; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
389 match self { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
390 Normal | Added | Merged => true, |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
391 Removed => false, |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
392 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
393 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
394 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
395 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
396 impl TryFrom<u8> for EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
397 type Error = HgError; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
398 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
399 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
|
400 match value { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
401 b'n' => Ok(EntryState::Normal), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
402 b'a' => Ok(EntryState::Added), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
403 b'r' => Ok(EntryState::Removed), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
404 b'm' => Ok(EntryState::Merged), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
405 _ => Err(HgError::CorruptedRepository(format!( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
406 "Incorrect dirstate entry state {}", |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
407 value |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
408 ))), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
409 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
410 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
411 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
412 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
413 impl Into<u8> for EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
414 fn into(self) -> u8 { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
415 match self { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
416 EntryState::Normal => b'n', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
417 EntryState::Added => b'a', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
418 EntryState::Removed => b'r', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
419 EntryState::Merged => b'm', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
420 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
421 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
422 } |