rust/hg-cpython/src/dirstate/item.rs
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 19 Nov 2021 03:04:42 +0100
changeset 48440 434de12918fd
parent 48426 3d6eb119200d
child 48446 111098af6356
permissions -rw-r--r--
dirstate: remove need_delay logic Now that all¹ stored mtime are non ambiguous, we no longer need to apply the `need_delay` step. The need delay logic was not great are mtime gathered during longer operation could be ambiguous but younger than the `dirstate.write` call time. So, we don't need that logic anymore and can drop it This make the code much simpler. The code related to the test extension faking the dirstate write is now obsolete and associated test will be migrated as follow up. They currently do not break. [1] except the ones from `hg update`, but `need_delay` no longer help for them either. Differential Revision: https://phab.mercurial-scm.org/D11796
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     1
use cpython::exc;
48263
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
     2
use cpython::ObjectProtocol;
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     3
use cpython::PyBytes;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     4
use cpython::PyErr;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     5
use cpython::PyNone;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     6
use cpython::PyObject;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     7
use cpython::PyResult;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     8
use cpython::Python;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     9
use cpython::PythonObject;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    10
use hg::dirstate::DirstateEntry;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    11
use hg::dirstate::EntryState;
48271
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
    12
use hg::dirstate::TruncatedTimestamp;
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    13
use std::cell::Cell;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    14
use std::convert::TryFrom;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    15
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    16
py_class!(pub class DirstateItem |py| {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    17
    data entry: Cell<DirstateEntry>;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    18
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    19
    def __new__(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    20
        _cls,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    21
        wc_tracked: bool = false,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    22
        p1_tracked: bool = false,
48150
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    23
        p2_info: bool = false,
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    24
        has_meaningful_data: bool = true,
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    25
        has_meaningful_mtime: bool = true,
48426
3d6eb119200d dirstate-item: allow mtime to be None in "parentdata"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
    26
        parentfiledata: Option<(u32, u32, Option<(u32, u32)>)> = None,
48264
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    27
        fallback_exec: Option<bool> = None,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    28
        fallback_symlink: Option<bool> = None,
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    29
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    30
    ) -> PyResult<DirstateItem> {
48150
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    31
        let mut mode_size_opt = None;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    32
        let mut mtime_opt = None;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    33
        if let Some((mode, size, mtime)) = parentfiledata {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    34
            if has_meaningful_data {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    35
                mode_size_opt = Some((mode, size))
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    36
            }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    37
            if has_meaningful_mtime {
48426
3d6eb119200d dirstate-item: allow mtime to be None in "parentdata"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
    38
                if let Some(m) = mtime {
3d6eb119200d dirstate-item: allow mtime to be None in "parentdata"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
    39
                    mtime_opt = Some(timestamp(py, m)?);
3d6eb119200d dirstate-item: allow mtime to be None in "parentdata"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
    40
                }
48150
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    41
            }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    42
        }
48151
ab5a7fdbf75c dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents: 48150
diff changeset
    43
        let entry = DirstateEntry::from_v2_data(
48264
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    44
            wc_tracked,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    45
            p1_tracked,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    46
            p2_info,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    47
            mode_size_opt,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    48
            mtime_opt,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    49
            fallback_exec,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
    50
            fallback_symlink,
48150
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48146
diff changeset
    51
        );
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    52
        DirstateItem::create_instance(py, Cell::new(entry))
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    53
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    54
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    55
    @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    56
    def state(&self) -> PyResult<PyBytes> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    57
        let state_byte: u8 = self.entry(py).get().state().into();
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    58
        Ok(PyBytes::new(py, &[state_byte]))
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    59
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    60
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    61
    @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    62
    def mode(&self) -> PyResult<i32> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    63
        Ok(self.entry(py).get().mode())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    64
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    65
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    66
    @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    67
    def size(&self) -> PyResult<i32> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    68
        Ok(self.entry(py).get().size())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    69
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    70
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    71
    @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    72
    def mtime(&self) -> PyResult<i32> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    73
        Ok(self.entry(py).get().mtime())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    74
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    75
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    76
    @property
48263
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    77
    def has_fallback_exec(&self) -> PyResult<bool> {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    78
        match self.entry(py).get().get_fallback_exec() {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    79
            Some(_) => Ok(true),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    80
            None => Ok(false),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    81
        }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    82
    }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    83
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    84
    @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    85
    def fallback_exec(&self) -> PyResult<Option<bool>> {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    86
        match self.entry(py).get().get_fallback_exec() {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    87
            Some(exec) => Ok(Some(exec)),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    88
            None => Ok(None),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    89
        }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    90
    }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    91
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    92
    @fallback_exec.setter
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    93
    def set_fallback_exec(&self, value: Option<PyObject>) -> PyResult<()> {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    94
        match value {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    95
            None => {self.entry(py).get().set_fallback_exec(None);},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    96
            Some(value) => {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    97
            if value.is_none(py) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    98
                self.entry(py).get().set_fallback_exec(None);
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
    99
            } else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   100
                self.entry(py).get().set_fallback_exec(
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   101
                    Some(value.is_true(py)?)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   102
                );
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   103
            }},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   104
        }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   105
        Ok(())
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   106
    }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   107
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   108
    @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   109
    def has_fallback_symlink(&self) -> PyResult<bool> {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   110
        match self.entry(py).get().get_fallback_symlink() {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   111
            Some(_) => Ok(true),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   112
            None => Ok(false),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   113
        }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   114
    }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   115
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   116
    @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   117
    def fallback_symlink(&self) -> PyResult<Option<bool>> {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   118
        match self.entry(py).get().get_fallback_symlink() {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   119
            Some(symlink) => Ok(Some(symlink)),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   120
            None => Ok(None),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   121
        }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   122
    }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   123
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   124
    @fallback_symlink.setter
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   125
    def set_fallback_symlink(&self, value: Option<PyObject>) -> PyResult<()> {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   126
        match value {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   127
            None => {self.entry(py).get().set_fallback_symlink(None);},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   128
            Some(value) => {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   129
            if value.is_none(py) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   130
                self.entry(py).get().set_fallback_symlink(None);
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   131
            } else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   132
                self.entry(py).get().set_fallback_symlink(
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   133
                    Some(value.is_true(py)?)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   134
                );
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   135
            }},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   136
        }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   137
        Ok(())
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   138
    }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   139
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48206
diff changeset
   140
    @property
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   141
    def tracked(&self) -> PyResult<bool> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   142
        Ok(self.entry(py).get().tracked())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   143
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   144
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   145
    @property
