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