Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleRevListCount.rs

1//! `localGit:revListCount(repoPath, fromRef, toRef) -> u64`.
2//! Equivalent to `git rev-list --count from..to` - counts
3//! commits the GitLens / SCM viewlet "ahead/behind" badges
4//! display.
5
6use serde_json::{Value, json};
7
8use crate::IPC::WindServiceHandlers::{Git::Shared::RunGit::Fn as RunGit, Utilities::JsonValueHelpers::arg_string};
9
10pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
11	let RepoPath = arg_string(&Arguments, 0);
12
13	let FromRef = arg_string(&Arguments, 1);
14
15	let ToRef = arg_string(&Arguments, 2);
16
17	if RepoPath.is_empty() || FromRef.is_empty() || ToRef.is_empty() {
18		return Err("git:revListCount requires repoPath, fromRef, toRef".to_string());
19	}
20
21	let Range = format!("{}..{}", FromRef, ToRef);
22
23	let (ExitCode, Stdout, Stderr) = RunGit(
24		&uuid::Uuid::new_v4().to_string(),
25		&["rev-list".to_string(), "--count".to_string(), Range],
26		Some(&RepoPath),
27	)
28	.await?;
29
30	if ExitCode != 0 {
31		return Err(format!("git rev-list failed: {}", Stderr));
32	}
33
34	Ok(json!(Stdout.trim().parse::<u64>().unwrap_or(0)))
35}