48155
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48154
diff changeset
   146
    def p1_tracked(&self) -> PyResult<bool> {
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48154
diff changeset
   147
        Ok(self.entry(py).get().p1_tracked())
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48154
diff changeset
   148
    }
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48154
diff changeset
   149
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48154
diff changeset
   150
    @property
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   151
    def added(&self) -> PyResult<bool> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   152
        Ok(self.entry(py).get().added())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   153
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   154
48154
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48151
diff changeset
   155
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48151
diff changeset
   156
    @property
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48151
diff changeset
   157
    def p2_info(&self) -> PyResult<bool> {
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48151
diff changeset
   158
        Ok(self.entry(py).get().p2_info())
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48151
diff changeset
   159
    }
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48151
diff changeset
   160
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   161
    @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   162
    def removed(&self) -> PyResult<bool> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   163
        Ok(self.entry(py).get().removed())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   164
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   165
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   166
    @property
48098
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48082
diff changeset
   167
    def maybe_clean(&self) -> PyResult<bool> {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48082
diff changeset
   168
        Ok(self.entry(py).get().maybe_clean())
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48082
diff changeset
   169
    }
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48082
diff changeset
   170
48099
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48098
diff changeset
   171
    @property
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48098
diff changeset
   172
    def any_tracked(&self) -> PyResult<bool> {
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48098
diff changeset
   173
        Ok(self.entry(py).get().any_tracked())
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48098
diff changeset
   174
    }
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48098
diff changeset
   175
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   176
    def v1_state(&self) -> PyResult<PyBytes> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   177
        let (state, _mode, _size, _mtime) = self.entry(py).get().v1_data();
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   178
        let state_byte: u8 = state.into();
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   179
        Ok(PyBytes::new(py, &[state_byte]))
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   180
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   181
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   182
    def v1_mode(&self) -> PyResult<i32> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   183
        let (_state, mode, _size, _mtime) = self.entry(py).get().v1_data();
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   184
        Ok(mode)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   185
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   186
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   187
    def v1_size(&self) -> PyResult<i32> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   188
        let (_state, _mode, size, _mtime) = self.entry(py).get().v1_data();
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   189
        Ok(size)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   190
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   191
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   192
    def v1_mtime(&self) -> PyResult<i32> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   193
        let (_state, _mode, _size, mtime) = self.entry(py).get().v1_data();
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   194
        Ok(mtime)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   195
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   196
48271
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   197
    def mtime_likely_equal_to(&self, other: (u32, u32)) -> PyResult<bool> {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   198
        if let Some(mtime) = self.entry(py).get().truncated_mtime() {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   199
            Ok(mtime.likely_equal(timestamp(py, other)?))
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   200
        } else {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   201
            Ok(false)
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   202
        }
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   203
    }
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   204
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   205
    @classmethod
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   206
    def from_v1_data(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   207
        _cls,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   208
        state: PyBytes,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   209
        mode: i32,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   210
        size: i32,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   211
        mtime: i32,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   212
    ) -> PyResult<Self> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   213
        let state = <[u8; 1]>::try_from(state.data(py))
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   214
            .ok()
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   215
            .and_then(|state| EntryState::try_from(state[0]).ok())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   216
            .ok_or_else(|| PyErr::new::<exc::ValueError, _>(py, "invalid state"))?;
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   217
        let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   218
        DirstateItem::create_instance(py, Cell::new(entry))
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   219
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   220
48146
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48099
diff changeset
   221
    def drop_merge_data(&self) -> PyResult<PyNone> {
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48099
diff changeset
   222
        self.update(py, |entry| entry.drop_merge_data());
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48099
diff changeset
   223
        Ok(PyNone)
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48099
diff changeset
   224
    }
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48099
diff changeset
   225
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   226
    def set_clean(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   227
        &self,
48206
1000db4a71f1 dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents: 48176
diff changeset
   228
        mode: u32,
1000db4a71f1 dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents: 48176
diff changeset
   229
        size: u32,
48271
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   230
        mtime: (u32, u32),
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   231
    ) -> PyResult<PyNone> {
48271
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   232
        let mtime = timestamp(py, mtime)?;
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   233
        self.update(py, |entry| entry.set_clean(mode, size, mtime));
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   234
        Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   235
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   236
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   237
    def set_possibly_dirty(&self) -> PyResult<PyNone> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   238
        self.update(py, |entry| entry.set_possibly_dirty());
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   239
        Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   240
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   241
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   242
    def set_tracked(&self) -> PyResult<PyNone> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   243
        self.update(py, |entry| entry.set_tracked());
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   244
        Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   245
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   246
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   247
    def set_untracked(&self) -> PyResult<PyNone> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   248
        self.update(py, |entry| entry.set_untracked());
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   249
        Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   250
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   251
});
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   252
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   253
impl DirstateItem {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   254
    pub fn new_as_pyobject(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   255
        py: Python<'_>,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   256
        entry: DirstateEntry,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   257
    ) -> PyResult<PyObject> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   258
        Ok(DirstateItem::create_instance(py, Cell::new(entry))?.into_object())
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   259
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   260
48060
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48058
diff changeset
   261
    pub fn get_entry(&self, py: Python<'_>) -> DirstateEntry {
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48058
diff changeset
   262
        self.entry(py).get()
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48058
diff changeset
   263
    }
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48058
diff changeset
   264
48058
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   265
    // TODO: Use https://doc.rust-lang.org/std/cell/struct.Cell.html#method.update instead when it’s stable
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   266
    pub fn update(&self, py: Python<'_>, f: impl FnOnce(&mut DirstateEntry)) {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   267
        let mut entry = self.entry(py).get();
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   268
        f(&mut entry);
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   269
        self.entry(py).set(entry)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   270
    }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   271
}
48271
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   272
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   273
pub(crate) fn timestamp(
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   274
    py: Python<'_>,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   275
    (s, ns): (u32, u32),
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   276
) -> PyResult<TruncatedTimestamp> {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   277
    TruncatedTimestamp::from_already_truncated(s, ns).map_err(|_| {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   278
        PyErr::new::<exc::ValueError, _>(
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   279
            py,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   280
            "expected mtime truncated to 31 bits",
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   281
        )
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   282
    })
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48269
diff changeset
   283
}