Skip to content

Commit 1443239

Browse files
committed
Add hash to timeline
1 parent 2085384 commit 1443239

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/bin/analyzer/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
)]
1111

1212
use anyhow::{Context, Result};
13+
use codeprints_analyzer::git;
14+
use codeprints_analyzer::Merger;
1315
use codeprints_analyzer::Parser;
1416
use codeprints_analyzer::Timeline;
15-
use codeprints_analyzer::{count_commits, Merger};
1617
use glob::glob;
1718
use std::fs;
1819
use structopt::StructOpt;
@@ -39,7 +40,7 @@ fn main() -> Result<()> {
3940
committer,
4041
} => {
4142
print!("Analyzing commits in current repository...");
42-
let input = count_commits(&before, &after, author, committer).context(
43+
let input = git::count_commits(&before, &after, author, committer).context(
4344
"Cannot read project history. Make sure there is no typo in the command",
4445
)?;
4546
let mut parser = Parser::new(input);
@@ -51,7 +52,8 @@ fn main() -> Result<()> {
5152
}
5253
let timeline = parser.parse()?;
5354

54-
write(&timeline, "codeprints.json")?;
55+
let sha = git::sha()?;
56+
write(&timeline, &format!("codeprints_{}.json", sha))?;
5557
}
5658
Command::Merge {} => {
5759
// Find all `codeprints*.json` files in the current directory

src/git.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn count_commits(
3030
Ok(commits)
3131
}
3232

33-
// Parse a date from the git log
33+
/// Parse a date from the git log
3434
pub fn parse_date(line: &str) -> Result<Option<NaiveDate>> {
3535
if line.trim().is_empty() {
3636
// Empty lines are allowed, but skipped
@@ -39,3 +39,9 @@ pub fn parse_date(line: &str) -> Result<Option<NaiveDate>> {
3939
let date: NaiveDate = line.parse().context(format!("Invalid date {}", line))?;
4040
Ok(Some(date))
4141
}
42+
43+
/// Get the current git commit sha
44+
pub fn sha() -> Result<String> {
45+
let sha = cmd("git", &["rev-parse", "--short", "HEAD"]).read()?;
46+
Ok(sha)
47+
}

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
unused_qualifications
1313
)]
1414

15-
mod git;
15+
/// Git helper functions
16+
pub mod git;
17+
1618
mod merge;
1719
mod parser;
1820
mod quartiles;
1921
mod types;
2022

21-
pub use crate::git::count_commits;
2223
pub use crate::merge::Merger;
2324
pub use crate::parser::Parser;
24-
pub use crate::types::Timeline as Timeline;
25+
pub use crate::types::Timeline;

0 commit comments

Comments
 (0)