Get commit log.
(repo_path: &Path, max_count: usize)
| 457 | |
| 458 | /// Get commit log. |
| 459 | pub fn get_log(repo_path: &Path, max_count: usize) -> Result<Vec<CommitInfo>> { |
| 460 | let format = "%H|%s|%an|%ad"; |
| 461 | let date_format = "%Y-%m-%d %H:%M"; |
| 462 | let args = [ |
| 463 | "log", |
| 464 | &format!("--format={}", format), |
| 465 | &format!("--date=format:{}", date_format), |
| 466 | &format!("-{}", max_count), |
| 467 | ]; |
| 468 | |
| 469 | let (_, stdout, _) = run_git(repo_path, &args)?; |
| 470 | |
| 471 | let commits: Vec<CommitInfo> = stdout |
| 472 | .lines() |
| 473 | .filter_map(|line| { |
| 474 | let parts: Vec<&str> = line.splitn(4, '|').collect(); |
| 475 | if parts.len() >= 4 { |
| 476 | Some(CommitInfo { |
| 477 | id: parts[0].to_string(), |
| 478 | message: parts[1].to_string(), |
| 479 | author: parts[2].to_string(), |
| 480 | date: parts[3].to_string(), |
| 481 | }) |
| 482 | } else { |
| 483 | None |
| 484 | } |
| 485 | }) |
| 486 | .collect(); |
| 487 | |
| 488 | Ok(commits) |
| 489 | } |
| 490 | |
| 491 | /// Branch information. |
| 492 | #[derive(Debug, Clone)] |