Skip to content

Commit 5c823dc

Browse files
committed
sketch data structure that should do the trick (#450)
That way the most complex thing will be the validation along with the matching.
1 parent 362bd46 commit 5c823dc

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

git-refspec/src/lib.rs

+55-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
11
//! Parse [ref specs]() and represent them.
22
#![forbid(unsafe_code, rust_2018_idioms)]
3-
#![deny(missing_docs)]
3+
#![allow(missing_docs)]
4+
5+
use bstr::{BStr, BString};
6+
7+
/// The way to interpret a refspec.
8+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
9+
pub enum Mode {
10+
/// Even though according to normal rules a non-fastforward would be denied, override this and reset a ref forcefully in the destination.
11+
Force,
12+
/// Instead of considering matching refs included, we consider them excluded. This applies only to the source side of a refspec.
13+
Negative,
14+
}
15+
16+
/// What operation to perform with the refspec.
17+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
18+
pub enum Operation {
19+
/// The `src` side is local and the `dst` side is remote.
20+
Push,
21+
/// The `src` side is remote and the `dst` side is local.
22+
Fetch,
23+
}
24+
25+
/// A refspec with references to the memory it was parsed from.
26+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
27+
pub struct RefSpecRef<'a> {
28+
mode: Mode,
29+
op: Operation,
30+
src: Option<&'a BStr>,
31+
dest: Option<&'a BStr>,
32+
}
33+
34+
/// An owned refspec.
35+
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
36+
pub struct RefSpec {
37+
mode: Mode,
38+
op: Operation,
39+
src: Option<BString>,
40+
dest: Option<BString>,
41+
}
42+
43+
mod spec {
44+
use crate::{RefSpec, RefSpecRef};
45+
46+
impl RefSpecRef<'_> {
47+
/// Convert this ref into a standalone, owned copy.
48+
pub fn to_owned(&self) -> RefSpec {
49+
RefSpec {
50+
mode: self.mode,
51+
op: self.op,
52+
src: self.src.map(ToOwned::to_owned),
53+
dest: self.dest.map(ToOwned::to_owned),
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)