diff --git a/git-refspec/src/lib.rs b/git-refspec/src/lib.rs index ff723740fa..af645881f1 100644 --- a/git-refspec/src/lib.rs +++ b/git-refspec/src/lib.rs @@ -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, + dest: Option, +} + +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), + } + } + } +}