Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sketch data structure that should do the trick (#450)
That way the most complex thing will be the validation along with the matching.
- Loading branch information
Showing
1 changed file
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
//! Parse [ref specs]() and represent them. | ||
#![forbid(unsafe_code, rust_2018_idioms)] | ||
#![deny(missing_docs)] | ||
#![allow(missing_docs)] | ||
|
||
use bstr::{BStr, BString}; | ||
|
||
/// The way to interpret a refspec. | ||
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] | ||
pub enum Mode { | ||
/// Even though according to normal rules a non-fastforward would be denied, override this and reset a ref forcefully in the destination. | ||
Force, | ||
/// Instead of considering matching refs included, we consider them excluded. This applies only to the source side of a refspec. | ||
Negative, | ||
} | ||
|
||
/// What operation to perform with the refspec. | ||
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] | ||
pub enum Operation { | ||
/// The `src` side is local and the `dst` side is remote. | ||
Push, | ||
/// The `src` side is remote and the `dst` side is local. | ||
Fetch, | ||
} | ||
|
||
/// A refspec with references to the memory it was parsed from. | ||
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] | ||
pub struct RefSpecRef<'a> { | ||
mode: Mode, | ||
op: Operation, | ||
src: Option<&'a BStr>, | ||
dest: Option<&'a BStr>, | ||
} | ||
|
||
/// An owned refspec. | ||
#[derive(PartialEq, Eq, Clone, Hash, Debug)] | ||
pub struct RefSpec { | ||
mode: Mode, | ||
op: Operation, | ||
src: Option<BString>, | ||
dest: Option<BString>, | ||
} | ||
|
||
mod spec { | ||
use crate::{RefSpec, RefSpecRef}; | ||
|
||
impl RefSpecRef<'_> { | ||
/// Convert this ref into a standalone, owned copy. | ||
pub fn to_owned(&self) -> RefSpec { | ||
RefSpec { | ||
mode: self.mode, | ||
op: self.op, | ||
src: self.src.map(ToOwned::to_owned), | ||
dest: self.dest.map(ToOwned::to_owned), | ||
} | ||
} | ||
} | ||
} |