-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit.rs
More file actions
41 lines (39 loc) · 1.1 KB
/
git.rs
File metadata and controls
41 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use anyhow::{Context, Result};
use chrono::NaiveDate;
use duct::cmd;
/// Get the count of commits for each day from the git logs
pub fn count_commits(
before: &Option<String>,
after: &Option<String>,
authors: Vec<String>,
committers: Vec<String>,
) -> Result<String> {
let mut args = vec!["log", "--date=short", "--pretty=format:%ad"];
if let Some(before) = &before {
args.push("--before");
args.push(before);
}
if let Some(after) = &after {
args.push("--after");
args.push(after);
}
for author in &authors {
args.push("--author");
args.push(author);
}
for committer in &committers {
args.push("--committer");
args.push(committer);
}
let commits = cmd("git", &args).read()?;
Ok(commits)
}
// Parse a date from the git log
pub fn parse_date(line: &str) -> Result<Option<NaiveDate>> {
if line.trim().is_empty() {
// Empty lines are allowed, but skipped
return Ok(None);
}
let date: NaiveDate = line.parse().context(format!("Invalid date {}", line))?;
Ok(Some(date))
}