3 # Copyright (C) 2020 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GCC is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING. If not, write to
19 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 # Boston, MA 02110-1301, USA.
25 if __name__
== '__main__':
26 parser
= argparse
.ArgumentParser(description
='Backport a git revision and '
27 'stash all ChangeLog files.')
28 parser
.add_argument('revision', help='Revision')
29 args
= parser
.parse_args()
31 r
= subprocess
.run('git cherry-pick -x %s' % args
.revision
, shell
=True)
33 cmd
= 'git show --name-only --pretty="" -- "*ChangeLog"'
34 changelogs
= subprocess
.check_output(cmd
, shell
=True, encoding
='utf8')
35 changelogs
= changelogs
.strip()
37 for changelog
in changelogs
.split('\n'):
38 subprocess
.check_output('git checkout HEAD~ %s' % changelog
,
40 subprocess
.check_output('git commit --amend --no-edit', shell
=True)
42 # 1) remove all ChangeLog files from conflicts
43 out
= subprocess
.check_output('git diff --name-only --diff-filter=U',
46 conflicts
= out
.strip().split('\n')
47 changelogs
= [c
for c
in conflicts
if c
.endswith('ChangeLog')]
49 cmd
= 'git checkout --theirs %s' % ' '.join(changelogs
)
50 subprocess
.check_output(cmd
, shell
=True)
51 # 2) remove all ChangeLog files from index
52 cmd
= 'git diff --name-only --diff-filter=M HEAD'
53 out
= subprocess
.check_output(cmd
, shell
=True, encoding
='utf8')
54 out
= out
.strip().split('\n')
55 modified
= [c
for c
in out
if c
.endswith('ChangeLog')]
57 subprocess
.check_output('git reset %s' % m
, shell
=True)
58 subprocess
.check_output('git checkout %s' % m
, shell
=True)
61 if len(conflicts
) == len(changelogs
):
62 cmd
= 'git -c core.editor=true cherry-pick --continue'
63 subprocess
.check_output(cmd
, shell
=True)
65 print('Please resolve all remaining file conflicts.')