Files
radicle-git/git-storage/src/glob.rs
T
Fintan Halpenny e6f36318cd git-storage: port storage from librad
This provides a port of the librad::git::storage[0] API, with a focus
on being more generic and decomposing writing and reading
operations. It also takes heavy inspiration from
link_replication::io::refdb[1] for its implementation of the
transactional writes.

[0]: https://github.com/radicle-dev/radicle-link/blob/master/librad/src/git/storage.rs
[1]: https://github.com/radicle-dev/radicle-link/blob/master/link-replication/src/io/refdb.rs

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-09-27 12:32:20 +01:00

47 lines
1.2 KiB
Rust

// Copyright © 2019-2020 The Radicle Foundation <hello@radicle.foundation>
//
// This file is part of radicle-link, distributed under the GPLv3 with Radicle
// Linking Exception. For full terms see the included LICENSE file.
use std::path::Path;
use git_ext as ext;
use git_ref_format::refspec::PatternString;
pub trait Pattern {
fn matches<P: AsRef<Path>>(&self, path: P) -> bool;
}
impl Pattern for globset::GlobMatcher {
fn matches<P: AsRef<Path>>(&self, path: P) -> bool {
self.is_match(path)
}
}
impl Pattern for globset::GlobSet {
fn matches<P: AsRef<Path>>(&self, path: P) -> bool {
self.is_match(path)
}
}
#[derive(Clone, Debug)]
pub struct RefspecMatcher(globset::GlobMatcher);
impl From<ext::RefspecPattern> for RefspecMatcher {
fn from(pat: ext::RefspecPattern) -> Self {
Self(globset::Glob::new(pat.as_str()).unwrap().compile_matcher())
}
}
impl From<PatternString> for RefspecMatcher {
fn from(pat: PatternString) -> Self {
Self(globset::Glob::new(pat.as_str()).unwrap().compile_matcher())
}
}
impl Pattern for RefspecMatcher {
fn matches<P: AsRef<Path>>(&self, path: P) -> bool {
self.0.is_match(path)
}
}