Skip to content

Commit bd4b7d5

Browse files
committed
fix(vcs): limit unpushed git commit queries
The VCS panel should not walk the entire ahead history on every refresh. Bound the Git unpushed-commit query to a recent window so refresh cost stays predictable on long-lived branches. Constraint: The panel still needs enough recent commit context to be useful Rejected: Keep the query unbounded and rely on fast repos | large ahead histories make refresh cost user-visible Confidence: high Scope-risk: narrow Directive: Any UI-driven VCS history query should be explicitly bounded unless the user asked for full history
1 parent eb0a6ce commit bd4b7d5

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

crates/taskers-core/src/vcs.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use taskers_control::{
1111
};
1212
use taskers_domain::{AppModel, PaneKind, SurfaceId};
1313

14+
const GIT_RECENT_COMMIT_LIMIT: &str = "50";
15+
1416
#[derive(Clone, Default)]
1517
pub struct VcsService;
1618

@@ -263,13 +265,13 @@ impl VcsService {
263265
let commits_raw = run_command(
264266
&target.repo_root,
265267
"git",
266-
&["log", "--format=%h\t%s", "--shortstat", "@{upstream}..HEAD"],
268+
&git_recent_commit_log_args("@{upstream}..HEAD"),
267269
)
268270
.or_else(|_| {
269271
run_command(
270272
&target.repo_root,
271273
"git",
272-
&["log", "--format=%h\t%s", "--shortstat", "origin/HEAD..HEAD"],
274+
&git_recent_commit_log_args("origin/HEAD..HEAD"),
273275
)
274276
})
275277
.map(|o| o.stdout)
@@ -850,6 +852,17 @@ fn normalize_git_numstat_path(path: &str) -> String {
850852
.unwrap_or_else(|| path.to_string())
851853
}
852854

855+
fn git_recent_commit_log_args(range: &str) -> [&str; 6] {
856+
[
857+
"log",
858+
"-n",
859+
GIT_RECENT_COMMIT_LIMIT,
860+
"--format=%h\t%s",
861+
"--shortstat",
862+
range,
863+
]
864+
}
865+
853866
fn enrich_files_with_stats(
854867
files: &mut [VcsFileEntry],
855868
stats: &HashMap<String, (u32, u32)>,
@@ -1066,10 +1079,10 @@ mod tests {
10661079
use std::{collections::HashMap, fs};
10671080

10681081
use super::{
1069-
enrich_files_with_stats, enrich_git_files_with_stats, jj_diff_preview,
1070-
parse_git_log_shortstat, parse_git_numstat, parse_git_status, parse_jj_bookmarks,
1071-
parse_jj_current, parse_jj_diff_stat, parse_jj_diff_summary, parse_jj_log_stat,
1072-
resolve_repo_root,
1082+
GIT_RECENT_COMMIT_LIMIT, enrich_files_with_stats, enrich_git_files_with_stats,
1083+
git_recent_commit_log_args, jj_diff_preview, parse_git_log_shortstat, parse_git_numstat,
1084+
parse_git_status, parse_jj_bookmarks, parse_jj_current, parse_jj_diff_stat,
1085+
parse_jj_diff_summary, parse_jj_log_stat, resolve_repo_root,
10731086
};
10741087
use taskers_control::{VcsFileEntry, VcsFileStatus, VcsMode};
10751088
use tempfile::TempDir;
@@ -1215,6 +1228,21 @@ mod tests {
12151228
assert_eq!(stats["src/main.rs"], (5, 2));
12161229
}
12171230

1231+
#[test]
1232+
fn git_recent_commit_log_args_include_a_limit() {
1233+
assert_eq!(
1234+
git_recent_commit_log_args("@{upstream}..HEAD"),
1235+
[
1236+
"log",
1237+
"-n",
1238+
GIT_RECENT_COMMIT_LIMIT,
1239+
"--format=%h\t%s",
1240+
"--shortstat",
1241+
"@{upstream}..HEAD",
1242+
]
1243+
);
1244+
}
1245+
12181246
#[test]
12191247
fn parses_git_log_shortstat() {
12201248
let raw = "abc1234\tfix: handle edge case\n\n 3 files changed, 10 insertions(+), 5 deletions(-)\n\ndef5678\tfeat: add new feature\n\n 1 file changed, 20 insertions(+)\n";

0 commit comments

Comments
 (0)