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