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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use std::path::PathBuf;
use git2::{Commit as GitCommit, Repository};
#[derive(Clone)]
pub struct Commit<'a> {
git_commit: GitCommit<'a>,
repo: &'a Repository,
}
impl<'a> Commit<'a> {
pub(crate) fn new(git_commit: GitCommit<'a>, repo: &'a Repository) -> Self {
Self { git_commit, repo }
}
// pub(crate) fn commit(&self) -> &GitCommit<'a> {
// &self.git_commit
// }
pub(crate) fn message(&self) -> String {
self.git_commit.summary().unwrap_or_default().to_string()
}
// pub(crate) fn hash(&self) -> String {
// self.git_commit.id().to_string()
// }
// pub(crate) fn author(&self) -> String {
// self.git_commit
// .author()
// .name()
// .unwrap_or_default()
// .to_string()
// }
// pub(crate) fn date(&self) -> String {
// self.git_commit.time().seconds().to_string()
// }
pub(crate) fn is_merge(&self) -> bool {
self.git_commit.parents().len() > 1
}
pub(crate) fn files(&self) -> Vec<PathBuf> {
let mut diff_files = vec![];
let a = if self.git_commit.parents().len() == 1 {
let parent = self.git_commit.parent(0).unwrap();
Some(parent.tree().unwrap())
} else {
None
};
let b = self.git_commit.tree().unwrap();
let diff = self
.repo
.diff_tree_to_tree(a.as_ref(), Some(&b), None)
.unwrap();
let ds = diff.deltas();
for d in ds {
let file_name = d.new_file().path().unwrap().to_owned();
// .unwrap().to_str().unwrap().to_owned()
if !file_name.starts_with("master") {
diff_files.push(file_name);
}
}
diff_files
}
}