@@ -2,7 +2,6 @@ use crate::{Change, Index};
2
2
use git_repository as git;
3
3
use git_repository:: prelude:: ObjectIdExt ;
4
4
use git_repository:: refs:: transaction:: PreviousValue ;
5
- use std:: convert:: TryFrom ;
6
5
use std:: sync:: atomic:: AtomicBool ;
7
6
8
7
mod delegate;
@@ -12,8 +11,6 @@ use delegate::Delegate;
12
11
#[ derive( Debug , thiserror:: Error ) ]
13
12
#[ allow( missing_docs) ]
14
13
pub enum Error {
15
- #[ error( "Failed to fetch crates.io index repository" ) ]
16
- FetchGit2 ( #[ from] git2:: Error ) ,
17
14
#[ error( "Couldn't update marker reference" ) ]
18
15
ReferenceEdit ( #[ from] git:: reference:: edit:: Error ) ,
19
16
#[ error( "Failed to parse rev-spec to determine which revisions to diff" ) ]
@@ -53,62 +50,7 @@ pub enum Error {
53
50
impl Index {
54
51
/// As `peek_changes_with_options`, but without the options.
55
52
pub fn peek_changes ( & self ) -> Result < ( Vec < Change > , git:: hash:: ObjectId ) , Error > {
56
- self . peek_changes_with_options ( None )
57
- }
58
-
59
- /// Return all `Change`s that are observed between the last time `fetch_changes(…)` was called
60
- /// and the latest state of the `crates.io` index repository, which is obtained by fetching
61
- /// the remote called `origin`.
62
- /// The `last_seen_reference()` will not be created or updated.
63
- /// The second field in the returned tuple is the commit object to which the changes were provided.
64
- /// If one would set the `last_seen_reference()` to that object, the effect is exactly the same
65
- /// as if `fetch_changes(…)` had been called.
66
- ///
67
- /// # Resource Usage
68
- ///
69
- /// As this method fetches the git repository, loose objects or small packs may be created. Over time,
70
- /// these will accumulate and either slow down subsequent operations, or cause them to fail due to exhaustion
71
- /// of the maximum number of open file handles as configured with `ulimit`.
72
- ///
73
- /// Thus it is advised for the caller to run `git gc` occasionally based on their own requirements and usage patterns.
74
- pub fn peek_changes_with_options (
75
- & self ,
76
- options : Option < & mut git2:: FetchOptions < ' _ > > ,
77
- ) -> Result < ( Vec < Change > , git:: hash:: ObjectId ) , Error > {
78
- let repo = & self . repo ;
79
- let from = repo
80
- . find_reference ( self . seen_ref_name )
81
- . ok ( )
82
- . and_then ( |r| r. try_id ( ) . map ( |id| id. detach ( ) ) )
83
- . unwrap_or_else ( || git:: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ) ;
84
- let remote_name = self
85
- . remote_name
86
- . as_deref ( )
87
- . expect ( "always set for this old portion of the code" ) ;
88
- let to = {
89
- let repo = git2:: Repository :: open ( repo. git_dir ( ) ) ?;
90
- repo. find_remote ( remote_name) . and_then ( |mut r| {
91
- r. fetch (
92
- & [ format ! (
93
- "+refs/heads/{branch}:refs/remotes/{remote}/{branch}" ,
94
- remote = remote_name,
95
- branch = self . branch_name,
96
- ) ] ,
97
- options,
98
- None ,
99
- )
100
- } ) ?;
101
- git:: hash:: ObjectId :: try_from (
102
- repo. refname_to_id ( & format ! (
103
- "refs/remotes/{}/{}" ,
104
- remote_name, self . branch_name
105
- ) ) ?
106
- . as_bytes ( ) ,
107
- )
108
- . expect ( "valid oid" )
109
- } ;
110
-
111
- Ok ( ( self . changes_between_commits ( from, to) ?, to) )
53
+ self . peek_changes_with_options ( git:: progress:: Discard , & AtomicBool :: default ( ) )
112
54
}
113
55
114
56
/// Return all `Change`s that are observed between the last time `peek_changes*(…)` was called
@@ -128,7 +70,7 @@ impl Index {
128
70
///
129
71
/// Thus it is advised for the caller to run `git gc` occasionally based on their own requirements and usage patterns.
130
72
// TODO: update this once it's clear how auto-gc works in `gitoxide`.
131
- pub fn peek_changes_with_options2 (
73
+ pub fn peek_changes_with_options (
132
74
& self ,
133
75
progress : impl git:: Progress ,
134
76
should_interrupt : & AtomicBool ,
@@ -243,14 +185,9 @@ impl Index {
243
185
244
186
/// Find changes while changing the underlying repository in one way or another.
245
187
impl Index {
246
- /// As `fetch_changes_with_options`, but without the options.
247
- pub fn fetch_changes2 ( & self ) -> Result < Vec < Change > , Error > {
248
- self . fetch_changes_with_options2 ( git:: progress:: Discard , & AtomicBool :: default ( ) )
249
- }
250
-
251
188
/// As `fetch_changes_with_options`, but without the options.
252
189
pub fn fetch_changes ( & self ) -> Result < Vec < Change > , Error > {
253
- self . fetch_changes_with_options ( None )
190
+ self . fetch_changes_with_options ( git :: progress :: Discard , & AtomicBool :: default ( ) )
254
191
}
255
192
256
193
/// Return all `Change`s that are observed between the last time this method was called
@@ -267,33 +204,11 @@ impl Index {
267
204
///
268
205
/// Thus it is advised for the caller to run `git gc` occasionally based on their own requirements and usage patterns.
269
206
pub fn fetch_changes_with_options (
270
- & self ,
271
- options : Option < & mut git2:: FetchOptions < ' _ > > ,
272
- ) -> Result < Vec < Change > , Error > {
273
- let ( changes, to) = self . peek_changes_with_options ( options) ?;
274
- self . set_last_seen_reference ( to) ?;
275
- Ok ( changes)
276
- }
277
-
278
- /// Return all `Change`s that are observed between the last time this method was called
279
- /// and the latest state of the `crates.io` index repository, which is obtained by fetching
280
- /// the remote called `origin`.
281
- /// The `last_seen_reference()` will be created or adjusted to point to the latest fetched
282
- /// state, which causes this method to have a different result each time it is called.
283
- ///
284
- /// # Resource Usage
285
- ///
286
- /// As this method fetches the git repository, loose objects or small packs may be created. Over time,
287
- /// these will accumulate and either slow down subsequent operations, or cause them to fail due to exhaustion
288
- /// of the maximum number of open file handles as configured with `ulimit`.
289
- ///
290
- /// Thus it is advised for the caller to run `git gc` occasionally based on their own requirements and usage patterns.
291
- pub fn fetch_changes_with_options2 (
292
207
& self ,
293
208
progress : impl git:: Progress ,
294
209
should_interrupt : & AtomicBool ,
295
210
) -> Result < Vec < Change > , Error > {
296
- let ( changes, to) = self . peek_changes_with_options2 ( progress, should_interrupt) ?;
211
+ let ( changes, to) = self . peek_changes_with_options ( progress, should_interrupt) ?;
297
212
self . set_last_seen_reference ( to) ?;
298
213
Ok ( changes)
299
214
}
0 commit comments