Radish alpha
r
rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt
Git libraries for Radicle
Radicle
Git
git-ref-format: add Refspec type
Fintan Halpenny committed 2 years ago
commit 64fef2f0ad67b14353ee75e1d0099b48da5aac52
parent 24e27f6
1 file changed +28 -1
modified radicle-git-ext/git-ref-format/core/src/refspec.rs
@@ -6,7 +6,7 @@
use std::{
    borrow::{Borrow, Cow},
    convert::TryFrom,
-
    fmt::{self, Display},
+
    fmt::{self, Display, Write as _},
    iter::FromIterator,
    ops::Deref,
};
@@ -558,3 +558,30 @@ impl Display for NamespacedPattern<'_> {
        self.0.fmt(f)
    }
}
+

+
/// A Git [refspec].
+
///
+
/// **Note** that this is a simplified version of a [refspec] where
+
/// the `src` and `dst` are required and there is no way to construct
+
/// a negative refspec, e.g. `^refs/heads/no-thanks`.
+
///
+
/// [refspec]: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
+
#[derive(Clone, Debug, PartialEq, Eq)]
+
pub struct Refspec<T, U> {
+
    pub src: T,
+
    pub dst: U,
+
    pub force: bool,
+
}
+

+
impl<T, U> fmt::Display for Refspec<T, U>
+
where
+
    T: fmt::Display,
+
    U: fmt::Display,
+
{
+
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+
        if self.force {
+
            f.write_char('+')?;
+
        }
+
        write!(f, "{}:{}", self.src, self.dst)
+
    }
+
}