@@ -18,17 +18,23 @@ pub struct Iter<'r> {
18
18
repo : & ' r crate :: Repository ,
19
19
}
20
20
21
+ impl < ' r > Iter < ' r > {
22
+ fn new ( repo : & ' r crate :: Repository , platform : git_ref:: file:: iter:: LooseThenPacked < ' r , ' r > ) -> Self {
23
+ Iter {
24
+ inner : platform,
25
+ peel : false ,
26
+ repo,
27
+ }
28
+ }
29
+ }
30
+
21
31
impl < ' r > Platform < ' r > {
22
32
/// Return an iterator over all references in the repository.
23
33
///
24
34
/// Even broken or otherwise unparsible or inaccessible references are returned and have to be handled by the caller on a
25
35
/// case by case basis.
26
36
pub fn all ( & self ) -> Result < Iter < ' _ > , init:: Error > {
27
- Ok ( Iter {
28
- inner : self . platform . all ( ) ?,
29
- peel : false ,
30
- repo : self . repo ,
31
- } )
37
+ Ok ( Iter :: new ( self . repo , self . platform . all ( ) ?) )
32
38
}
33
39
34
40
/// Return an iterator over all references that match the given `prefix`.
@@ -37,47 +43,31 @@ impl<'r> Platform<'r> {
37
43
// TODO: Create a custom `Path` type that enforces the requirements of git naturally, this type is surprising possibly on windows
38
44
// and when not using a trailing '/' to signal directories.
39
45
pub fn prefixed ( & self , prefix : impl AsRef < Path > ) -> Result < Iter < ' _ > , init:: Error > {
40
- Ok ( Iter {
41
- inner : self . platform . prefixed ( prefix) ?,
42
- peel : false ,
43
- repo : self . repo ,
44
- } )
46
+ Ok ( Iter :: new ( self . repo , self . platform . prefixed ( prefix) ?) )
45
47
}
46
48
47
49
// TODO: tests
48
50
/// Return an iterator over all references that are tags.
49
51
///
50
52
/// They are all prefixed with `refs/tags`.
51
53
pub fn tags ( & self ) -> Result < Iter < ' _ > , init:: Error > {
52
- Ok ( Iter {
53
- inner : self . platform . prefixed ( "refs/tags/" ) ?,
54
- peel : false ,
55
- repo : self . repo ,
56
- } )
54
+ Ok ( Iter :: new ( self . repo , self . platform . prefixed ( "refs/tags/" ) ?) )
57
55
}
58
56
59
57
// TODO: tests
60
58
/// Return an iterator over all local branches.
61
59
///
62
60
/// They are all prefixed with `refs/heads`.
63
61
pub fn local_branches ( & self ) -> Result < Iter < ' _ > , init:: Error > {
64
- Ok ( Iter {
65
- inner : self . platform . prefixed ( "refs/heads/" ) ?,
66
- peel : false ,
67
- repo : self . repo ,
68
- } )
62
+ Ok ( Iter :: new ( self . repo , self . platform . prefixed ( "refs/heads/" ) ?) )
69
63
}
70
64
71
65
// TODO: tests
72
66
/// Return an iterator over all remote branches.
73
67
///
74
68
/// They are all prefixed with `refs/remotes`.
75
69
pub fn remote_branches ( & self ) -> Result < Iter < ' _ > , init:: Error > {
76
- Ok ( Iter {
77
- inner : self . platform . prefixed ( "refs/remotes/" ) ?,
78
- peel : false ,
79
- repo : self . repo ,
80
- } )
70
+ Ok ( Iter :: new ( self . repo , self . platform . prefixed ( "refs/remotes/" ) ?) )
81
71
}
82
72
}
83
73
0 commit comments