Add new git-backport.py script.
contrib/ChangeLog: * gcc-git-customization.sh: Use git-backport.py to drop all changes for ChangeLog files. * git-backport.py: New file.
This commit is contained in:
parent
8d6bae5548
commit
e247d59274
|
@ -26,7 +26,7 @@ git config alias.gcc-descr \!"f() { if test \${1:-no} = --full; then c=\${2:-mas
|
||||||
git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream); r=\$(echo \$1 | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\$,\\1,p'); n=\$(echo \$1 | sed -n 's,^r[0-9]\\+-\\([0-9]\\+\\)\$,\\1,p'); test -z \$r && echo Invalid id \$1 && exit 1; h=\$(git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$r); test -z \$h && h=\$(git rev-parse --verify --quiet \${o:-origin}/master); p=\$(git describe --all --match 'basepoints/gcc-'\$r \$h | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+-\\([0-9]\\+\\)-g[0-9a-f]*\$,\\2,p;s,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+\$,0,p'); git rev-parse --verify \$h~\$(expr \$p - \$n); }; f"
|
git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream); r=\$(echo \$1 | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\$,\\1,p'); n=\$(echo \$1 | sed -n 's,^r[0-9]\\+-\\([0-9]\\+\\)\$,\\1,p'); test -z \$r && echo Invalid id \$1 && exit 1; h=\$(git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$r); test -z \$h && h=\$(git rev-parse --verify --quiet \${o:-origin}/master); p=\$(git describe --all --match 'basepoints/gcc-'\$r \$h | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+-\\([0-9]\\+\\)-g[0-9a-f]*\$,\\2,p;s,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+\$,0,p'); git rev-parse --verify \$h~\$(expr \$p - \$n); }; f"
|
||||||
|
|
||||||
git config alias.gcc-verify '!f() { "`git rev-parse --show-toplevel`/contrib/gcc-changelog/git_check_commit.py" $@; } ; f'
|
git config alias.gcc-verify '!f() { "`git rev-parse --show-toplevel`/contrib/gcc-changelog/git_check_commit.py" $@; } ; f'
|
||||||
git config alias.gcc-backport '!f() { rev=$1; git cherry-pick -x $@; } ; f'
|
git config alias.gcc-backport '!f() { "`git rev-parse --show-toplevel`/contrib/git-backport.py" $@; } ; f'
|
||||||
git config alias.gcc-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f'
|
git config alias.gcc-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f'
|
||||||
git config alias.gcc-commit-mklog '!f() { GCC_FORCE_MKLOG=1 git commit "$@"; }; f'
|
git config alias.gcc-commit-mklog '!f() { GCC_FORCE_MKLOG=1 git commit "$@"; }; f'
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of GCC.
|
||||||
|
#
|
||||||
|
# GCC is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# GCC is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GCC; see the file COPYING. If not, write to
|
||||||
|
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='Backport a git revision and '
|
||||||
|
'stash all ChangeLog files.')
|
||||||
|
parser.add_argument('revision', help='Revision')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
r = subprocess.run('git cherry-pick -x %s' % args.revision, shell=True)
|
||||||
|
if r.returncode == 0:
|
||||||
|
cmd = 'git show --name-only --pretty="" -- "*ChangeLog" |' \
|
||||||
|
'xargs git checkout HEAD~'
|
||||||
|
subprocess.check_output(cmd, shell=True)
|
||||||
|
subprocess.check_output('git commit --amend --no-edit', shell=True)
|
||||||
|
else:
|
||||||
|
# 1) remove all ChangeLog files from conflicts
|
||||||
|
out = subprocess.check_output('git diff --name-only --diff-filter=U',
|
||||||
|
shell=True,
|
||||||
|
encoding='utf8')
|
||||||
|
conflicts = out.strip().split('\n')
|
||||||
|
changelogs = [c for c in conflicts if c.endswith('ChangeLog')]
|
||||||
|
if changelogs:
|
||||||
|
cmd = 'git checkout --theirs %s' % '\n'.join(changelogs)
|
||||||
|
subprocess.check_output(cmd, shell=True)
|
||||||
|
# 2) remove all ChangeLog files from index
|
||||||
|
cmd = 'git diff --name-only --diff-filter=M HEAD'
|
||||||
|
out = subprocess.check_output(cmd, shell=True, encoding='utf8')
|
||||||
|
out = out.strip().split('\n')
|
||||||
|
modified = [c for c in out if c.endswith('ChangeLog')]
|
||||||
|
for m in modified:
|
||||||
|
subprocess.check_output('git reset %s' % m, shell=True)
|
||||||
|
subprocess.check_output('git checkout %s' % m, shell=True)
|
||||||
|
|
||||||
|
# try to continue
|
||||||
|
if len(conflicts) == len(changelogs):
|
||||||
|
subprocess.check_output('git cherry-pick --continue', shell=True)
|
||||||
|
else:
|
||||||
|
print('Please resolve all remaining file conflicts.')
|
Loading…
Reference in New Issue