Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleRevListCount.rs

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