1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! The object model, the on-disk format primitives, and the typed config of
//! ostree.
//!
//! A caller reads and writes the objects of an ostree repository as bytes in
//! the on-disk format and computes their checksums. The crate also holds the
//! format rules for loose paths, ref names, and new commits. It re-exports the
//! GVariant codec of `ostrya-gvariant` for the metadata of a commit. The
//! module [`config`] reads and edits the keys of a repository `config` file
//! through key types, with no repository handle. The crate opens no file, and
//! it compiles on Linux, macOS, and Windows.
//!
//! # Entry points
//!
//! - [`Checksum`] is the SHA-256 id of an object.
//! - [`Commit`] reads and writes a commit object.
//! - [`DirTree`] and [`DirMeta`] read and write the objects of a directory.
//! - [`FileHeader`] is the header of a content object.
//! - [`Xattrs`] is a sorted set of extended attributes.
//! - [`ObjectType`] and [`RepoMode`] select the [`loose_path`] of an object.
//! - [`DeflateSink`] compresses the payload of an archive-mode content object.
//! - [`KeyFile`] parses and prints the text of the repository `config` file.
//! - [`config::ConfigView`] and [`config::ConfigEdit`] read and edit a
//! [`KeyFile`] through the key types of [`config`].
//! - [`Ref`] is one ref of a repository: local, remote, or collection.
//! - [`RefPattern`] checks and matches one ref pattern with `*` and `**`.
//! - [`RefSelector`] selects ref names with a list of positive and negative
//! patterns.
//!
//! # Modules
//!
//! - [`base64`]: standard base64 for byte strings of any length.
//! - [`config`]: the typed config. It holds the traits of the groups and the
//! keys, the text form of a value, and the typed reads and edits. It also
//! holds the groups `[core]` and `[ex-integrity]`, and the value types of
//! the keys of the port that use no item of `ostrya`.
//! - [`filehdr`]: the content-object header, its framing, and its checksum.
//! - [`sizes`]: the packed entries of the `ostree.sizes` commit metadata.
//! - [`varint`]: the LEB128 varints of the format.
//!
//! # Typed config
//!
//! Each key of `config` is a zero-sized type. The type states the group, the
//! key name, the value type, and the default of the key. The module
//! [`config::repo`] holds the key types of `[core]`, and the module
//! [`config::ex_integrity`] holds the key types of `[ex-integrity]`.
//!
//! - [`config::ConfigView`] reads a [`KeyFile`] through the key types. It has
//! no override, so the value in effect of a key is the value of the file or
//! the default of the key.
//! - [`config::ConfigEdit`] edits a [`KeyFile`] in memory through the key
//! types.
//! - [`config_group!`] defines a group of a library user and its key types.
//! The name of the group starts with `ex-`.
//! - A library user implements [`config::Value`] for each value type of its
//! own.
//! - A typed read and a typed edit give [`config::ConfigError`].
//!
//! The `ostrya` crate re-exports each documented item of [`config`] under
//! `ostrya::config`, and the macro as `ostrya::config_group!`. It adds
//! `RepoConfig` and the other groups of the port. `RepoConfig` applies the
//! overrides of a repository handle and reads the remotes of the remotes
//! directory.
//!
//! `ostrya` reads and writes `config` with a cap of 1 MiB (1048576 bytes). A
//! program that links `ostrya-core` alone reads at most that many bytes before
//! [`KeyFile::parse`]. It does not write a larger document, because the open
//! of `ostrya` refuses such a file.
//!
//! # Examples
//!
//! ```
//! use ostrya_core::{Checksum, DirMeta, ObjectType, RepoMode, Xattrs, loose_path};
//!
//! // The root directory of a commit: uid 0, gid 0, mode 0755, no xattrs.
//! let meta = DirMeta { uid: 0, gid: 0, mode: 0o040755, xattrs: Xattrs::empty() };
//! let checksum = Checksum::sha256(&meta.serialize()?);
//! let hex = "446a0ef11b7cc167f3b603e585c7eeeeb675faa412d5ec73f62988eb0b6c5488";
//! assert_eq!(checksum.to_hex(), hex);
//! let path = loose_path(&checksum, ObjectType::DirMeta, RepoMode::Bare);
//! assert_eq!(path, format!("44/{}.dirmeta", &hex[2..]));
//! # Ok::<(), ostrya_core::Error>(())
//! ```
//!
//! A library user defines a group, reads the group and a key of `[core]`, and
//! edits the key file:
//!
//! ```
//! use ostrya_core::config::{ConfigEdit, ConfigView, Tristate, ex_integrity, repo};
//! use ostrya_core::{KeyFile, RepoMode};
//!
//! ostrya_core::config_group! {
//! /// The keys of a build tool.
//! pub group tool = "ex-tool" {
//! /// The number of parallel jobs.
//! Jobs: u32 = "jobs", default 4;
//! }
//! }
//!
//! let mut kf = KeyFile::parse("[core]\nrepo_version=1\nmode=bare\n[ex-tool]\njobs=8\n")?;
//! let view = ConfigView::new(&kf);
//! assert_eq!(view.get::<repo::Mode>()?, RepoMode::Bare);
//! assert_eq!(view.get::<tool::Jobs>()?, 8);
//!
//! ConfigEdit::new(&mut kf).set::<ex_integrity::Fsverity>(Tristate::No)?;
//! assert_eq!(kf.get_value("ex-integrity", "fsverity"), Some("no"));
//! # Ok::<(), ostrya_core::config::ConfigError>(())
//! ```
pub use Checksum;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use KeyFile;
pub use loose_path;
pub use RepoMode;
pub use ObjectName;
pub use ObjectType;
pub use ;
pub use ;
pub use ;
// The dynamic GVariant value tree and the codec functions. `Commit::metadata`
// is a `Value`. With these re-exports, a dependent crate can read and write
// any metadata dict with no direct dependency on `ostrya-gvariant`.
pub use ;
/// The size limit of a metadata object: 128 MiB.
///
/// The format sets this limit. A reader loads a metadata object whole, so it
/// must refuse a larger object.
pub const MAX_METADATA_SIZE: u64 = 128 * 1024 * 1024;