Skip to content

Commit 35156ef

Browse files
WIP: Get commit history
Refactor commit history to remove Arc and add handler - Removed Arc from commit history return type - Added handle_commit_history request handler - Updated proto definitions for commit history requests and responses
1 parent baabf3f commit 35156ef

File tree

5 files changed

+100
-7
lines changed

5 files changed

+100
-7
lines changed

crates/git/src/commit_history.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::repository::CommitDetails;
22
use anyhow::{anyhow, Result};
3-
use std::{path::Path, process::Stdio, sync::Arc};
3+
use std::{path::Path, process::Stdio};
44

55
pub struct CommitHistory {}
66

@@ -10,7 +10,7 @@ impl CommitHistory {
1010
working_directory: &Path,
1111
skip: i32,
1212
limit: i32,
13-
) -> Result<Arc<Vec<CommitDetails>>> {
13+
) -> Result<Vec<CommitDetails>> {
1414
const COMMIT_WRAPPER_START: &str = "<COMMIT_START>";
1515
const COMMIT_WRAPPER_END: &str = "<COMMIT_END>";
1616
const DATA_MARKER: &str = "<DATA_MARKER>";

crates/git/src/repository.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub trait GitRepository: Send + Sync {
162162
/// Returns the list of git statuses, sorted by path
163163
fn status(&self, path_prefixes: &[RepoPath]) -> Result<GitStatus>;
164164

165-
fn commit_history(&self, skip: i32, limit: i32) -> Result<Arc<Vec<CommitDetails>>>;
165+
fn commit_history(&self, skip: i32, limit: i32) -> Result<Vec<CommitDetails>>;
166166

167167
fn branches(&self) -> Result<Vec<Branch>>;
168168
fn change_branch(&self, _: &str) -> Result<()>;
@@ -473,7 +473,7 @@ impl GitRepository for RealGitRepository {
473473
GitStatus::new(&self.git_binary_path, &working_directory, path_prefixes)
474474
}
475475

476-
fn commit_history(&self, skip: i32, limit: i32) -> Result<Arc<Vec<CommitDetails>>> {
476+
fn commit_history(&self, skip: i32, limit: i32) -> Result<Vec<CommitDetails>> {
477477
let working_directory = self
478478
.repository
479479
.lock()
@@ -1006,10 +1006,10 @@ impl GitRepository for FakeGitRepository {
10061006
})
10071007
}
10081008

1009-
fn commit_history(&self, skip: i32, limit: i32) -> Result<Arc<Vec<CommitDetails>>> {
1009+
fn commit_history(&self, skip: i32, limit: i32) -> Result<Vec<CommitDetails>> {
10101010
let _ = limit;
10111011
let _ = skip;
1012-
Ok(Arc::new(Vec::new()))
1012+
Ok(Vec::new())
10131013
}
10141014

10151015
fn branches(&self) -> Result<Vec<Branch>> {

crates/project/src/git.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ impl GitStore {
141141
client.add_entity_request_handler(Self::handle_askpass);
142142
client.add_entity_request_handler(Self::handle_check_for_pushed_commits);
143143
client.add_entity_request_handler(Self::handle_git_diff);
144+
client.add_entity_request_handler(Self::handle_commit_history);
144145
}
145146

146147
pub fn active_repository(&self) -> Option<Entity<Repository>> {
@@ -663,6 +664,37 @@ impl GitStore {
663664
Ok(proto::Ack {})
664665
}
665666

667+
async fn handle_commit_history(
668+
this: Entity<Self>,
669+
envelope: TypedEnvelope<proto::GitGetCommitHistory>,
670+
mut cx: AsyncApp,
671+
) -> Result<proto::GitCommitHistoryResponse> {
672+
let worktree_id = WorktreeId::from_proto(envelope.payload.worktree_id);
673+
let work_directory_id = ProjectEntryId::from_proto(envelope.payload.work_directory_id);
674+
let repository_handle =
675+
Self::repository_for_request(&this, worktree_id, work_directory_id, &mut cx)?;
676+
677+
let commits = repository_handle
678+
.update(&mut cx, |repository_handle, _| {
679+
repository_handle.get_commit_history(envelope.payload.skip, envelope.payload.limit)
680+
})?
681+
.await??;
682+
683+
Ok(proto::GitCommitHistoryResponse {
684+
commits: commits
685+
.clone()
686+
.into_iter()
687+
.map(|commit| proto::GitCommitDetails {
688+
committer_name: commit.committer_name.into(),
689+
commit_timestamp: commit.commit_timestamp.into(),
690+
committer_email: commit.committer_email.into(),
691+
sha: commit.sha.into(),
692+
message: commit.message.into(),
693+
})
694+
.collect::<Vec<_>>(),
695+
})
696+
}
697+
666698
async fn handle_show(
667699
this: Entity<Self>,
668700
envelope: TypedEnvelope<proto::GitShow>,
@@ -1662,6 +1694,49 @@ impl Repository {
16621694
})
16631695
}
16641696

1697+
pub fn get_commit_history(
1698+
&self,
1699+
skip: i32,
1700+
limit: i32,
1701+
) -> oneshot::Receiver<Result<Vec<CommitDetails>>> {
1702+
self.send_job(move |repo| async move {
1703+
match repo {
1704+
GitRepo::Local(git_repository) => git_repository.commit_history(skip, limit),
1705+
GitRepo::Remote {
1706+
project_id,
1707+
client,
1708+
worktree_id,
1709+
work_directory_id,
1710+
} => {
1711+
let response = client
1712+
.request(proto::GitGetCommitHistory {
1713+
project_id: project_id.0,
1714+
worktree_id: worktree_id.to_proto(),
1715+
work_directory_id: work_directory_id.to_proto(),
1716+
skip: skip,
1717+
limit: limit,
1718+
})
1719+
.await?;
1720+
1721+
let commits = response
1722+
.commits
1723+
.clone()
1724+
.into_iter()
1725+
.map(|commit| CommitDetails {
1726+
committer_name: commit.committer_name.into(),
1727+
commit_timestamp: commit.commit_timestamp.into(),
1728+
committer_email: commit.committer_email.into(),
1729+
sha: commit.sha.into(),
1730+
message: commit.message.into(),
1731+
})
1732+
.collect();
1733+
1734+
Ok(commits)
1735+
}
1736+
}
1737+
})
1738+
}
1739+
16651740
pub fn diff(&self, diff_type: DiffType, _cx: &App) -> oneshot::Receiver<Result<String>> {
16661741
self.send_job(|repo| async move {
16671742
match repo {

crates/proto/proto/zed.proto

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ message Envelope {
345345
AskPassResponse ask_pass_response = 318;
346346

347347
GitDiff git_diff = 319;
348-
GitDiffResponse git_diff_response = 320; // current max
348+
GitDiffResponse git_diff_response = 320;
349+
GitGetCommitHistory git_get_commit_history = 321;
350+
GitCommitHistoryResponse git_commit_history_response = 322; // current max
349351
}
350352

351353
reserved 87 to 88;
@@ -2709,6 +2711,10 @@ message GitBranchesResponse {
27092711
repeated Branch branches = 1;
27102712
}
27112713

2714+
message GitCommitHistoryResponse {
2715+
repeated GitCommitDetails commits = 1;
2716+
}
2717+
27122718
message UpdateGitBranch {
27132719
uint64 project_id = 1;
27142720
string branch_name = 2;
@@ -2937,3 +2943,11 @@ message GitDiff {
29372943
message GitDiffResponse {
29382944
string diff = 1;
29392945
}
2946+
2947+
message GitGetCommitHistory {
2948+
uint64 project_id = 1;
2949+
uint64 worktree_id = 2;
2950+
uint64 work_directory_id = 3;
2951+
int32 skip = 4;
2952+
int32 limit = 5;
2953+
}

crates/proto/src/proto.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ messages!(
460460
(CheckForPushedCommitsResponse, Background),
461461
(GitDiff, Background),
462462
(GitDiffResponse, Background),
463+
(GitGetCommitHistory, Background),
464+
(GitCommitHistoryResponse, Background),
463465
);
464466

465467
request_messages!(
@@ -607,6 +609,7 @@ request_messages!(
607609
(GitChangeBranch, Ack),
608610
(CheckForPushedCommits, CheckForPushedCommitsResponse),
609611
(GitDiff, GitDiffResponse),
612+
(GitGetCommitHistory, GitCommitHistoryResponse)
610613
);
611614

612615
entity_messages!(
@@ -713,6 +716,7 @@ entity_messages!(
713716
GitCreateBranch,
714717
CheckForPushedCommits,
715718
GitDiff,
719+
GitGetCommitHistory
716720
);
717721

718722
entity_messages!(

0 commit comments

Comments
 (0)