annotate rust/hg-cpython/src/dirstate/item.rs @ 48260:269ff8978086

dirstate: store mtimes with nanosecond precision in memory Keep integer seconds since the Unix epoch, together with integer nanoseconds in the `0 <= n < 1e9` range. For now, nanoseconds are still always zero. This commit is about data structure changes. Differential Revision: https://phab.mercurial-scm.org/D11684
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 18 Oct 2021 11:23:07 +0200
parents c591944f42c1
children 3d6eb119200d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
1 use cpython::exc;
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
2 use cpython::ObjectProtocol;
48043
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;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
12 use hg::dirstate::TruncatedTimestamp;
48043
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,
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
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: 48134
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: 48134
diff changeset
25 has_meaningful_mtime: bool = true,
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
26 parentfiledata: Option<(u32, u32, (u32, u32))> = None,
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
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: 48252
diff changeset
28 fallback_symlink: Option<bool> = None,
48043
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> {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
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: 48134
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: 48134
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: 48134
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: 48134
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: 48134
diff changeset
36 }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
37 if has_meaningful_mtime {
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
38 mtime_opt = Some(timestamp(py, mtime)?)
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
39 }
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
40 }
48139
ab5a7fdbf75c dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents: 48138
diff changeset
41 let entry = DirstateEntry::from_v2_data(
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
42 wc_tracked,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
43 p1_tracked,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
44 p2_info,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
45 mode_size_opt,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
46 mtime_opt,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
47 fallback_exec,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
48 fallback_symlink,
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
49 );
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
50 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
51 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
52
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
53 @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
54 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
55 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
56 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
57 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
58
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
59 @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
60 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
61 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
62 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
63
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
64 @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
65 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
66 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
67 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
68
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
69 @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
70 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
71 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
72 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
73
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
74 @property
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
75 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: 48194
diff changeset
76 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: 48194
diff changeset
77 Some(_) => Ok(true),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
78 None => Ok(false),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
79 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
80 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
81
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
82 @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
83 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: 48194
diff changeset
84 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: 48194
diff changeset
85 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: 48194
diff changeset
86 None => Ok(None),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
87 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
88 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
89
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
90 @fallback_exec.setter
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
91 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: 48194
diff changeset
92 match value {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
93 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: 48194
diff changeset
94 Some(value) => {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
95 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: 48194
diff changeset
96 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: 48194
diff changeset
97 } else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
98 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: 48194
diff changeset
99 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: 48194
diff changeset
100 );
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
101 }},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
102 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
103 Ok(())
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
104 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
105
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
106 @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
107 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: 48194
diff changeset
108 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: 48194
diff changeset
109 Some(_) => Ok(true),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
110 None => Ok(false),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
111 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
112 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
113
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
114 @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
115 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: 48194
diff changeset
116 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: 48194
diff changeset
117 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: 48194
diff changeset
118 None => Ok(None),
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
119 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
120 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
121
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
122 @fallback_symlink.setter
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
123 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: 48194
diff changeset
124 match value {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
125 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: 48194
diff changeset
126 Some(value) => {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
127 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: 48194
diff changeset
128 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: 48194
diff changeset
129 } else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
130 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: 48194
diff changeset
131 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: 48194
diff changeset
132 );
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
133 }},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
134 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
135 Ok(())
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
136 }
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
137
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48194
diff changeset
138 @property
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
139 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
140 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
141 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
142
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
143 @property
48143
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
144 def p1_tracked(&self) -> PyResult<bool> {
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
145 Ok(self.entry(py).get().p1_tracked())
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
146 }
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
147
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
148 @property
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
149 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
150 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
151 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
152
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
153
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48139
diff changeset
154 @property
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48139
diff changeset
155 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: 48139
diff changeset
156 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: 48139
diff changeset
157 }
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48139
diff changeset
158
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
159 @property
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
160 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
161 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
162 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
163
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
164 @property
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
165 def maybe_clean(&self) -> PyResult<bool> {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
166 Ok(self.entry(py).get().maybe_clean())
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
167 }
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
168
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
169 @property
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
170 def any_tracked(&self) -> PyResult<bool> {
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
171 Ok(self.entry(py).get().any_tracked())
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
172 }
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
173
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
174 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
175 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
176 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
177 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
178 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
179
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
180 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
181 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
182 Ok(mode)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
183 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
184
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
185 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
186 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
187 Ok(size)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
188 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
189
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
190 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
191 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
192 Ok(mtime)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
193 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
194
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
195 def need_delay(&self, now: (u32, u32)) -> PyResult<bool> {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
196 let now = timestamp(py, now)?;
48258
c591944f42c1 dirstate: align Rust function name to `need_delay`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
197 Ok(self.entry(py).get().need_delay(now))
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
198 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
199
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
200 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: 48258
diff changeset
201 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: 48258
diff changeset
202 Ok(mtime.likely_equal(timestamp(py, other)?))
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
203 } else {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
204 Ok(false)
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
205 }
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
206 }
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
207
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
208 @classmethod
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
209 def from_v1_data(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
210 _cls,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
211 state: PyBytes,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
212 mode: i32,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
213 size: i32,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
214 mtime: i32,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
215 ) -> PyResult<Self> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
216 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
217 .ok()
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
218 .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
219 .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
220 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
221 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
222 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
223
48134
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
224 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: 48087
diff changeset
225 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: 48087
diff changeset
226 Ok(PyNone)
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
227 }
3c7db97ce541 dirstate-item: implement `drop_merge_data` on the Rust DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
228
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
229 def set_clean(
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
230 &self,
48194
1000db4a71f1 dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
231 mode: u32,
1000db4a71f1 dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
232 size: u32,
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
233 mtime: (u32, u32),
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
234 ) -> PyResult<PyNone> {
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
235 let mtime = timestamp(py, mtime)?;
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
236 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
237 Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
238 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
239
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
240 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
241 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
242 Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
243 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
244
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
245 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
246 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
247 Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
248 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
249
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
250 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
251 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
252 Ok(PyNone)
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
253 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
254 });
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
255
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
256 impl DirstateItem {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
257 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
258 py: Python<'_>,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
259 entry: DirstateEntry,
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
260 ) -> PyResult<PyObject> {
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
261 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
262 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
263
48045
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
264 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: 48043
diff changeset
265 self.entry(py).get()
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
266 }
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48043
diff changeset
267
48043
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
268 // 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
269 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
270 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
271 f(&mut entry);
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
272 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
273 }
3e69bef2031a rust: Add Python bindings for DirstateEntry as rustext.dirstate.DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
274 }
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
275
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
276 pub(crate) fn timestamp(
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
277 py: Python<'_>,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
278 (s, ns): (u32, u32),
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
279 ) -> PyResult<TruncatedTimestamp> {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
280 TruncatedTimestamp::from_already_truncated(s, ns).map_err(|_| {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
281 PyErr::new::<exc::ValueError, _>(
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
282 py,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
283 "expected mtime truncated to 31 bits",
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
284 )
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
285 })
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48258
diff changeset
286 }