rust/hg-core/src/dirstate/entry.rs
changeset 48022 f2a9db29cb2d
parent 48018 08efe5945d2b
child 48026 1b2ee68e85f9
equal deleted inserted replaced
48021:627cd8f33db0 48022:f2a9db29cb2d
    13 /// The C implementation uses all signed types. This will be an issue
    13 /// The C implementation uses all signed types. This will be an issue
    14 /// either when 4GB+ source files are commonplace or in 2038, whichever
    14 /// either when 4GB+ source files are commonplace or in 2038, whichever
    15 /// comes first.
    15 /// comes first.
    16 #[derive(Debug, PartialEq, Copy, Clone)]
    16 #[derive(Debug, PartialEq, Copy, Clone)]
    17 pub struct DirstateEntry {
    17 pub struct DirstateEntry {
    18     pub state: EntryState,
    18     state: EntryState,
    19     pub mode: i32,
    19     mode: i32,
    20     pub mtime: i32,
    20     size: i32,
    21     pub size: i32,
    21     mtime: i32,
    22 }
    22 }
    23 
    23 
    24 pub const V1_RANGEMASK: i32 = 0x7FFFFFFF;
    24 pub const V1_RANGEMASK: i32 = 0x7FFFFFFF;
    25 
    25 
    26 pub const MTIME_UNSET: i32 = -1;
    26 pub const MTIME_UNSET: i32 = -1;
    32 /// A special value used for internal representation of special case in
    32 /// A special value used for internal representation of special case in
    33 /// dirstate v1 format.
    33 /// dirstate v1 format.
    34 pub const SIZE_NON_NORMAL: i32 = -1;
    34 pub const SIZE_NON_NORMAL: i32 = -1;
    35 
    35 
    36 impl DirstateEntry {
    36 impl DirstateEntry {
       
    37     pub fn from_v1_data(
       
    38         state: EntryState,
       
    39         mode: i32,
       
    40         size: i32,
       
    41         mtime: i32,
       
    42     ) -> Self {
       
    43         Self {
       
    44             state,
       
    45             mode,
       
    46             size,
       
    47             mtime,
       
    48         }
       
    49     }
       
    50 
       
    51     /// Creates a new entry in "removed" state.
       
    52     ///
       
    53     /// `size` is expected to be zero, `SIZE_NON_NORMAL`, or
       
    54     /// `SIZE_FROM_OTHER_PARENT`
       
    55     pub fn new_removed(size: i32) -> Self {
       
    56         Self {
       
    57             state: EntryState::Removed,
       
    58             mode: 0,
       
    59             size,
       
    60             mtime: 0,
       
    61         }
       
    62     }
       
    63 
       
    64     /// TODO: refactor `DirstateMap::add_file` to not take a `DirstateEntry`
       
    65     /// parameter and remove this constructor
       
    66     pub fn new_for_add_file(mode: i32, size: i32, mtime: i32) -> Self {
       
    67         Self {
       
    68             // XXX Arbitrary default value since the value is determined later
       
    69             state: EntryState::Normal,
       
    70             mode,
       
    71             size,
       
    72             mtime,
       
    73         }
       
    74     }
       
    75 
       
    76     pub fn state(&self) -> EntryState {
       
    77         self.state
       
    78     }
       
    79 
       
    80     pub fn mode(&self) -> i32 {
       
    81         self.mode
       
    82     }
       
    83 
       
    84     pub fn size(&self) -> i32 {
       
    85         self.size
       
    86     }
       
    87 
       
    88     pub fn mtime(&self) -> i32 {
       
    89         self.mtime
       
    90     }
       
    91 
       
    92     /// Returns `(state, mode, size, mtime)` for the puprose of serialization
       
    93     /// in the dirstate-v1 format.
       
    94     ///
       
    95     /// This includes marker values such as `mtime == -1`. In the future we may
       
    96     /// want to not represent these cases that way in memory, but serialization
       
    97     /// will need to keep the same format.
       
    98     pub fn v1_data(&self) -> (u8, i32, i32, i32) {
       
    99         (self.state.into(), self.mode, self.size, self.mtime)
       
   100     }
       
   101 
    37     pub fn is_non_normal(&self) -> bool {
   102     pub fn is_non_normal(&self) -> bool {
    38         self.state != EntryState::Normal || self.mtime == MTIME_UNSET
   103         self.state != EntryState::Normal || self.mtime == MTIME_UNSET
    39     }
   104     }
    40 
   105 
    41     pub fn is_from_other_parent(&self) -> bool {
   106     pub fn is_from_other_parent(&self) -> bool {