]>
git.proxmox.com Git - mirror_frr.git/blob - git-reindent-branch.py
2 # -*- coding: utf-8 -*-
5 import subprocess
, argparse
, tempfile
9 proc
= subprocess
.Popen(cmd
, stdout
= subprocess
.PIPE
)
10 rv
= proc
.communicate('')[0].decode('UTF-8')
14 argp
= argparse
.ArgumentParser(description
= 'git whitespace-fixing tool')
15 argp
.add_argument('branch', metavar
='BRANCH', type = str, nargs
= '?', default
= 'HEAD')
16 args
= argp
.parse_args()
19 commit
= run(['git', 'rev-list', '-n', '1', branch
, '--']).strip()
20 beforeid
= run(['git', 'rev-list', '-n', '1', 'reindent-master-before', '--']).strip()
21 afterid
= run(['git', 'rev-list', '-n', '1', 'reindent-master-after', '--']).strip()
23 beforebase
= run(['git', 'merge-base', commit
, beforeid
]).strip()
24 afterbase
= run(['git', 'merge-base', commit
, afterid
]).strip()
26 if afterbase
== afterid
:
27 sys
.stderr
.write('this branch was already rebased\n')
30 if beforebase
!= beforeid
:
31 sys
.stderr
.write('you need to rebase your branch onto the tag "reindent-master-before"\n')
34 revs
= run(['git', 'rev-list', 'reindent-master-before..%s' % commit
]).strip().split('\n')
38 tmpdir
= tempfile
.mkdtemp('frrindent')
41 sys
.stderr
.write('using temporary directory %s; %d revisions\n' % (tmpdir
, len(revs
)))
42 run(['git', 'clone', '-s', '-b', 'reindent-master-after', srcdir
, 'repo'])
47 filestat
= run(['git', 'diff', '-z', '--name-status', prev
, rev
]).rstrip('\0').split('\0')
48 changes
= zip(filestat
[0::2], filestat
[1::2])
49 sys
.stderr
.write('%s: %d files\n' % (rev
, len(changes
)))
51 for typ
, name
in changes
:
53 run(['git', 'rm', name
])
54 elif typ
in ['A', 'M']:
55 run(['git', 'checkout', rev
, '--', name
])
56 if name
.endswith('.c') or name
.endswith('.h'):
57 for d
in ['babeld/', 'ldpd/', 'nhrpd/']:
58 if name
.startswith(d
):
61 sys
.stderr
.write('\t%s\n' % name
)
62 indent
.wrap_file(name
)
63 run(['git', 'add', name
])
65 run(['git', 'commit', '-C', rev
])
68 run(['git', 'push', 'origin', 'HEAD:refs/heads/reindented-branch'])
69 sys
.stderr
.write('\n\n"reindented-branch" should now be OK.\n')
70 sys
.stderr
.write('you could use "git reset --hard reindented-branch" to set your current branch to the reindented output\n')
71 sys
.stderr
.write('\033[31;1mplease always double-check the output\033[m\n')