Skip to content
David Lamparter edited this page Aug 22, 2017 · 5 revisions

FRR's master branch has been reindented to Linux kernel CodingStyle on Monday, July 17th, 2017. To adapt your local in-development branches, follow these instructions:


install clang 4.0

You need clang 4.0 to automatically reindent your source code. You can hopefully find it in your distribution's packages. If it's not easily possible to install clang 4.0, you can download a prebuilt binary package for most distributions here.


determine whether to rebase or merge

A branch can be adjusted for the whitespace changes either by merging or rebasing the reindentation. You need to pick one of the 2 approaches.

You should merge, if:

  • the branch already contains other merges
  • the branch shares history with other branches
  • the branch's commit IDs are otherwise important

You should rebase, if:

  • the branch is small to medium in size
  • the branch forks off master without any further merges
  • the branch contains development history that you want to flatten/squash anyway

reindent by rebase

  1. switch to your branch
    git checkout mybranch
    
  2. rebase your branch onto the last commit before the reindentation:
    git rebase reindent-master-before
    
  3. (fix any code conflicts this may entail)
  4. use the git-reindent-branch.py script:
    git show master:git-reindent-branch.py > git-reindent-branch.py
    git show master:indent.py > indent.py
    git show master:.clang-format > .clang-format
    python git-reindent-branch.py mybranch
    
  5. if the script successfully completes, you now have a branch named reindented-branch in your working directory. This branch should contains all of your commits, identical for all purposes except that all of the code should be properly indented. Please check that its history and diff looks correct.
  6. Make a backup of your previous branch, then replace your branch with reindented-branch and delete the latter:
    git branch backup/mybranch HEAD
    git reset --hard reindented-branch
    git branch -D reindented-branch
    
    NOTE: git reset will overwrite your current HEAD with the reindented output here. Don't switch to another branch in the middle.
  7. Rebase your branch again to bring it up to date with master:
    git rebase master
    
  8. (fix any code conflicts this may entail)
  9. Force-Push your branch to any repositories that have a copy of it:
    git push -f somerepo mybranch
    

reindent by merge

  1. switch to your branch

    git checkout mybranch
    
  2. merge the last commit before the reindentation into your branch:

    git merge reindent-master-before
    
  3. (fix any code conflicts this may entail)

  4. perform a no-op merge of the reindentation:

    git merge --strategy=ours reindent-master-after
    

    This does not actually do any change to your source code; it creates an "empty" merge commit that doesn't actually merge anything.

    NOTE: do NOT replace reindent-master-after with master. It is essential to merge exactly this tag/commit.

  5. reindent your source code:

    git show master:indent.py > indent.py
    git show master:.clang-format > .clang-format
    python indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
    
  6. add the reindentation changes and amend them into the merge:

    git add -u
    git commit --amend
    

    (This really should be amended and not left as a separate commit because the latter would interfere with the next merge of/into master.)

  7. merge current master to bring the branch up to date:

    git merge master
    
  8. (fix any code conflicts this may entail)

  9. Push the branch out.