summaryrefslogtreecommitdiff
path: root/git-reindent-branch.py
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-08-22 18:49:23 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2017-08-22 18:51:31 +0200
commitfeda3ca36c9d28af67b26336b41b1d839fb2d79f (patch)
treed3dff61748d6f9f118cc602f8308c4b8b1f43083 /git-reindent-branch.py
parent1d84515ca9d0a5e543be7e8e7ca9afc8b744e662 (diff)
*: update git-reindent-branch.py
- autodetect whether it's on master or stable/3.0 - grab .clang-format from master Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'git-reindent-branch.py')
-rw-r--r--git-reindent-branch.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/git-reindent-branch.py b/git-reindent-branch.py
index b0dd8db6de..c207f5946f 100644
--- a/git-reindent-branch.py
+++ b/git-reindent-branch.py
@@ -11,14 +11,28 @@ def run(cmd):
proc.wait()
return rv
+clangfmt = run(['git', 'show', 'master:.clang-format'])
+
argp = argparse.ArgumentParser(description = 'git whitespace-fixing tool')
argp.add_argument('branch', metavar='BRANCH', type = str, nargs = '?', default = 'HEAD')
args = argp.parse_args()
branch = args.branch
commit = run(['git', 'rev-list', '-n', '1', branch, '--']).strip()
-beforeid = run(['git', 'rev-list', '-n', '1', 'reindent-master-before', '--']).strip()
-afterid = run(['git', 'rev-list', '-n', '1', 'reindent-master-after', '--']).strip()
+
+# frr-3.1-dev = first commit that is on master but not on stable/3.0
+masterid = run(['git', 'rev-list', '-n', '1', 'frr-3.1-dev', '--']).strip()
+masterbase = run(['git', 'merge-base', commit, masterid]).strip()
+
+if masterbase == masterid:
+ refbranch = 'master'
+else:
+ refbranch = '3.0'
+
+sys.stderr.write('autodetected base: %s (can be 3.0 or master)\n' % refbranch)
+
+beforeid = run(['git', 'rev-list', '-n', '1', 'reindent-%s-before' % refbranch, '--']).strip()
+afterid = run(['git', 'rev-list', '-n', '1', 'reindent-%s-after' % refbranch, '--']).strip()
beforebase = run(['git', 'merge-base', commit, beforeid]).strip()
afterbase = run(['git', 'merge-base', commit, afterid]).strip()
@@ -28,10 +42,10 @@ if afterbase == afterid:
sys.exit(1)
if beforebase != beforeid:
- sys.stderr.write('you need to rebase your branch onto the tag "reindent-master-before"\n')
+ sys.stderr.write('you need to rebase your branch onto the tag "reindent-%s-before"\n' % refbranch)
sys.exit(1)
-revs = run(['git', 'rev-list', 'reindent-master-before..%s' % commit]).strip().split('\n')
+revs = run(['git', 'rev-list', 'reindent-%s-before..%s' % (refbranch, commit)]).strip().split('\n')
revs.reverse()
srcdir = os.getcwd()
@@ -39,9 +53,12 @@ tmpdir = tempfile.mkdtemp('frrindent')
os.chdir(tmpdir)
sys.stderr.write('using temporary directory %s; %d revisions\n' % (tmpdir, len(revs)))
-run(['git', 'clone', '-s', '-b', 'reindent-master-after', srcdir, 'repo'])
+run(['git', 'clone', '-s', '-b', 'reindent-%s-after' % refbranch, srcdir, 'repo'])
os.chdir('repo')
+with open('.clang-format', 'w') as fd:
+ fd.write(clangfmt)
+
prev = beforeid
for rev in revs:
filestat = run(['git', 'diff', '-z', '--name-status', prev, rev]).rstrip('\0').split('\0')