Mercurial > hg
annotate rust/hg-core/src/dirstate/entry.rs @ 48142:fb3b41d583c2
dirstate-item: introduce a `p2_info` property that combine two others
The `merged` and `from_p2` property are always used together so we can expose a
combined property instead.
Differential Revision: https://phab.mercurial-scm.org/D11585
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 01 Oct 2021 04:04:09 +0200 |
parents | ab5a7fdbf75c |
children | 21542d4cb568 |
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 }, |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
97 EntryState::Merged => Self::new_merged(), |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
98 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
99 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
100 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
101 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
|
102 Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
103 // 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
|
104 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
|
105 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
|
106 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
107 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
108 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
109 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
110 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
|
111 Self { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
112 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
|
113 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
|
114 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
115 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
116 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
117 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
118 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
|
119 Self { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
120 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
|
121 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
|
122 mtime: None, |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
123 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
124 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
125 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
126 pub fn new_merged() -> Self { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
127 Self { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
128 flags: Flags::WDIR_TRACKED |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
129 | Flags::P1_TRACKED // might not be true because of rename ? |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
130 | Flags::P2_INFO, // might not be true because of rename ? |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
131 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
|
132 mtime: None, |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
133 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
134 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
135 |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
136 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
|
137 Self { |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
138 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
|
139 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
|
140 mtime: Some(mtime), |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
141 } |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
142 } |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48043
diff
changeset
|
143 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
144 /// 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
|
145 /// |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
146 /// `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
|
147 /// `SIZE_FROM_OTHER_PARENT` |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
148 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
|
149 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
|
150 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
151 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
152 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
|
153 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
|
154 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
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 merged(&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 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
170 .contains(Flags::WDIR_TRACKED | 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
|
171 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
172 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
173 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
|
174 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
|
175 } |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
176 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
177 pub fn from_p2(&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
|
178 self.flags.contains(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
|
179 && !self.flags.contains(Flags::P1_TRACKED) |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
180 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
181 |
48086
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
182 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
|
183 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
|
184 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
185 } 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
|
186 false |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
187 } 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
|
188 false |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
189 } else { |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
190 true |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
191 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
192 } |
80783e553bd5
dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48067
diff
changeset
|
193 |
48087
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 ) |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
198 } |
79bc60ca5946
dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48086
diff
changeset
|
199 |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
200 /// 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
|
201 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
|
202 &self, |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
203 ) -> (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
|
204 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
|
205 // 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
|
206 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
|
207 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 (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
|
214 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48138
diff
changeset
|
215 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
216 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
|
217 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
|
218 // 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
|
219 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
|
220 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
221 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
222 EntryState::Removed |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
223 } else if self.merged() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
224 EntryState::Merged |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
225 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
226 EntryState::Added |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
227 } else { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
228 EntryState::Normal |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
229 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
230 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
231 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
232 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
|
233 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
|
234 mode |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
235 } else { |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
236 0 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
237 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
238 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
239 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
240 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
|
241 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
|
242 // 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
|
243 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
|
244 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
245 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
|
246 && 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
|
247 { |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
248 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
|
249 } else if self.removed() && 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
|
250 SIZE_FROM_OTHER_PARENT |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
251 } else if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
252 0 |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
253 } else if self.merged() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
254 SIZE_FROM_OTHER_PARENT |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
255 } else if self.added() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
256 SIZE_NON_NORMAL |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
257 } else if self.from_p2() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
258 SIZE_FROM_OTHER_PARENT |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
259 } 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
|
260 size |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
261 } else { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
262 SIZE_NON_NORMAL |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
263 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
264 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
265 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
266 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
|
267 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
|
268 // 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
|
269 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
|
270 } |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
271 if self.removed() { |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
272 0 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
273 } 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
|
274 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
|
275 } 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
|
276 MTIME_UNSET |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
277 } else { |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
278 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
|
279 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
280 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
281 |
48138
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
282 // 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
|
283 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
|
284 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
|
285 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
286 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
287 // 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
|
288 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
|
289 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
|
290 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
291 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
292 // 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
|
293 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
|
294 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
|
295 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
296 |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
297 // 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
|
298 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
|
299 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
|
300 } |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
301 |
48134
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
308 } |
3c7db97ce541
dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48087
diff
changeset
|
309 |
48043
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
310 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
|
311 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
|
312 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
313 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
314 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
|
315 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
|
316 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
|
317 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
|
318 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
319 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
320 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
|
321 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
|
322 // `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
|
323 // 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
|
324 // |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
325 // 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
|
326 // broad. |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
327 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
|
328 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
329 |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 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
|
334 } |
3e69bef2031a
rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
335 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
336 /// 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
|
337 /// in the dirstate-v1 format. |
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 /// 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
|
340 /// 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
|
341 /// 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
|
342 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
|
343 ( |
38488d488ec1
dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48134
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 ) |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
349 } |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48018
diff
changeset
|
350 |
48061
060cd909439f
dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48051
diff
changeset
|
351 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
|
352 self.state() == EntryState::Normal |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
353 && self.size() == SIZE_FROM_OTHER_PARENT |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
354 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
355 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
356 // TODO: other platforms |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
357 #[cfg(unix)] |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
358 pub fn mode_changed( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
359 &self, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
360 filesystem_metadata: &std::fs::Metadata, |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
361 ) -> bool { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
362 use std::os::unix::fs::MetadataExt; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 dirstate_exec_bit != fs_exec_bit |
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 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
369 /// 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
|
370 /// `DirstateMapMethods::debug_iter`. |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
371 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
|
372 (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
|
373 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
374 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
375 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
|
376 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
|
377 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
378 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
379 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
|
380 let ambiguous = self.mtime_is_ambiguous(now); |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
381 if ambiguous { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
382 // 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
|
383 // 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
|
384 // 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
|
385 // 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
|
386 // 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
|
387 // 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
|
388 // 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
|
389 // 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
|
390 // 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
|
391 self.set_possibly_dirty() |
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 ambiguous |
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 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
397 impl EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
398 pub fn is_tracked(self) -> bool { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
399 use EntryState::*; |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
400 match self { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
401 Normal | Added | Merged => true, |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
402 Removed => false, |
48018
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
403 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
404 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
405 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
406 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
407 impl TryFrom<u8> for EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
408 type Error = HgError; |
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 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
|
411 match value { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
412 b'n' => Ok(EntryState::Normal), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
413 b'a' => Ok(EntryState::Added), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
414 b'r' => Ok(EntryState::Removed), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
415 b'm' => Ok(EntryState::Merged), |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
416 _ => Err(HgError::CorruptedRepository(format!( |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
417 "Incorrect dirstate entry state {}", |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
418 value |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
419 ))), |
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 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
423 |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
424 impl Into<u8> for EntryState { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
425 fn into(self) -> u8 { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
426 match self { |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
427 EntryState::Normal => b'n', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
428 EntryState::Added => b'a', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
429 EntryState::Removed => b'r', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
430 EntryState::Merged => b'm', |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
431 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
432 } |
08efe5945d2b
rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
433 } |