gitoxide_core/repository/
mod.rs1use std::fmt::Formatter;
2use std::path::PathBuf;
3
4use anyhow::{Context as AnyhowContext, Result};
5use gix::bstr::BString;
6
7#[cfg(feature = "archive")]
8pub mod archive;
9pub mod branch;
10pub mod cat;
11pub use cat::function::cat;
12pub mod blame;
13pub mod commit;
14pub mod config;
15mod credential;
16pub use credential::function as credential;
17pub mod attributes;
18#[cfg(feature = "clean")]
19pub mod clean;
20pub mod diff;
21pub mod dirty;
22#[cfg(feature = "clean")]
23pub use clean::function::clean;
24#[cfg(feature = "blocking-client")]
25pub mod clone;
26pub mod exclude;
27#[cfg(feature = "blocking-client")]
28pub mod fetch;
29#[cfg(feature = "blocking-client")]
30pub use clone::function::clone;
31#[cfg(feature = "blocking-client")]
32pub use fetch::function::fetch;
33
34pub mod commitgraph;
35mod fsck;
36pub use fsck::function as fsck;
37pub mod index;
38pub mod log;
39pub mod mailmap;
40mod merge_base;
41pub use merge_base::merge_base;
42pub mod merge;
43pub mod odb;
44pub mod remote;
45pub mod revision;
46pub mod status;
47pub mod submodule;
48pub mod tag;
49pub mod tree;
50pub mod verify;
51pub mod worktree;
52
53pub fn init(directory: Option<PathBuf>) -> Result<gix::discover::repository::Path> {
54 gix::create::into(
55 directory.unwrap_or_default(),
56 gix::create::Kind::WithWorktree,
57 gix::create::Options::default(),
58 )
59 .with_context(|| "Repository initialization failed")
60}
61
62pub enum PathsOrPatterns {
63 Paths(Box<dyn std::iter::Iterator<Item = BString>>),
64 Patterns(Vec<BString>),
65}
66
67struct HexId<'a>(gix::Id<'a>, bool);
68
69impl<'a> HexId<'a> {
70 pub fn new(id: gix::Id<'a>, long_hex: bool) -> Self {
71 HexId(id, long_hex)
72 }
73}
74
75impl std::fmt::Display for HexId<'_> {
76 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
77 let HexId(id, long_hex) = self;
78 if *long_hex {
79 id.fmt(f)
80 } else {
81 id.shorten_or_id().fmt(f)
82 }
83 }
84}