Skip to main content

gitoxide_core/repository/
mod.rs

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