Skip to content

Commit a942922

Browse files
committed
Use gitoxide for obtaining status information
1 parent eb8782e commit a942922

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/info/pending.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::info::utils::info_field::InfoField;
22
use anyhow::Result;
3-
use git2::{Status, StatusOptions, StatusShow};
43
use gix::Repository;
54
use serde::Serialize;
65

@@ -12,36 +11,31 @@ pub struct PendingInfo {
1211

1312
impl PendingInfo {
1413
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)?;
1815
Ok(Self { pending_changes })
1916
}
2017
}
2118

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())?;
3124

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+
});
4539

4640
let mut result = String::new();
4741
if modified > 0 {

0 commit comments

Comments
 (0)