xvc_core/
lib.rs

1//! Xvc Core Library for common operations
2#![warn(missing_docs)]
3#![forbid(unsafe_code)]
4pub mod check_ignore;
5pub mod error;
6pub mod root;
7pub mod types;
8pub mod util;
9
10pub use types::hashalgorithm::HashAlgorithm;
11pub use types::recheckmethod::RecheckMethod;
12
13pub use types::xvcdigest::content_digest::ContentDigest;
14pub use types::xvcdigest::path_collection_digest::PathCollectionDigest;
15pub use types::xvcdigest::stdout_digest::StdoutDigest;
16pub use types::xvcdigest::url_get_digest::UrlContentDigest;
17pub use types::xvcdigest::xvc_metadata_digest::XvcMetadataDigest;
18pub use types::xvcdigest::AttributeDigest;
19pub use types::xvcdigest::XvcDigest;
20pub use types::xvcdigest::XvcDigests;
21
22pub use types::diff::Diff;
23pub use types::diff::DiffStore;
24pub use types::diff::DiffStore2;
25pub use types::diff::DiffStore3;
26pub use types::diff::DiffStore4;
27
28pub use types::diff::apply_diff;
29pub use types::diff::diff_store;
30pub use types::diff::update_with_actual;
31
32pub use types::xvcfiletype::XvcFileType;
33pub use types::xvcmetadata::XvcMetadata;
34pub use types::xvcpath::TextOrBinary;
35pub use types::xvcpath::XvcCachePath;
36pub use types::xvcpath::XvcPath;
37pub use types::xvcroot::XvcRoot;
38
39pub use error::Error;
40pub use error::Result;
41
42// Reexported types
43pub use xvc_ecs::error::Error as XvcEcsError;
44pub use xvc_ecs::error::Result as XvcEcsResult;
45pub use xvc_ecs::{
46    persist, Event, EventLog, HStore, R11Store, R1NStore, RMNStore, SharedHStore, SharedXStore,
47    Storable, VStore, XvcEntity, XvcStore,
48};
49
50pub use xvc_logging::{
51    debug, error, info, output, panic, setup_logging, trace, uwo, uwr, warn, watch, XvcOutputLine,
52    XvcOutputSender,
53};
54
55pub use xvc_walker as walker;
56pub use xvc_walker::Error as XvcWalkerError;
57pub use xvc_walker::Result as XvcWalkerResult;
58
59pub use xvc_walker::{
60    content_to_patterns, make_polling_watcher, path_metadata_map_from_file_targets, walk_parallel,
61    walk_serial, AbsolutePath, Glob, IgnoreRules, MatchResult, PathEvent, PathSync, WalkOptions,
62};
63
64pub use xvc_config::error::Error as XvcConfigError;
65pub use xvc_config::error::Result as XvcConfigResult;
66pub use xvc_config::{
67    conf, FromConfigKey, UpdateFromXvcConfig, XvcConfig, XvcConfigOptionSource, XvcConfigParams,
68    XvcVerbosity,
69};
70
71pub use util::git;
72
73pub use util::file::{all_paths_and_metadata, dir_includes, glob_includes, glob_paths};
74pub use util::git::{
75    build_gitignore, exec_git, get_absolute_git_command, get_git_tracked_files, git_auto_commit,
76    git_auto_stage, git_checkout_ref, git_ignored, handle_git_automation, inside_git,
77    stash_user_staged_files, unstash_user_staged_files,
78};
79
80pub use util::pmp::XvcPathMetadataProvider;
81pub use util::XvcPathMetadataMap;
82
83/// Channel size for [crossbeam_channel::bounded] used across the library.
84/// TODO: This can be configurable for smaller/larger RAM sizes.
85pub const CHANNEL_BOUND: usize = 1000000;
86
87/// The standard metadata directory
88///
89/// For an Xvc project under `dir`, all relevant metadata is kept under `dir/.xvc`
90pub const XVC_DIR: &str = ".xvc";
91
92/// The standard ignore filename
93///
94/// Xvc considers patterns in this filename to be ignored.
95/// Patterns are identical in structure to Gitignore
96pub const XVCIGNORE_FILENAME: &str = ".xvcignore";
97
98/// Initial .xvgignore content when a project is initialized
99///
100/// This is written to [XVCIGNORE_FILENAME] in the root of repository once it's initialized.
101pub const XVCIGNORE_INITIAL_CONTENT: &str = "
102# Add patterns of files xvc should ignore, which could improve
103# the performance.
104# It's in the same format as .gitignore files.
105
106.DS_Store
107";
108
109/// The Git directory for a project.
110///
111/// This is not expected to change for some time.
112pub const GIT_DIR: &str = ".git";
113
114/// The initial content for `.xvc/.gitignore` to hide files in .xvc/
115///
116/// We ignore all, and just track the store, entity counter and the configuration
117pub const GITIGNORE_INITIAL_CONTENT: &str = "
118## Following are required for Xvc to function correctly.
119.xvc/*
120!.xvc/store/
121!.xvc/ec/
122!.xvc/config.toml
123";
124
125/// Creates a new project configuration by writing all default values.
126/// This is used when initializing a new project.
127/// The repository GUID is created here.
128///
129/// # Arguments
130///
131/// - `use_git`: sets `core.use_git` option.
132pub fn default_project_config(use_git: bool) -> String {
133    let uuid = uuid::Uuid::new_v4();
134    let guid = hex::encode(seahash::hash(uuid.as_bytes()).to_le_bytes());
135    format!(
136        r##"
137[core]
138# The repository id. Please do not delete or change it.
139# This is used to identify the repository and generate paths in storages.
140# In the future it may be used to in other ways.
141guid = "{guid}"
142# Default verbosity level.
143# One of "error", "warn", "info"
144verbosity = "error"
145
146[git]
147# Automate git operations.
148# Turning this off leads Xvc to behave as if it's not in a Git repository.
149# Not recommended unless you're really not using Git
150use_git = {use_git}
151# Command to run Git process.
152# You can set this to an absolute path to specify an executable
153# If set to a non-absolute path, the executable will be searched in $PATH.
154command = "git"
155
156# Commit changes in .xvc/ directory after commands.
157# You can set this to false if you want to commit manually.
158auto_commit = true
159
160# Stage changes in .xvc/ directory without committing.
161# auto_commit implies auto_stage.
162# If you want to commit manually but don't want to stage after individual Xvc commands, you can set this to true.
163auto_stage = false
164
165[cache]
166# The hash algorithm used for the cache.
167# It may take blake3, blake2, sha2 or sha3 as values.
168# All algorithms are selected to produce 256-bit hashes, so sha2 means SHA2-256, blake2 means BLAKE2s, etc.
169# The cache path is produced by prepending algorithm name to the cache.
170# Blake3 files are in .xvc/b3/, while sha2 files are in .xvc/s2/ etc.
171algorithm = "blake3"
172
173[file]
174
175[file.track]
176
177# Don't move file content to cache after xvc file track
178no_commit = false
179# Force to track files even if they are already tracked.
180force = false
181
182# Xvc calculates file content digest differently for text and binary files.
183# This option controls whether to treat files as text or binary.
184# It may take auto, text or binary as values.
185# Auto check each file individually and treat it as text if it's text.
186text_or_binary = "auto"
187
188# Don't use parallelism in track operations.
189# Note that some of the operations are implemented in parallel by default, and this option affects some heavier operations.
190no_parallel = false
191
192# Track files that are tracked by Git. 
193include_git_files = {include_git_files}
194
195[file.list]
196
197# Format for `xvc file list` rows. You can reorder or remove columns.
198# The following are the keys for each row:
199# - {{acd64}}:  actual content digest. All 64 digits from the workspace file's content.
200# - {{acd8}}:  actual content digest. First 8 digits the file content digest.
201# - {{aft}}:  actual file type. Whether the entry is a file (F), directory (D),
202#   symlink (S), hardlink (H) or reflink (R).
203# - {{asz}}:  actual size. The size of the workspace file in bytes. It uses MB,
204#   GB and TB to represent sizes larger than 1MB.
205# - {{ats}}:  actual timestamp. The timestamp of the workspace file.
206# - {{cst}}:  cache status. One of "=", ">", "<", "X", or "?" to show
207#   whether the file timestamp is the same as the cached timestamp, newer,
208#   older, not cached or not tracked.
209# - {{name}}: The name of the file or directory.
210# - {{rcd64}}:  recorded content digest. All 64 digits.
211# - {{rcd8}}:  recorded content digest. First 8 digits.
212# - {{rrm}}:  recorded recheck method. Whether the entry is linked to the workspace
213#   as a copy (C), symlink (S), hardlink (H) or reflink (R).
214# - {{rsz}}:  recorded size. The size of the cached content in bytes. It uses
215#   MB, GB and TB to represent sizes larged than 1MB.
216# - {{rts}}:  recorded timestamp. The timestamp of the cached content.
217#
218# There are no escape sequences in the format string.
219# If you want to add a tab, type it to the string.
220# If you want to add a literal double curly brace, open an issue.
221format = "{{{{aft}}}}{{{{rrm}}}} {{{{asz}}}} {{{{ats}}}} {{{{rcd8}}}} {{{{acd8}}}} {{{{name}}}}"
222
223# Default sort order for `xvc file list`.
224# Valid values are
225# none, name-asc, name-desc, size-asc, size-desc, ts-asc, ts-desc.
226sort = "name-desc"
227
228# Show dot files like .gitignore
229show_dot_files = false
230
231# Do not show a summary for as the final row for `xvc file list`.
232no_summary = false
233
234# List files recursively always.
235recursive = false
236
237# List files tracked by Git. 
238include_git_files = {include_git_files}
239
240[file.carry-in]
241# Carry-in the files to cache always, even if they are already present.
242force = false
243
244# Don't use parallel move/copy in carry-in
245no_parallel = false
246
247[file.recheck]
248# The recheck method for Xvc. It may take copy, hardlink, symlink, reflink as values.
249# The default is copy to make sure the options is portable.
250# Copy duplicates the file content, while hardlink, symlink and reflink only create a new path to the file.
251# Note that hardlink and symlink are read-only as they link the files in cache.
252method = "copy"
253
254[pipeline]
255# Name of the current pipeline to run
256current_pipeline = "default"
257# Name of the default pipeline
258default = "default"
259# Name of the default params file name
260default_params_file = "params.yaml"
261# Number of command processes to run concurrently
262process_pool_size = 4
263 
264[check-ignore]
265# Show details by default
266details = false
267
268"##,
269        guid = guid,
270        use_git = use_git,
271        include_git_files = !use_git
272    )
273}