152
|
1 #!/usr/bin/env python3
|
|
2 #
|
|
3 # This file is part of GCC.
|
|
4 #
|
|
5 # GCC is free software; you can redistribute it and/or modify it under
|
|
6 # the terms of the GNU General Public License as published by the Free
|
|
7 # Software Foundation; either version 3, or (at your option) any later
|
|
8 # version.
|
|
9 #
|
|
10 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 # for more details.
|
|
14 #
|
|
15 # You should have received a copy of the GNU General Public License
|
|
16 # along with GCC; see the file COPYING3. If not see
|
|
17 # <http://www.gnu.org/licenses/>. */
|
|
18
|
|
19 from datetime import datetime
|
|
20
|
|
21 try:
|
|
22 from git import Repo
|
|
23 except ImportError:
|
|
24 print('Cannot import GitPython package, please install the package:')
|
|
25 print(' Fedora, openSUSE: python3-GitPython')
|
|
26 print(' Debian, Ubuntu: python3-git')
|
|
27 exit(1)
|
|
28
|
|
29 from git_commit import GitCommit
|
|
30
|
|
31
|
|
32 def parse_git_revisions(repo_path, revisions, strict=False):
|
|
33 repo = Repo(repo_path)
|
|
34
|
|
35 parsed_commits = []
|
|
36 if '..' in revisions:
|
|
37 commits = list(repo.iter_commits(revisions))
|
|
38 else:
|
|
39 commits = [repo.commit(revisions)]
|
|
40
|
|
41 for commit in commits:
|
|
42 diff = repo.commit(commit.hexsha + '~').diff(commit.hexsha)
|
|
43
|
|
44 modified_files = []
|
|
45 for file in diff:
|
|
46 if file.new_file:
|
|
47 t = 'A'
|
|
48 elif file.deleted_file:
|
|
49 t = 'D'
|
|
50 else:
|
|
51 t = 'M'
|
|
52 modified_files.append((file.b_path, t))
|
|
53
|
|
54 date = datetime.utcfromtimestamp(commit.committed_date)
|
|
55 author = '%s <%s>' % (commit.author.name, commit.author.email)
|
|
56 git_commit = GitCommit(commit.hexsha, date, author,
|
|
57 commit.message.split('\n'), modified_files,
|
|
58 strict=strict)
|
|
59 parsed_commits.append(git_commit)
|
|
60 return parsed_commits
|