time_rz: Use idx_t for nonnegative ptrdiff_t variables.
[gnulib.git] / build-aux / vcs-to-changelog.py
blobedc6128a797336afc4b43192ce871b7f8981e823
1 #!/usr/bin/python3
2 # Main VCSToChangeLog script.
3 # Copyright (C) 2019-2020 Free Software Foundation, Inc.
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.
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.
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/>.
18 ''' Generate a ChangeLog style output based on a VCS log.
20 This script takes two revisions as input and generates a ChangeLog style output
21 for all revisions between the two revisions.
23 This script is intended to be executed from the project parent directory.
25 The vcstocl directory has a file vcstocl_quirks.py that defines a
26 function called get_project_quirks that returns a object of class type
27 ProjectQuirks or a subclass of the same. The definition of the ProjectQuirks
28 class is below and it specifies the properties that the project must set to
29 ensure correct parsing of its contents.
31 Among other things, ProjectQurks specifies the VCS to read from; the default is
32 assumed to be git. The script then studies the VCS log and for each change,
33 list out the nature of changes in the constituent files.
35 Each file type may have parser frontends that can read files and construct
36 objects that may be compared to determine the minimal changes that occured in
37 each revision. For files that do not have parsers, we may only know the nature
38 of changes at the top level depending on the information that the VCS stores.
40 The parser frontend must have a compare() method that takes the old and new
41 files as arrays of strings and prints the output in ChangeLog format.
43 Currently implemented VCS:
45 git
47 Currently implemented frontends:
50 '''
51 import sys
52 import os
53 import re
54 import argparse
55 from vcstocl.misc_util import *
56 from vcstocl import frontend_c
57 from vcstocl.vcs_git import *
58 from vcstocl.projectquirks import ProjectQuirks
60 debug = DebugUtil(False)
62 sys.path.append('/'.join([os.path.dirname(os.path.realpath(__file__)),
63 'vcstocl']))
65 def main(repo, frontends, refs):
66 ''' ChangeLog Generator Entry Point.
67 '''
68 commits = repo.list_commits(args.refs)
69 for commit in commits:
70 repo.list_changes(commit, frontends)
73 if __name__ == '__main__':
74 parser = argparse.ArgumentParser()
76 parser.add_argument('refs', metavar='ref', type=str, nargs=2,
77 help='Refs to print ChangeLog entries between')
79 parser.add_argument('-d', '--debug', required=False, action='store_true',
80 help='Run the file parser debugger.')
82 parser.add_argument('-q', '--quirks', required=False, type=str,
83 help='Load a quirks file.')
85 args = parser.parse_args()
87 debug.debug = args.debug
89 if len(args.refs) < 2:
90 debug.eprint('Two refs needed to get a ChangeLog.')
91 sys.exit(os.EX_USAGE)
93 # Load quirks file. We assume that the script is run from the top level source
94 # directory.
95 if args.quirks:
96 import importlib.util
97 spec = importlib.util.spec_from_file_location("vcstocl_quirks", args.quirks)
98 vcstocl_quirks = importlib.util.module_from_spec(spec)
99 spec.loader.exec_module(vcstocl_quirks)
100 project_quirks = vcstocl_quirks.get_project_quirks(debug)
101 else:
102 try:
103 from vcstocl_quirks import *
104 project_quirks = get_project_quirks(debug)
105 except:
106 project_quirks = ProjectQuirks()
108 REPO = {'git': GitRepo(project_quirks.IGNORE_LIST, debug)}
110 fe_c = frontend_c.Frontend(project_quirks, debug)
111 FRONTENDS = {'.c': fe_c,
112 '.h': fe_c}
114 main(REPO[project_quirks.repo], FRONTENDS, args.refs)