Skip to content

Commit 8dd76e3

Browse files
committed
feat: Add MatchGroup::from_push_specs() for symmetry with *::from_fetch_specs()
1 parent 8ac2dcc commit 8dd76e3

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

gix-refspec/src/match_group/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ impl<'a> MatchGroup<'a> {
1616
specs: specs.into_iter().filter(|s| s.op == Operation::Fetch).collect(),
1717
}
1818
}
19+
20+
/// Take all the push ref specs from `specs` get a match group ready.
21+
pub fn from_push_specs(specs: impl IntoIterator<Item = RefSpecRef<'a>>) -> Self {
22+
MatchGroup {
23+
specs: specs.into_iter().filter(|s| s.op == Operation::Push).collect(),
24+
}
25+
}
1926
}
2027

2128
/// Matching
2229
impl<'a> MatchGroup<'a> {
23-
/// Match all `items` against all fetch specs present in this group, returning deduplicated mappings from source to destination.
24-
/// Note that this method only makes sense if the specs are indeed fetch specs and may panic otherwise.
30+
/// Match all `items` against all *fetch* specs present in this group, returning deduplicated mappings from source to destination.
31+
/// *Note that this method is correct only for specs*, even though it also *works for push-specs*.
2532
///
2633
/// Note that negative matches are not part of the return value, so they are not observable but will be used to remove mappings.
34+
// TODO: figure out how to deal with push-specs, probably when push is being implemented.
2735
pub fn match_remotes<'item>(self, mut items: impl Iterator<Item = Item<'item>> + Clone) -> Outcome<'a, 'item> {
2836
let mut out = Vec::new();
2937
let mut seen = BTreeSet::default();
@@ -54,11 +62,11 @@ impl<'a> MatchGroup<'a> {
5462

5563
let mut has_negation = false;
5664
for (spec_index, (spec, matcher)) in self.specs.iter().zip(matchers.iter_mut()).enumerate() {
65+
if spec.mode == Mode::Negative {
66+
has_negation = true;
67+
continue;
68+
}
5769
for (item_index, item) in items.clone().enumerate() {
58-
if spec.mode == Mode::Negative {
59-
has_negation = true;
60-
continue;
61-
}
6270
if let Some(matcher) = matcher {
6371
let (matched, rhs) = matcher.matches_lhs(item);
6472
if matched {
@@ -73,8 +81,8 @@ impl<'a> MatchGroup<'a> {
7381
}
7482
}
7583

76-
if let Some(id) = has_negation.then(|| items.next().map(|i| i.target)).flatten() {
77-
let null_id = gix_hash::ObjectId::null(id.kind());
84+
if let Some(hash_kind) = has_negation.then(|| items.next().map(|i| i.target.kind())).flatten() {
85+
let null_id = hash_kind.null();
7886
for matcher in matchers
7987
.into_iter()
8088
.zip(self.specs.iter())

gix-refspec/src/match_group/util.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ impl<'a> Matcher<'a> {
2020
match (self.lhs, self.rhs) {
2121
(Some(lhs), None) => (lhs.matches(item).is_match(), None),
2222
(Some(lhs), Some(rhs)) => lhs.matches(item).into_match_outcome(rhs, item),
23-
(None, _) => {
24-
unreachable!("For all we know, the lefthand side is never empty. Push specs might change that.")
25-
}
23+
(None, _) => (false, None),
2624
}
2725
}
2826
}

0 commit comments

Comments
 (0)