]>
git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/gcc-changelog/git_repository.py
3 # This file is part of GCC.
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
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
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/>. */
19 from datetime
import datetime
24 print('Cannot import GitPython package, please install the package:')
25 print(' Fedora, openSUSE: python3-GitPython')
26 print(' Debian, Ubuntu: python3-git')
29 from git_commit
import GitCommit
, GitInfo
32 def parse_git_revisions(repo_path
, revisions
, strict
=False):
33 repo
= Repo(repo_path
)
35 def commit_to_info(commit
):
37 c
= repo
.commit(commit
)
38 diff
= repo
.commit(commit
+ '~').diff(commit
)
44 elif file.deleted_file
:
46 elif file.renamed_file
:
47 # Consider that renamed files are two operations:
48 # the deletion of the original name
49 # and the addition of the new one.
50 modified_files
.append((file.a_path
, 'D'))
54 modified_files
.append((file.b_path
, t
))
56 date
= datetime
.utcfromtimestamp(c
.committed_date
)
57 author
= '%s <%s>' % (c
.author
.name
, c
.author
.email
)
58 git_info
= GitInfo(c
.hexsha
, date
, author
,
59 c
.message
.split('\n'), modified_files
)
66 commits
= list(repo
.iter_commits(revisions
))
68 commits
= [repo
.commit(revisions
)]
70 for commit
in commits
:
71 git_commit
= GitCommit(commit_to_info(commit
.hexsha
), strict
=strict
,
72 commit_to_info_hook
=commit_to_info
)
73 parsed_commits
.append(git_commit
)