-
-
Notifications
You must be signed in to change notification settings - Fork 260
/
mod.rs
46 lines (39 loc) · 1.56 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::bstr::BStr;
use crate::revision::Spec;
use crate::Repository;
use git_hash::ObjectId;
use git_revision::spec::parse;
use std::collections::HashSet;
mod types;
pub use types::{Error, ObjectKindHint, Options, RefsHint};
///
pub mod error;
impl<'repo> Spec<'repo> {
/// Parse `spec` and use information from `repo` to resolve it, using `opts` to learn how to deal with ambiguity.
///
/// Note that it's easier and to use [`repo.rev_parse()`][Repository::rev_parse()] instead.
pub fn from_bstr<'a>(spec: impl Into<&'a BStr>, repo: &'repo Repository, opts: Options) -> Result<Self, Error> {
let mut delegate = Delegate::new(repo, opts);
match git_revision::spec::parse(spec.into(), &mut delegate) {
Err(parse::Error::Delegate) => Err(delegate.into_err()),
Err(err) => Err(err.into()),
Ok(()) => delegate.into_rev_spec(),
}
}
}
struct Delegate<'repo> {
refs: [Option<git_ref::Reference>; 2],
objs: [Option<HashSet<ObjectId>>; 2],
/// The originally encountered ambiguous objects for potential later use in errors.
ambiguous_objects: [Option<HashSet<ObjectId>>; 2],
idx: usize,
kind: Option<git_revision::spec::Kind>,
opts: Options,
err: Vec<Error>,
/// The ambiguous prefix obtained during a call to `disambiguate_prefix()`.
prefix: [Option<git_hash::Prefix>; 2],
/// If true, we didn't try to do any other transformation which might have helped with disambiguation.
last_call_was_disambiguate_prefix: [bool; 2],
repo: &'repo Repository,
}
mod delegate;