1
1
use crate :: info:: utils:: info_field:: InfoField ;
2
2
use anyhow:: Result ;
3
- use git2:: { Status , StatusOptions , StatusShow } ;
4
3
use gix:: Repository ;
5
4
use serde:: Serialize ;
6
5
@@ -12,36 +11,31 @@ pub struct PendingInfo {
12
11
13
12
impl PendingInfo {
14
13
pub fn new ( repo : & Repository ) -> Result < Self > {
15
- let git_dir = repo. git_dir ( ) . to_owned ( ) ;
16
- let repo = git2:: Repository :: open ( git_dir) ?;
17
- let pending_changes = get_pending_changes ( & repo) ?;
14
+ let pending_changes = get_pending_changes ( repo) ?;
18
15
Ok ( Self { pending_changes } )
19
16
}
20
17
}
21
18
22
- fn get_pending_changes ( repo : & git2:: Repository ) -> Result < String > {
23
- let statuses = repo. statuses ( Some (
24
- StatusOptions :: default ( )
25
- . show ( StatusShow :: Workdir )
26
- . update_index ( true )
27
- . include_untracked ( true )
28
- . renames_head_to_index ( true )
29
- . recurse_untracked_dirs ( true ) ,
30
- ) ) ?;
19
+ fn get_pending_changes ( repo : & Repository ) -> Result < String > {
20
+ let statuses = repo
21
+ . status ( gix:: progress:: Discard ) ?
22
+ . dirwalk_options ( |options| options. emit_untracked ( gix:: dir:: walk:: EmissionMode :: Matching ) )
23
+ . into_index_worktree_iter ( Vec :: new ( ) ) ?;
31
24
32
- let ( added, deleted, modified) =
33
- statuses
34
- . iter ( )
35
- . fold ( ( 0 , 0 , 0 ) , |( added, deleted, modified) , e| {
36
- let s: Status = e. status ( ) ;
37
- if s. is_index_new ( ) || s. is_wt_new ( ) {
38
- ( added + 1 , deleted, modified)
39
- } else if s. is_index_deleted ( ) || s. is_wt_deleted ( ) {
40
- ( added, deleted + 1 , modified)
41
- } else {
42
- ( added, deleted, modified + 1 )
43
- }
44
- } ) ;
25
+ let ( added, deleted, modified) = statuses
26
+ . take_while ( Result :: is_ok)
27
+ . filter_map ( Result :: ok)
28
+ . filter_map ( |item| item. summary ( ) )
29
+ . fold ( ( 0 , 0 , 0 ) , |( added, deleted, modified) , status| {
30
+ use gix:: status:: index_worktree:: iter:: Summary ;
31
+ match status {
32
+ Summary :: Removed => ( added, deleted + 1 , modified) ,
33
+ Summary :: Added => ( added + 1 , deleted, modified) ,
34
+ Summary :: Modified | Summary :: TypeChange => ( added, deleted, modified + 1 ) ,
35
+ Summary :: Renamed | Summary :: Copied => ( added + 1 , deleted + 1 , modified) ,
36
+ Summary :: IntentToAdd | Summary :: Conflict => ( added, deleted, modified) ,
37
+ }
38
+ } ) ;
45
39
46
40
let mut result = String :: new ( ) ;
47
41
if modified > 0 {
0 commit comments