]> git.ipfire.org Git - thirdparty/glibc.git/blame - scripts/gitlog_to_changelog.py
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / scripts / gitlog_to_changelog.py
CommitLineData
f2144b78
SP
1#!/usr/bin/python3
2# Main VCSToChangeLog script.
d614a753 3# Copyright (C) 2019-2020 Free Software Foundation, Inc.
f2144b78
SP
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18''' Generate a ChangeLog style output based on a VCS log.
19
20This script takes two revisions as input and generates a ChangeLog style output
21for all revisions between the two revisions.
22
23This script is intended to be executed from the project parent directory.
24
25The vcs_to_changelog directory has a file vcstocl_quirks.py that defines a
26function called get_project_quirks that returns a object of class type
27ProjectQuirks or a subclass of the same. The definition of the ProjectQuirks
28class is below and it specifies the properties that the project must set to
29ensure correct parsing of its contents.
30
31Among other things, ProjectQurks specifies the VCS to read from; the default is
32assumed to be git. The script then studies the VCS log and for each change,
33list out the nature of changes in the constituent files.
34
35Each file type may have parser frontends that can read files and construct
36objects that may be compared to determine the minimal changes that occured in
37each revision. For files that do not have parsers, we may only know the nature
38of changes at the top level depending on the information that the VCS stores.
39
40The parser frontend must have a compare() method that takes the old and new
41files as arrays of strings and prints the output in ChangeLog format.
42
43Currently implemented VCS:
44
45 git
46
47Currently implemented frontends:
48
49 C
50'''
51import sys
52import os
53import re
54import argparse
55from vcs_to_changelog.misc_util import *
56from vcs_to_changelog import frontend_c
57from vcs_to_changelog.vcs_git import *
58
59debug = DebugUtil(False)
60
61class ProjectQuirks:
62 # This is a list of regex substitutions for C/C++ macros that are known to
63 # break parsing of the C programs. Each member of this list is a dict with
64 # the key 'orig' having the regex and 'sub' having the substitution of the
65 # regex.
66 MACRO_QUIRKS = []
67
68 # This is a list of macro definitions that are extensively used and are
69 # known to break parsing due to some characteristic, mainly the lack of a
70 # semicolon at the end.
71 C_MACROS = []
72
73 # The repo type, defaults to git.
74 repo = 'git'
75
76 # List of files to ignore either because they are not needed (such as the
77 # ChangeLog) or because they are non-parseable. For example, glibc has a
78 # header file that is only assembly code, which breaks the C parser.
79 IGNORE_LIST = ['ChangeLog']
80
81
82# Load quirks file. We assume that the script is run from the top level source
83# directory.
84sys.path.append('/'.join([os.getcwd(), 'scripts', 'vcs_to_changelog']))
85try:
86 from vcstocl_quirks import *
87 project_quirks = get_project_quirks(debug)
88except:
89 project_quirks = ProjectQuirks()
90
91def analyze_diff(filename, oldfile, newfile, frontends):
92 ''' Parse the output of the old and new files and print the difference.
93
94 For input files OLDFILE and NEWFILE with name FILENAME, generate reduced
95 trees for them and compare them. We limit our comparison to only C source
96 files.
97 '''
98 name, ext = os.path.splitext(filename)
99
100 if not ext in frontends.keys():
101 return None
102 else:
103 frontend = frontends[ext]
104 frontend.compare(oldfile, newfile)
105
106
107def main(repo, frontends, refs):
108 ''' ChangeLog Generator Entry Point.
109 '''
110 commits = repo.list_commits(args.refs)
111 for commit in commits:
112 repo.list_changes(commit, frontends)
113
114
115if __name__ == '__main__':
116 parser = argparse.ArgumentParser()
117
118 parser.add_argument('refs', metavar='ref', type=str, nargs=2,
119 help='Refs to print ChangeLog entries between')
120
121 parser.add_argument('-d', '--debug', required=False, action='store_true',
122 help='Run the file parser debugger.')
123
124 args = parser.parse_args()
125
126 debug.debug = args.debug
127
128 if len(args.refs) < 2:
129 debug.eprint('Two refs needed to get a ChangeLog.')
130 sys.exit(os.EX_USAGE)
131
132 REPO = {'git': GitRepo(project_quirks.IGNORE_LIST, debug)}
133
134 fe_c = frontend_c.Frontend(project_quirks, debug)
135 FRONTENDS = {'.c': fe_c,
136 '.h': fe_c}
137
138 main(REPO[project_quirks.repo], FRONTENDS, args.refs)