Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/collab/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ fn db_status_to_proto(
}),
diff_stat_added: entry.lines_added.map(|v| v as u32),
diff_stat_deleted: entry.lines_deleted.map(|v| v as u32),
staged_diff_stat_added: None,
staged_diff_stat_deleted: None,
unstaged_diff_stat_added: None,
unstaged_diff_stat_deleted: None,
})
}

Expand Down
46 changes: 34 additions & 12 deletions crates/fs/src/fake_git_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ impl GitRepository for FakeGitRepository {

fn diff_stat(
&self,
diff: git::repository::DiffStatType,
path_prefixes: &[RepoPath],
) -> BoxFuture<'static, Result<git::status::GitDiffStat>> {
fn count_lines(s: &str) -> u32 {
Expand Down Expand Up @@ -1203,22 +1204,43 @@ impl GitRepository for FakeGitRepository {

self.with_state_async(false, move |state| {
let mut entries = Vec::new();
let all_paths: HashSet<&RepoPath> = state
.head_contents
.keys()
.chain(
worktree_files
.keys()
.filter(|p| state.index_contents.contains_key(*p)),
)
.collect();
let (old_files, new_files) = match diff {
git::repository::DiffStatType::HeadToIndex => {
(&state.head_contents, &state.index_contents)
}
git::repository::DiffStatType::HeadToWorktree => {
(&state.head_contents, &worktree_files)
}
git::repository::DiffStatType::IndexToWorktree => {
(&state.index_contents, &worktree_files)
}
};
let all_paths: HashSet<&RepoPath> = match diff {
git::repository::DiffStatType::HeadToIndex => state
.head_contents
.keys()
.chain(state.index_contents.keys())
.collect(),
git::repository::DiffStatType::HeadToWorktree => state
.head_contents
.keys()
.chain(
worktree_files
.keys()
.filter(|path| state.index_contents.contains_key(*path)),
)
.collect(),
git::repository::DiffStatType::IndexToWorktree => {
state.index_contents.keys().collect()
}
};
for path in all_paths {
if !matches_prefixes(path, &path_prefixes) {
continue;
}
let head = state.head_contents.get(path);
let worktree = worktree_files.get(path);
match (head, worktree) {
let old_file = old_files.get(path);
let new_file = new_files.get(path);
match (old_file, new_file) {
(Some(old), Some(new)) if old != new => {
entries.push((
path.clone(),
Expand Down
22 changes: 16 additions & 6 deletions crates/git/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ pub trait GitRepository: Send + Sync {

fn diff_stat(
&self,
diff: DiffStatType,
path_prefixes: &[RepoPath],
) -> BoxFuture<'static, Result<crate::status::GitDiffStat>>;

Expand Down Expand Up @@ -1189,6 +1190,13 @@ pub enum DiffType {
MergeBase { base_ref: SharedString },
}

#[derive(Clone, Copy)]
pub enum DiffStatType {
HeadToIndex,
HeadToWorktree,
IndexToWorktree,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)]
pub enum PushOptions {
SetUpstream,
Expand Down Expand Up @@ -2329,6 +2337,7 @@ impl GitRepository for RealGitRepository {

fn diff_stat(
&self,
diff: DiffStatType,
path_prefixes: &[RepoPath],
) -> BoxFuture<'static, Result<crate::status::GitDiffStat>> {
let path_prefixes = path_prefixes.to_vec();
Expand All @@ -2337,12 +2346,13 @@ impl GitRepository for RealGitRepository {
self.executor
.spawn(async move {
let git_binary = git_binary?;
let mut args: Vec<String> = vec![
"diff".into(),
"--numstat".into(),
"--no-renames".into(),
"HEAD".into(),
];
let mut args: Vec<String> =
vec!["diff".into(), "--numstat".into(), "--no-renames".into()];
match diff {
DiffStatType::HeadToIndex => args.extend(["--cached".into(), "HEAD".into()]),
DiffStatType::HeadToWorktree => args.push("HEAD".into()),
DiffStatType::IndexToWorktree => {}
}
if !path_prefixes.is_empty() {
args.push("--".into());
args.extend(
Expand Down
55 changes: 44 additions & 11 deletions crates/git_ui/src/git_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4548,13 +4548,13 @@ impl GitPanel {

self.stash_entries = repo.cached_stash();

for entry in repo.cached_status() {
for status_entry in repo.cached_status() {
self.changes_count += 1;
let is_conflict = repo.had_conflict_on_last_merge_head_change(&entry.repo_path);
let is_new = entry.status.is_created();
let staging = entry.status.staging();
let is_conflict = repo.had_conflict_on_last_merge_head_change(&status_entry.repo_path);
let is_new = status_entry.status.is_created();
let staging = status_entry.status.staging();

if let Some(pending) = repo.pending_ops_for_path(&entry.repo_path)
if let Some(pending) = repo.pending_ops_for_path(&status_entry.repo_path)
&& pending
.ops
.iter()
Expand All @@ -4564,10 +4564,10 @@ impl GitPanel {
}

let entry = GitStatusEntry {
repo_path: entry.repo_path.clone(),
status: entry.status,
repo_path: status_entry.repo_path.clone(),
status: status_entry.status,
staging,
diff_stat: entry.diff_stat,
diff_stat: status_entry.diff_stat,
};

if !is_conflict && !is_new {
Expand All @@ -4583,10 +4583,16 @@ impl GitPanel {
conflict_entries.push(entry);
} else if group_by_staging_state {
if staging.has_staged() {
staged_entries.push(entry.clone());
staged_entries.push(GitStatusEntry {
diff_stat: status_entry.staged_diff_stat,
..entry.clone()
});
}
if staging.has_unstaged() {
unstaged_entries.push(entry);
unstaged_entries.push(GitStatusEntry {
diff_stat: status_entry.unstaged_diff_stat,
..entry
});
}
} else if group_by_file_status && is_conflict {
conflict_entries.push(entry);
Expand Down Expand Up @@ -9339,7 +9345,6 @@ mod tests {
("crates/util/util.rs", StatusCode::Modified.worktree()),
],
);

let project =
Project::test(fs.clone(), [path!("/root/zed/crates/gpui").as_ref()], cx).await;
let window_handle =
Expand Down Expand Up @@ -9552,6 +9557,16 @@ mod tests {
("unstaged.rs", StatusCode::Modified.worktree()),
],
);
fs.with_git_state(path!("/project/.git").as_ref(), true, |state| {
state.head_contents.insert(
repo_path("partial.rs"),
"head one\nhead two\nhead three\nhead four".into(),
);
state
.index_contents
.insert(repo_path("partial.rs"), "index one\nindex two".into());
})
.expect("fake repository should exist");

let project = Project::test(fs.clone(), [Path::new(path!("/project"))], cx).await;
let window_handle =
Expand Down Expand Up @@ -9626,6 +9641,24 @@ mod tests {
panel.stage_intent_for_entry_index(projections[1].index),
StageIntent::Stage
);
assert_eq!(
panel.entries[projections[0].index]
.status_entry()
.and_then(|entry| entry.diff_stat),
Some(DiffStat {
added: 2,
deleted: 4,
})
);
assert_eq!(
panel.entries[projections[1].index]
.status_entry()
.and_then(|entry| entry.diff_stat),
Some(DiffStat {
added: 1,
deleted: 2,
})
);
panel.entries.clone()
});

Expand Down
Loading
Loading