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 import argparse
|
|
20 import datetime
|
|
21 import os
|
|
22
|
|
23 from git import Repo
|
|
24
|
|
25 from git_repository import parse_git_revisions
|
|
26
|
|
27 current_timestamp = datetime.datetime.now().strftime('%Y%m%d\n')
|
|
28
|
|
29
|
|
30 def read_timestamp(path):
|
|
31 return open(path).read()
|
|
32
|
|
33
|
|
34 def prepend_to_changelog_files(repo, folder, git_commit):
|
|
35 if not git_commit.success:
|
|
36 for error in git_commit.errors:
|
|
37 print(error)
|
|
38 raise AssertionError()
|
|
39 for entry, output in git_commit.to_changelog_entries(use_commit_ts=True):
|
|
40 full_path = os.path.join(folder, entry, 'ChangeLog')
|
|
41 print('writting to %s' % full_path)
|
|
42 if os.path.exists(full_path):
|
|
43 content = open(full_path).read()
|
|
44 else:
|
|
45 content = ''
|
|
46 with open(full_path, 'w+') as f:
|
|
47 f.write(output)
|
|
48 if content:
|
|
49 f.write('\n\n')
|
|
50 f.write(content)
|
|
51 repo.git.add(full_path)
|
|
52
|
|
53
|
|
54 active_refs = ['master', 'releases/gcc-8', 'releases/gcc-9', 'releases/gcc-10']
|
|
55
|
|
56 parser = argparse.ArgumentParser(description='Update DATESTAMP and generate '
|
|
57 'ChangeLog entries')
|
|
58 parser.add_argument('-g', '--git-path', default='.',
|
|
59 help='Path to git repository')
|
|
60 args = parser.parse_args()
|
|
61
|
|
62 repo = Repo(args.git_path)
|
|
63 origin = repo.remotes['origin']
|
|
64
|
|
65 for ref in origin.refs:
|
|
66 assert ref.name.startswith('origin/')
|
|
67 name = ref.name[len('origin/'):]
|
|
68 if name in active_refs:
|
|
69 if name in repo.branches:
|
|
70 branch = repo.branches[name]
|
|
71 else:
|
|
72 branch = repo.create_head(name, ref).set_tracking_branch(ref)
|
|
73 print('=== Working on: %s ===' % branch, flush=True)
|
|
74 origin.pull(rebase=True)
|
|
75 branch.checkout()
|
|
76 print('branch pulled and checked out')
|
|
77 assert not repo.index.diff(None)
|
|
78 commit = branch.commit
|
|
79 commit_count = 1
|
|
80 while commit:
|
|
81 if (commit.author.email == 'gccadmin@gcc.gnu.org'
|
|
82 and commit.message.strip() == 'Daily bump.'):
|
|
83 break
|
|
84 commit = commit.parents[0]
|
|
85 commit_count += 1
|
|
86
|
|
87 print('%d revisions since last Daily bump' % commit_count)
|
|
88 datestamp_path = os.path.join(args.git_path, 'gcc/DATESTAMP')
|
|
89 if read_timestamp(datestamp_path) != current_timestamp:
|
|
90 print('DATESTAMP will be changed:')
|
|
91 commits = parse_git_revisions(args.git_path, '%s..HEAD'
|
|
92 % commit.hexsha)
|
|
93 for git_commit in reversed(commits):
|
|
94 prepend_to_changelog_files(repo, args.git_path, git_commit)
|
|
95 # update timestamp
|
|
96 with open(datestamp_path, 'w+') as f:
|
|
97 f.write(current_timestamp)
|
|
98 repo.git.add(datestamp_path)
|
|
99 repo.index.commit('Daily bump.')
|
|
100 # TODO: push the repository
|
|
101 # repo.git.push('origin', branch)
|
|
102 else:
|
|
103 print('DATESTAMP unchanged')
|
|
104 print('branch is done\n', flush=True)
|