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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use git_odb::pack::Find;
use git_ref::file::ReferenceExt;
use crate::{Id, Reference};
pub mod iter;
pub mod remote;
mod errors;
pub use errors::{edit, find, head_commit, head_id, peel};
use crate::ext::ObjectIdExt;
pub mod log;
pub use git_ref::{Category, Kind};
impl<'repo> Reference<'repo> {
pub fn try_id(&self) -> Option<Id<'repo>> {
match self.inner.target {
git_ref::Target::Symbolic(_) => None,
git_ref::Target::Peeled(oid) => oid.to_owned().attach(self.repo).into(),
}
}
pub fn id(&self) -> Id<'repo> {
self.try_id()
.expect("BUG: tries to obtain object id from symbolic target")
}
pub fn target(&self) -> git_ref::TargetRef<'_> {
self.inner.target.to_ref()
}
pub fn name(&self) -> &git_ref::FullNameRef {
self.inner.name.as_ref()
}
pub fn detach(self) -> git_ref::Reference {
self.inner
}
}
impl<'repo> std::fmt::Debug for Reference<'repo> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.inner, f)
}
}
impl<'repo> Reference<'repo> {
pub(crate) fn from_ref(reference: git_ref::Reference, repo: &'repo crate::Repository) -> Self {
Reference { inner: reference, repo }
}
}
impl<'repo> Reference<'repo> {
pub fn peel_to_id_in_place(&mut self) -> Result<Id<'repo>, peel::Error> {
let repo = &self.repo;
let oid = self.inner.peel_to_id_in_place(&repo.refs, |oid, buf| {
repo.objects
.try_find(oid, buf)
.map(|po| po.map(|(o, _l)| (o.kind, o.data)))
})?;
Ok(Id::from_id(oid, repo))
}
pub fn into_fully_peeled_id(mut self) -> Result<Id<'repo>, peel::Error> {
self.peel_to_id_in_place()
}
}
mod edits;
pub use edits::{delete, set_target_id};