Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleRevListCount.rs

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