From fc0c6fd984c200e55bdf4cfcada549a9b4a97461 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Fri, 16 Dec 2016 11:19:52 -0800 Subject: [PATCH] "make format" format diff since last commit from master Summary: Update clang-format script to format diff since last commit from master, instead of just last commit. In our common workflow we usually endup with multiple commits for a single PR. This change make it easier to format all stacking changes. Closes https://github.com/facebook/rocksdb/pull/1684 Differential Revision: D4340597 Pulled By: yiwu-arbug fbshipit-source-id: c18949e --- build_tools/format-diff.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/build_tools/format-diff.sh b/build_tools/format-diff.sh index 9c752b2a1..3c5605079 100755 --- a/build_tools/format-diff.sh +++ b/build_tools/format-diff.sh @@ -51,14 +51,15 @@ fi set -e uncommitted_code=`git diff HEAD` +LAST_MASTER=`git merge-base master HEAD` # If there's no uncommitted changes, we assume user are doing post-commit -# format check, in which case we'll check the modified lines from latest commit. -# Otherwise, we'll check format of the uncommitted code only. +# format check, in which case we'll check the modified lines since last commit +# from master. Otherwise, we'll check format of the uncommitted code only. if [ -z "$uncommitted_code" ] then # Check the format of last commit - diffs=$(git diff -U0 HEAD^ | $CLANG_FORMAT_DIFF -p 1) + diffs=$(git diff -U0 $LAST_MASTER^ | $CLANG_FORMAT_DIFF -p 1) else # Check the format of uncommitted lines, diffs=$(git diff -U0 HEAD | $CLANG_FORMAT_DIFF -p 1) @@ -98,7 +99,12 @@ then fi # Do in-place format adjustment. -git diff -U0 HEAD^ | $CLANG_FORMAT_DIFF -i -p 1 +if [ -z "$uncommitted_code" ] +then + git diff -U0 $LAST_MASTER^ | $CLANG_FORMAT_DIFF -i -p 1 +else + git diff -U0 HEAD^ | $CLANG_FORMAT_DIFF -i -p 1 +fi echo "Files reformatted!" # Amend to last commit if user do the post-commit format check