annotate rust/hg-core/src/dirstate/entry.rs @ 48161:20e41b367953

dirstate-item: drop the legacy new_possibly_dirty constructor Nobody is calling it anymore. Its purposes has been filled. Differential Revision: https://phab.mercurial-scm.org/D11605
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 01 Oct 2021 09:25:13 +0200
parents 898de425bcd6
children d0081dbca442
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
48158
da304f78a0e1 dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48157
diff changeset
71 Self {
da304f78a0e1 dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48157
diff changeset
72 // might be missing P1_TRACKED
da304f78a0e1 dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48157
diff changeset
73 flags: Flags::WDIR_TRACKED | Flags::P2_INFO,
da304f78a0e1 dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48157
diff changeset
74 mode_size: None,
da304f78a0e1 dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48157
diff changeset
75 mtime: None,
da304f78a0e1 dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48157
diff changeset
76 }
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
77 } else if size == SIZE_NON_NORMAL {
48160
898de425bcd6 dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48159
diff changeset
78 Self {
898de425bcd6 dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48159
diff changeset
79 flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED,
898de425bcd6 dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48159
diff changeset
80 mode_size: None,
898de425bcd6 dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48159
diff changeset
81 mtime: None,
898de425bcd6 dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48159
diff changeset
82 }
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
83 } else if mtime == MTIME_UNSET {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
84 Self {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
85 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
86 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
87 mtime: None,
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
88 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
89 } else {
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
90 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
91 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
92 }
48156
d342815ff827 dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48155
diff changeset
93 EntryState::Added => Self {
d342815ff827 dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48155
diff changeset
94 flags: Flags::WDIR_TRACKED,
d342815ff827 dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48155
diff changeset
95 mode_size: None,
d342815ff827 dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48155
diff changeset
96 mtime: None,
d342815ff827 dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48155
diff changeset
97 },
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
98 EntryState::Removed => Self {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
99 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
100 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
101 } 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
102 // 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
103 Flags::P2_INFO
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
104 } else {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
105 Flags::P1_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
106 },
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
107 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
108 mtime: None,
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
109 },
48154
7a8c9869e4fe dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48153
diff changeset
110 EntryState::Merged => Self {
7a8c9869e4fe dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48153
diff changeset
111 flags: Flags::WDIR_TRACKED
7a8c9869e4fe dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48153
diff changeset
112 | 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
113 | 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
114 mode_size: None,
7a8c9869e4fe dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48153
diff changeset
115 mtime: None,
7a8c9869e4fe dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48153
diff changeset
116 },
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
117 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
118 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
119
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
120 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
121 Self {
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
122 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
123 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
124 mtime: Some(mtime),
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
125 }
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
126 }
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
127
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
128 /// 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
129 ///
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
130 /// `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
131 /// `SIZE_FROM_OTHER_PARENT`
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
132 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
133 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
134 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
135
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
136 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
137 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
138 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
139
48143
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
140 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
141 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
142 }
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
143
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
144 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
145 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
146 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
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 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
149 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
150 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
151
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
152 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
153 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
154 }
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48139
diff changeset
155
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
156 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
157 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
158 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
159
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
160 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
161 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
162 false
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
163 } 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
164 false
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
165 } 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
166 false
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
167 } else {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
168 true
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
169 }
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
170 }
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
171
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
172 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
173 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
174 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
175 )
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
176 }
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
177
48139
ab5a7fdbf75c dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents: 48138
diff changeset
178 /// 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
179 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
180 &self,
ab5a7fdbf75c dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents: 48138
diff changeset
181 ) -> (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
182 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
183 // 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
184 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
185 }
ab5a7fdbf75c dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents: 48138
diff changeset
186 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
187 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
188 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
189 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
190 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
191 (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
192 }
ab5a7fdbf75c dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents: 48138
diff changeset
193
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
194 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
195 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
196 // 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
197 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
198 }
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
199 if self.removed() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
200 EntryState::Removed
48152
8f88307f8e07 dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48150
diff changeset
201 } else if self
8f88307f8e07 dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48150
diff changeset
202 .flags
8f88307f8e07 dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48150
diff changeset
203 .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
204 {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
205 EntryState::Merged
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
206 } else if self.added() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
207 EntryState::Added
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
208 } else {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
209 EntryState::Normal
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
210 }
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
211 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
212
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
213 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
214 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
215 mode
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
216 } else {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
217 0
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
218 }
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
219 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
220
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
221 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
222 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
223 // 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
224 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
225 }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
226 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
227 && 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
228 {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
229 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
230 } 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
231 SIZE_FROM_OTHER_PARENT
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
232 } else if self.removed() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
233 0
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
234 } else if self.added() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
235 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
236 } 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
237 size
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
238 } else {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
239 SIZE_NON_NORMAL
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
240 }
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
241 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
242
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
243 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
244 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
245 // 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
246 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
247 }
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
248 if self.removed() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
249 0
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
250 } 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
251 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
252 } 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
253 MTIME_UNSET
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
254 } else {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
255 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
256 }
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
257 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
258
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
259 // 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
260 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
261 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
262 }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
263
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
264 // 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
265 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
266 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
267 }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
268
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
269 // 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
270 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
271 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
272 }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
273
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
274 // 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
275 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
276 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
277 }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
278
48134
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
279 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
280 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
281 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
282 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
283 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
284 }
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
285 }
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
286
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
287 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
288 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
289 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
290
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
291 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
292 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
293 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
294 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
295 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
296
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
297 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
298 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
299 // `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
300 // 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
301 //
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
302 // 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
303 // broad.
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
304 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
305 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
306
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
307 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
308 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
309 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
310 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
311 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
312
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
313 /// 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
314 /// in the dirstate-v1 format.
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
315 ///
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
316 /// 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
317 /// 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
318 /// 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
319 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
320 (
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
321 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
322 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
323 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
324 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
325 )
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
326 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
327
48061
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48051
diff changeset
328 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
329 self.state() == EntryState::Normal
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
330 && self.size() == SIZE_FROM_OTHER_PARENT
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
331 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
332
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
333 // TODO: other platforms
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
334 #[cfg(unix)]
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
335 pub fn mode_changed(
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
336 &self,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
337 filesystem_metadata: &std::fs::Metadata,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
338 ) -> bool {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
339 use std::os::unix::fs::MetadataExt;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
340 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
341 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
342 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
343 dirstate_exec_bit != fs_exec_bit
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
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
346 /// 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
347 /// `DirstateMapMethods::debug_iter`.
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
348 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
349 (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
350 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
351
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
352 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
353 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
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 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
357 let ambiguous = self.mtime_is_ambiguous(now);
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
358 if ambiguous {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
359 // 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
360 // 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
361 // 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
362 // 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
363 // 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
364 // 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
365 // 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
366 // 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
367 // 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
368 self.set_possibly_dirty()
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
369 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
370 ambiguous
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
371 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
372 }
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 impl EntryState {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
375 pub fn is_tracked(self) -> bool {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
376 use EntryState::*;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
377 match self {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
378 Normal | Added | Merged => true,
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
379 Removed => false,
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
380 }
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 }
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 impl TryFrom<u8> for EntryState {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
385 type Error = HgError;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
386
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
387 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
388 match value {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
389 b'n' => Ok(EntryState::Normal),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
390 b'a' => Ok(EntryState::Added),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
391 b'r' => Ok(EntryState::Removed),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
392 b'm' => Ok(EntryState::Merged),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
393 _ => Err(HgError::CorruptedRepository(format!(
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
394 "Incorrect dirstate entry state {}",
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
395 value
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 }
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 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
400
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
401 impl Into<u8> for EntryState {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
402 fn into(self) -> u8 {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
403 match self {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
404 EntryState::Normal => b'n',
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
405 EntryState::Added => b'a',
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
406 EntryState::Removed => b'r',
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
407 EntryState::Merged => b'm',
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 }