@@ -13,15 +13,15 @@ pub struct Platform<'r> {
13
13
}
14
14
15
15
/// An iterator over references, with or without filter.
16
- pub struct Iter < ' r > {
17
- inner : gix_ref:: file:: iter:: LooseThenPacked < ' r , ' r > ,
16
+ pub struct Iter < ' p , ' r > {
17
+ inner : gix_ref:: file:: iter:: LooseThenPacked < ' p , ' r > ,
18
18
peel_with_packed : Option < gix_ref:: file:: packed:: SharedBufferSnapshot > ,
19
19
peel : bool ,
20
20
repo : & ' r crate :: Repository ,
21
21
}
22
22
23
- impl < ' r > Iter < ' r > {
24
- fn new ( repo : & ' r crate :: Repository , platform : gix_ref:: file:: iter:: LooseThenPacked < ' r , ' r > ) -> Self {
23
+ impl < ' p , ' r > Iter < ' p , ' r > {
24
+ fn new ( repo : & ' r crate :: Repository , platform : gix_ref:: file:: iter:: LooseThenPacked < ' p , ' r > ) -> Self {
25
25
Iter {
26
26
inner : platform,
27
27
peel_with_packed : None ,
@@ -31,39 +31,55 @@ impl<'r> Iter<'r> {
31
31
}
32
32
}
33
33
34
- impl Platform < ' _ > {
34
+ impl < ' repo > Platform < ' repo > {
35
35
/// Return an iterator over all references in the repository, excluding
36
36
/// pseudo references.
37
37
///
38
38
/// Even broken or otherwise unparsable or inaccessible references are returned and have to be handled by the caller on a
39
39
/// case by case basis.
40
- pub fn all ( & self ) -> Result < Iter < ' _ > , init:: Error > {
40
+ pub fn all < ' p > ( & ' p self ) -> Result < Iter < ' p , ' repo > , init:: Error > {
41
41
Ok ( Iter :: new ( self . repo , self . platform . all ( ) ?) )
42
42
}
43
43
44
44
/// Return an iterator over all references that match the given `prefix`.
45
45
///
46
46
/// These are of the form `refs/heads/` or `refs/remotes/origin`, and must not contain relative paths components like `.` or `..`.
47
- pub fn prefixed < ' a > (
48
- & self ,
47
+ pub fn prefixed < ' p , ' a > (
48
+ & ' p self ,
49
49
prefix : impl TryInto < & ' a RelativePath , Error = gix_path:: relative_path:: Error > ,
50
- ) -> Result < Iter < ' _ > , init:: Error > {
50
+ ) -> Result < Iter < ' p , ' repo > , init:: Error > {
51
51
Ok ( Iter :: new ( self . repo , self . platform . prefixed ( prefix. try_into ( ) ?) ?) )
52
52
}
53
53
54
54
// TODO: tests
55
55
/// Return an iterator over all references that are tags.
56
56
///
57
57
/// They are all prefixed with `refs/tags`.
58
- pub fn tags ( & self ) -> Result < Iter < ' _ > , init:: Error > {
58
+ ///
59
+ /// ```rust
60
+ /// # // Regression test for https://github.com/GitoxideLabs/gitoxide/issues/2103
61
+ /// # // This only ensures we can return a reference, not that the code below is correct
62
+ /// /// Get the latest tag that isn't a pre-release version
63
+ /// fn latest_stable_tag(repo: &gix::Repository) -> Result<gix::Reference<'_>, Box<dyn std::error::Error>> {
64
+ /// repo.references()?
65
+ /// .tags()?
66
+ /// .filter_map(|tag| tag.ok())
67
+ /// // Warning: lexically sorting version numbers is incorrect, use the semver crate if
68
+ /// // you want correct results
69
+ /// .max_by_key(|tag| tag.name().shorten().to_owned())
70
+ /// .ok_or(std::io::Error::other("latest tag not found"))
71
+ /// .map_err(Into::into)
72
+ /// }
73
+ /// ```
74
+ pub fn tags < ' p > ( & ' p self ) -> Result < Iter < ' p , ' repo > , init:: Error > {
59
75
Ok ( Iter :: new ( self . repo , self . platform . prefixed ( b"refs/tags/" . try_into ( ) ?) ?) )
60
76
}
61
77
62
78
// TODO: tests
63
79
/// Return an iterator over all local branches.
64
80
///
65
81
/// They are all prefixed with `refs/heads`.
66
- pub fn local_branches ( & self ) -> Result < Iter < ' _ > , init:: Error > {
82
+ pub fn local_branches < ' p > ( & ' p self ) -> Result < Iter < ' p , ' repo > , init:: Error > {
67
83
Ok ( Iter :: new (
68
84
self . repo ,
69
85
self . platform . prefixed ( b"refs/heads/" . try_into ( ) ?) ?,
@@ -72,23 +88,23 @@ impl Platform<'_> {
72
88
73
89
// TODO: tests
74
90
/// Return an iterator over all local pseudo references.
75
- pub fn pseudo ( & self ) -> Result < Iter < ' _ > , init:: Error > {
91
+ pub fn pseudo < ' p > ( & ' p self ) -> Result < Iter < ' p , ' repo > , init:: Error > {
76
92
Ok ( Iter :: new ( self . repo , self . platform . pseudo ( ) ?) )
77
93
}
78
94
79
95
// TODO: tests
80
96
/// Return an iterator over all remote branches.
81
97
///
82
98
/// They are all prefixed with `refs/remotes`.
83
- pub fn remote_branches ( & self ) -> Result < Iter < ' _ > , init:: Error > {
99
+ pub fn remote_branches < ' p > ( & ' p self ) -> Result < Iter < ' p , ' repo > , init:: Error > {
84
100
Ok ( Iter :: new (
85
101
self . repo ,
86
102
self . platform . prefixed ( b"refs/remotes/" . try_into ( ) ?) ?,
87
103
) )
88
104
}
89
105
}
90
106
91
- impl Iter < ' _ > {
107
+ impl Iter < ' _ , ' _ > {
92
108
/// Automatically peel references before yielding them during iteration.
93
109
///
94
110
/// This has the same effect as using `iter.map(|r| {r.peel_to_id_in_place(); r})`.
@@ -104,7 +120,7 @@ impl Iter<'_> {
104
120
}
105
121
}
106
122
107
- impl < ' r > Iterator for Iter < ' r > {
123
+ impl < ' r > Iterator for Iter < ' _ , ' r > {
108
124
type Item = Result < crate :: Reference < ' r > , Box < dyn std:: error:: Error + Send + Sync + ' static > > ;
109
125
110
126
fn next ( & mut self ) -> Option < Self :: Item > {
0 commit comments