]>
git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/gcc-changelog/git_repository.py
3 # Copyright (C) 2020-2023 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3, or (at your option) any later
12 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>. */
21 from datetime
import datetime
26 print('Cannot import GitPython package, please install the package:')
27 print(' Fedora, openSUSE: python3-GitPython')
28 print(' Debian, Ubuntu: python3-git')
31 from git_commit
import GitCommit
, GitInfo
, decode_path
34 def parse_git_revisions(repo_path
, revisions
, ref_name
=None):
35 repo
= Repo(repo_path
)
37 def commit_to_info(commit
):
39 c
= repo
.commit(commit
)
40 diff
= repo
.commit(commit
+ '~').diff(commit
)
44 if hasattr(file, 'renamed_file'):
45 is_renamed
= file.renamed_file
47 is_renamed
= file.renamed
50 elif file.deleted_file
:
53 # Consider that renamed files are two operations:
54 # the deletion of the original name
55 # and the addition of the new one.
56 modified_files
.append((decode_path(file.a_path
), 'D'))
60 modified_files
.append((decode_path(file.b_path
), t
))
62 date
= datetime
.utcfromtimestamp(c
.committed_date
)
63 author
= '%s <%s>' % (c
.author
.name
, c
.author
.email
)
64 git_info
= GitInfo(c
.hexsha
, date
, author
,
65 c
.message
.split('\n'), modified_files
)
72 commits
= list(repo
.iter_commits(revisions
))
74 commits
= [repo
.commit(revisions
)]
76 for commit
in commits
:
77 git_commit
= GitCommit(commit_to_info(commit
.hexsha
),
78 commit_to_info_hook
=commit_to_info
,
80 parsed_commits
.append(git_commit
)