Skip to main content

gix_refspec/
lib.rs

1//! Parse git ref-specs and represent them.
2//!
3//! ## Examples
4//!
5//! ```
6//! use bstr::ByteSlice;
7//! use gix_refspec::parse::Operation;
8//!
9//! let spec = gix_refspec::parse(
10//!     "refs/heads/*:refs/remotes/origin/*".into(),
11//!     Operation::Fetch,
12//! )
13//! .unwrap();
14//!
15//! assert_eq!(spec.remote().unwrap(), "refs/heads/*");
16//! assert_eq!(spec.local().unwrap(), "refs/remotes/origin/*");
17//! assert_eq!(spec.prefix().unwrap(), "refs/heads/");
18//!
19//! let mut prefixes = Vec::new();
20//! spec.expand_prefixes(&mut prefixes);
21//! assert_eq!(prefixes.len(), 1);
22//! assert_eq!(prefixes[0].as_bstr(), "refs/heads/");
23//!
24//! assert_eq!(spec.to_bstring(), "refs/heads/*:refs/remotes/origin/*");
25//! ```
26#![deny(missing_docs, rust_2018_idioms)]
27#![forbid(unsafe_code)]
28
29///
30pub mod parse;
31pub use parse::function::parse;
32
33///
34pub mod instruction;
35
36/// A refspec with references to the memory it was parsed from.
37#[derive(Eq, Copy, Clone, Debug)]
38pub struct RefSpecRef<'a> {
39    mode: types::Mode,
40    op: parse::Operation,
41    src: Option<&'a bstr::BStr>,
42    dst: Option<&'a bstr::BStr>,
43}
44
45/// An owned refspec.
46#[derive(Eq, Clone, Debug)]
47pub struct RefSpec {
48    mode: types::Mode,
49    op: parse::Operation,
50    src: Option<bstr::BString>,
51    dst: Option<bstr::BString>,
52}
53
54mod spec;
55
56mod write;
57
58///
59pub mod match_group;
60pub use match_group::types::MatchGroup;
61
62mod types;
63pub use types::Instruction;