annotate rust/hg-core/src/dirstate/entry.rs @ 48134:3c7db97ce541

dirstate-item: implement `drop_merge_data` on the Rust DirstateItem It was currently missing and we want to be able to use in it the Rust case too. Differential Revision: https://phab.mercurial-scm.org/D11579
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 02 Oct 2021 00:14:32 +0200
parents 79bc60ca5946
children 38488d488ec1
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 {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
18 flags: Flags,
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
19 mode: i32,
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
20 size: i32,
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
21 mtime: i32,
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
22 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
23
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
24 bitflags! {
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
25 pub struct Flags: u8 {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
26 const WDIR_TRACKED = 1 << 0;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
27 const P1_TRACKED = 1 << 1;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
28 const P2_TRACKED = 1 << 2;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
29 const POSSIBLY_DIRTY = 1 << 3;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
30 const MERGED = 1 << 4;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
31 const CLEAN_P1 = 1 << 5;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
32 const CLEAN_P2 = 1 << 6;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
33 const ENTRYLESS_TREE_NODE = 1 << 7;
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
34 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
35 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
36
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
37 pub const V1_RANGEMASK: i32 = 0x7FFFFFFF;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
38
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
39 pub const MTIME_UNSET: i32 = -1;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
40
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
41 /// 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
42 /// 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
43 /// merge.
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
44 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
45 /// 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
46 /// dirstate v1 format.
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
47 pub const SIZE_NON_NORMAL: i32 = -1;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
48
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
49 impl DirstateEntry {
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
50 pub fn new(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
51 flags: Flags,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
52 mode_size_mtime: Option<(i32, i32, i32)>,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
53 ) -> Self {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
54 let (mode, size, mtime) =
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
55 mode_size_mtime.unwrap_or((0, SIZE_NON_NORMAL, MTIME_UNSET));
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
56 Self {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
57 flags,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
58 mode,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
59 size,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
60 mtime,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
61 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
62 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
63
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
64 pub fn from_v1_data(
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
65 state: EntryState,
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
66 mode: i32,
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
67 size: i32,
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
68 mtime: i32,
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
69 ) -> Self {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
70 match state {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
71 EntryState::Normal => {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
72 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
73 Self::new_from_p2()
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
74 } 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
75 Self::new_possibly_dirty()
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
76 } else if mtime == MTIME_UNSET {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
77 Self {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
78 flags: Flags::WDIR_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
79 | Flags::P1_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
80 | Flags::POSSIBLY_DIRTY,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
81 mode,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
82 size,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
83 mtime: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
84 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
85 } else {
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
86 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
87 }
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 EntryState::Added => Self::new_added(),
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
90 EntryState::Removed => Self {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
91 flags: if size == SIZE_NON_NORMAL {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
92 Flags::P1_TRACKED // might not be true because of rename ?
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
93 | Flags::P2_TRACKED // might not be true because of rename ?
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
94 | Flags::MERGED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
95 } 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
96 // We don’t know if P1_TRACKED should be set (file history)
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
97 Flags::P2_TRACKED | Flags::CLEAN_P2
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
98 } else {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
99 Flags::P1_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
100 },
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
101 mode: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
102 size: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
103 mtime: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
104 },
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
105 EntryState::Merged => Self::new_merged(),
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
106 }
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
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
109 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
110 Self {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
111 // might be missing P1_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
112 flags: Flags::WDIR_TRACKED | Flags::P2_TRACKED | Flags::CLEAN_P2,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
113 mode: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
114 size: SIZE_FROM_OTHER_PARENT,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
115 mtime: MTIME_UNSET,
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 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
118
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
119 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
120 Self {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
121 flags: Flags::WDIR_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
122 | Flags::P1_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
123 | Flags::POSSIBLY_DIRTY,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
124 mode: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
125 size: SIZE_NON_NORMAL,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
126 mtime: MTIME_UNSET,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
127 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
128 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
129
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
130 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
131 Self {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
132 flags: Flags::WDIR_TRACKED,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
133 mode: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
134 size: SIZE_NON_NORMAL,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
135 mtime: MTIME_UNSET,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
136 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
137 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
138
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
139 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
140 Self {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
141 flags: Flags::WDIR_TRACKED
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
142 | Flags::P1_TRACKED // might not be true because of rename ?
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
143 | Flags::P2_TRACKED // might not be true because of rename ?
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
144 | Flags::MERGED,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
145 mode: 0,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
146 size: SIZE_NON_NORMAL,
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
147 mtime: MTIME_UNSET,
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
148 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
149 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
150
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
151 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
152 Self {
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
153 flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED,
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
154 mode,
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
155 size,
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
156 mtime,
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
157 }
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
158 }
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
159
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
160 /// 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
161 ///
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
162 /// `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
163 /// `SIZE_FROM_OTHER_PARENT`
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
164 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
165 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
166 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
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 tracked(&self) -> bool {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
169 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
170 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
171
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
172 fn tracked_in_any_parent(&self) -> bool {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
173 self.flags.intersects(Flags::P1_TRACKED | Flags::P2_TRACKED)
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
174 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
175
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
176 pub fn removed(&self) -> bool {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
177 self.tracked_in_any_parent()
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
178 && !self.flags.contains(Flags::WDIR_TRACKED)
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
179 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
180
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
181 pub fn merged(&self) -> bool {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
182 self.flags.contains(Flags::WDIR_TRACKED | Flags::MERGED)
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
183 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
184
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
185 pub fn added(&self) -> bool {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
186 self.flags.contains(Flags::WDIR_TRACKED)
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
187 && !self.tracked_in_any_parent()
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
188 }
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
189
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
190 pub fn from_p2(&self) -> bool {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
191 self.flags.contains(Flags::WDIR_TRACKED | Flags::CLEAN_P2)
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
192 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
193
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
194 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
195 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
196 false
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
197 } else if self.added() {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
198 false
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
199 } else if self.flags.contains(Flags::MERGED) {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
200 false
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
201 } else if self.flags.contains(Flags::CLEAN_P2) {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
202 false
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
203 } else {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
204 true
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
205 }
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
206 }
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
207
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
208 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
209 self.flags.intersects(
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
210 Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_TRACKED,
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
211 )
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
212 }
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
213
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
214 pub fn state(&self) -> EntryState {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
215 if self.removed() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
216 EntryState::Removed
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
217 } else if self.merged() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
218 EntryState::Merged
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
219 } else if self.added() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
220 EntryState::Added
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
221 } else {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
222 EntryState::Normal
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
223 }
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
224 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
225
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
226 pub fn mode(&self) -> i32 {
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
227 self.mode
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
228 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
229
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
230 pub fn size(&self) -> i32 {
48064
2943955304b3 dirstate: inline the merged_removed logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48061
diff changeset
231 if self.removed() && self.flags.contains(Flags::MERGED) {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
232 SIZE_NON_NORMAL
48066
7a2de2bd9fcd dirstate: inline the `from_p2_removed` logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48065
diff changeset
233 } else if self.removed() && self.flags.contains(Flags::CLEAN_P2) {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
234 SIZE_FROM_OTHER_PARENT
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
235 } else if self.removed() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
236 0
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
237 } else if self.merged() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
238 SIZE_FROM_OTHER_PARENT
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
239 } else if self.added() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
240 SIZE_NON_NORMAL
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
241 } else if self.from_p2() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
242 SIZE_FROM_OTHER_PARENT
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
243 } else if self.flags.contains(Flags::POSSIBLY_DIRTY) {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
244 self.size // TODO: SIZE_NON_NORMAL ?
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
245 } else {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
246 self.size
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
247 }
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
248 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
249
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
250 pub fn mtime(&self) -> i32 {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
251 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.flags.contains(Flags::POSSIBLY_DIRTY) {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
254 MTIME_UNSET
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
255 } else if self.merged() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
256 MTIME_UNSET
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
257 } else if self.added() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
258 MTIME_UNSET
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
259 } else if self.from_p2() {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
260 MTIME_UNSET
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
261 } else {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
262 self.mtime
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
48134
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
266 pub fn drop_merge_data(&mut self) {
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
267 if self.flags.contains(Flags::CLEAN_P1)
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
268 || self.flags.contains(Flags::CLEAN_P2)
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
269 || self.flags.contains(Flags::MERGED)
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
270 || self.flags.contains(Flags::P2_TRACKED)
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
271 {
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
272 if self.flags.contains(Flags::MERGED) {
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
273 self.flags.insert(Flags::P1_TRACKED);
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
274 } else {
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
275 self.flags.remove(Flags::P1_TRACKED);
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
276 }
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
277 self.flags.remove(
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
278 Flags::MERGED
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
279 | Flags::CLEAN_P1
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
280 | Flags::CLEAN_P2
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
281 | Flags::P2_TRACKED,
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
282 );
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
283 self.flags.insert(Flags::POSSIBLY_DIRTY);
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
284 self.mode = 0;
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
285 self.mtime = 0;
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
286 // size = None on the python size turn into size = NON_NORMAL when
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
287 // accessed. So the next line is currently required, but a some
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
288 // future clean up would be welcome.
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
289 self.size = SIZE_NON_NORMAL;
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
290 }
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
291 }
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
292
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
293 pub fn set_possibly_dirty(&mut self) {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
294 self.flags.insert(Flags::POSSIBLY_DIRTY)
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_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
298 self.flags.insert(Flags::WDIR_TRACKED | Flags::P1_TRACKED);
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
299 self.flags.remove(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
300 Flags::P2_TRACKED // This might be wrong
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
301 | Flags::MERGED
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
302 | Flags::CLEAN_P2
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
303 | Flags::POSSIBLY_DIRTY,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
304 );
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
305 self.mode = mode;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
306 self.size = size;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
307 self.mtime = mtime;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
308 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
309
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_tracked(&mut self) {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
311 self.flags
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
312 .insert(Flags::WDIR_TRACKED | Flags::POSSIBLY_DIRTY);
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
313 // size = None on the python size turn into size = NON_NORMAL when
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
314 // accessed. So the next line is currently required, but a some future
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
315 // clean up would be welcome.
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
316 self.size = SIZE_NON_NORMAL;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
317 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
318
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
319 pub fn set_untracked(&mut self) {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
320 self.flags.remove(Flags::WDIR_TRACKED);
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
321 self.mode = 0;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
322 self.size = 0;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
323 self.mtime = 0;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
324 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
325
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
326 /// 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
327 /// in the dirstate-v1 format.
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
328 ///
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
329 /// 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
330 /// 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
331 /// 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
332 pub fn v1_data(&self) -> (u8, i32, i32, i32) {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
333 (self.state().into(), self.mode(), self.size(), self.mtime())
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
334 }
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
335
48061
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48051
diff changeset
336 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
337 self.state() == EntryState::Normal
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
338 && self.size() == SIZE_FROM_OTHER_PARENT
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
339 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
340
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
341 // TODO: other platforms
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
342 #[cfg(unix)]
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
343 pub fn mode_changed(
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
344 &self,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
345 filesystem_metadata: &std::fs::Metadata,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
346 ) -> bool {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
347 use std::os::unix::fs::MetadataExt;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
348 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
349 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
350 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
351 dirstate_exec_bit != fs_exec_bit
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
352 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
353
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
354 /// 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
355 /// `DirstateMapMethods::debug_iter`.
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
356 pub fn debug_tuple(&self) -> (u8, i32, i32, i32) {
48042
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
357 let state = if self.flags.contains(Flags::ENTRYLESS_TREE_NODE) {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
358 b' '
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
359 } else {
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
360 self.state().into()
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
361 };
008959fcbfb2 rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48026
diff changeset
362 (state, self.mode(), self.size(), self.mtime())
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
363 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
364
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
365 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
366 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
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 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
370 let ambiguous = self.mtime_is_ambiguous(now);
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
371 if ambiguous {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
372 // 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
373 // 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
374 // 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
375 // 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
376 // 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
377 // 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
378 // 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
379 // 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
380 // mistakenly treating such files as clean.
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
381 self.clear_mtime()
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 ambiguous
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
384 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
385
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
386 pub fn clear_mtime(&mut self) {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
387 self.mtime = -1;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
388 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
389 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
390
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
391 impl EntryState {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
392 pub fn is_tracked(self) -> bool {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
393 use EntryState::*;
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
394 match self {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
395 Normal | Added | Merged => true,
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
396 Removed => false,
48018
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 TryFrom<u8> for EntryState {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
402 type Error = HgError;
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 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
405 match value {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
406 b'n' => Ok(EntryState::Normal),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
407 b'a' => Ok(EntryState::Added),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
408 b'r' => Ok(EntryState::Removed),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
409 b'm' => Ok(EntryState::Merged),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
410 _ => Err(HgError::CorruptedRepository(format!(
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
411 "Incorrect dirstate entry state {}",
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
412 value
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
413 ))),
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
414 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
415 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
416 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
417
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
418 impl Into<u8> for EntryState {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
419 fn into(self) -> u8 {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
420 match self {
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
421 EntryState::Normal => b'n',
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
422 EntryState::Added => b'a',
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
423 EntryState::Removed => b'r',
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
424 EntryState::Merged => b'm',
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
425 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
426 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
427 }