mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-27 07:10:58 +08:00
git-ref-format: add Refspec type
Add a Refspec type that represents a `[+]<src>:<dst>` refspec[[0]]. [0]: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user