asyncgit/
lib.rs

1/*!
2`AsyncGit` is a library that provides non-blocking access to Git
3operations, enabling `GitUI` to perform potentially slow Git operations
4in the background while keeping the user interface responsive.
5
6It also provides synchronous Git operations.
7
8It wraps libraries like git2 and gix.
9*/
10
11#![forbid(missing_docs)]
12#![deny(
13	mismatched_lifetime_syntaxes,
14	unused_imports,
15	unused_must_use,
16	dead_code,
17	unstable_name_collisions,
18	unused_assignments,
19	deprecated
20)]
21#![deny(clippy::all, clippy::perf, clippy::nursery, clippy::pedantic)]
22#![deny(
23	clippy::filetype_is_file,
24	clippy::cargo,
25	clippy::unwrap_used,
26	clippy::panic,
27	clippy::match_like_matches_macro,
28	clippy::needless_update
29	//TODO: get this in someday since expect still leads us to crashes sometimes
30	// clippy::expect_used
31)]
32#![allow(
33	clippy::module_name_repetitions,
34	clippy::must_use_candidate,
35	clippy::missing_errors_doc,
36	clippy::empty_docs,
37	clippy::unnecessary_debug_formatting
38)]
39//TODO:
40#![allow(
41	clippy::significant_drop_tightening,
42	clippy::missing_panics_doc,
43	clippy::multiple_crate_versions
44)]
45
46pub mod asyncjob;
47mod blame;
48mod branches;
49pub mod cached;
50mod commit_files;
51mod diff;
52mod error;
53mod fetch_job;
54mod filter_commits;
55mod progress;
56mod pull;
57mod push;
58mod push_tags;
59pub mod remote_progress;
60pub mod remote_tags;
61mod revlog;
62mod status;
63pub mod sync;
64mod tags;
65mod treefiles;
66
67pub use crate::{
68	blame::{AsyncBlame, BlameParams},
69	branches::AsyncBranchesJob,
70	commit_files::{AsyncCommitFiles, CommitFilesParams},
71	diff::{AsyncDiff, DiffParams, DiffType},
72	error::{Error, Result},
73	fetch_job::AsyncFetchJob,
74	filter_commits::{AsyncCommitFilterJob, CommitFilterResult},
75	progress::ProgressPercent,
76	pull::{AsyncPull, FetchRequest},
77	push::{AsyncPush, PushRequest},
78	push_tags::{AsyncPushTags, PushTagsRequest},
79	remote_progress::{RemoteProgress, RemoteProgressState},
80	revlog::{AsyncLog, FetchStatus},
81	status::{AsyncStatus, StatusParams},
82	sync::{
83		diff::{DiffLine, DiffLineType, FileDiff},
84		remotes::push::PushType,
85		status::{StatusItem, StatusItemType},
86	},
87	tags::AsyncTags,
88	treefiles::AsyncTreeFilesJob,
89};
90pub use git2::message_prettify;
91use std::{
92	collections::hash_map::DefaultHasher,
93	hash::{Hash, Hasher},
94};
95
96/// this type is used to communicate events back through the channel
97#[derive(Copy, Clone, Debug, PartialEq, Eq)]
98pub enum AsyncGitNotification {
99	/// this indicates that no new state was fetched but that a async process finished
100	FinishUnchanged,
101	///
102	Status,
103	///
104	Diff,
105	///
106	Log,
107	///
108	FileLog,
109	///
110	CommitFiles,
111	///
112	Tags,
113	///
114	Push,
115	///
116	PushTags,
117	///
118	Pull,
119	///
120	Blame,
121	///
122	RemoteTags,
123	///
124	Fetch,
125	///
126	Branches,
127	///
128	TreeFiles,
129	///
130	CommitFilter,
131}
132
133/// helper function to calculate the hash of an arbitrary type that implements the `Hash` trait
134pub fn hash<T: Hash + ?Sized>(v: &T) -> u64 {
135	let mut hasher = DefaultHasher::new();
136	v.hash(&mut hasher);
137	hasher.finish()
138}
139
140///
141#[cfg(feature = "trace-libgit")]
142pub fn register_tracing_logging() -> bool {
143	fn git_trace(level: git2::TraceLevel, msg: &[u8]) {
144		log::info!("[{:?}]: {}", level, String::from_utf8_lossy(msg));
145	}
146	git2::trace_set(git2::TraceLevel::Trace, git_trace).is_ok()
147}
148
149///
150#[cfg(not(feature = "trace-libgit"))]
151pub fn register_tracing_logging() -> bool {
152	true
153}