Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply clang format #890

Merged
merged 1 commit into from
Nov 5, 2020
Merged

Apply clang format #890

merged 1 commit into from
Nov 5, 2020

Conversation

kxl-adsk
Copy link

@kxl-adsk kxl-adsk commented Nov 4, 2020

Time to start leveraging clang-format in maya-usd. Below are updated instructions from #843

Instructions for applying clang-format to an outstanding branch / PR

These instructions assume that:

  • $MAYA_USD_REPO points to the root directory of a checkout of the maya-usd source repository
  • $COMMIT_BEFORE_FORMAT points at the commit in the dev branch immediately before clang-format is applied (this is 0fe90bc)
  • $FORMAT_COMMIT points at the commit in the dev branch where clang-format was applied (this is 7c64b5d)
  • $FORMAT_BRANCH points at the head of the branch, containing any commits after $FORMAT_COMMIT (dev branch)
  • $YOUR_BRANCH is the name of the branch which does not have clang-format applied, but want to merge dev (with clang-format) into

Download and install clang-tools 10.0 (generally included as part of llvm):

Merge + apply clang-format to your branch (these instructions assume Linux, you may need to adapt to other OSes):

cd $MAYA_USD_REPO
git checkout $YOUR_BRANCH
git merge $COMMIT_BEFORE_FORMAT
# now resolve any merge errors that may have resulted from previous command

# this next command will technically create a merge in git, but won't actually change the
# state of any files
git merge -s ours $FORMAT_COMMIT

# now, apply the formatting to your branch...for Linux:
find . -regextype posix-egrep -regex "$(echo '.*('$(echo $(cat .clang-format-include) | tr ' ' '\|')')')" -exec clang-format -i {} \+
# for MacOS
# find -E . -regex "$(echo '.*('$(echo $(cat .clang-format-include) | tr ' ' '\|')')')" -exec clang-format -i {} \+

# ...then ammend the commit, to make this the new "merged" result
git commit -a --amend --no-edit

# now merge in any of the latest stuff, that came AFTER the clang-format changes
git merge $FORMAT_BRANCH

# OPTIONAL: do a sanity check, to make sure that the diff of your branch to
#           the format branch now only contains "substantive" changes (ie, not a
#           bunch of formatting changes!)
git diff $FORMAT_BRANCH
# ...or, if you have a gui difftool set up in your .gitconfig:
git difftool $FORMAT_BRANCH

@kxl-adsk kxl-adsk added the build Related to building maya-usd repository label Nov 4, 2020
@kxl-adsk kxl-adsk merged commit 91994c0 into dev Nov 5, 2020
@kxl-adsk kxl-adsk deleted the kxl-adsk/apply_clang_format_for_real branch November 5, 2020 00:14
@aloysbaillet
Copy link
Contributor

Great to see this happening!
It would be nice to add the reformat commit sha to a file named .git-blame-ignore-revs (which can be used by the git blame command, see https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame for example).

@kxl-adsk
Copy link
Author

kxl-adsk commented Nov 5, 2020

I like this suggestion @aloysbaillet, see #895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Related to building maya-usd repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants