llvm.org GIT mirror llvm / 9e9c2af
Update git-svnrevert to accept git and svn revisions Interchangeable commit ids can now be used on this git-svnrevert, which will figure out what kind of commit that is (if you use format rNNNN for SVN commits) and make sure the right ids are used in the right places. It's a little bit more robust and user-friendly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219290 91177308-0d34-0410-b5e6-96231b3b80d8 Renato Golin 5 years ago
1 changed file(s) with 16 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
11
22 if [ $# -ne 1 ]; then
33 echo "Invalid arguments!"
4 echo "$0 <commit to revert>"
4 echo "$0 <rNNNNNN | git-hash>"
55 exit 1
66 fi
77
1212 fi
1313
1414 COMMIT=$1
15
16 SVN_REVISION=$(git svn find-rev "$COMMIT")
15 OTHER=$(git svn find-rev "$COMMIT")
1716 if [ $? -ne 0 ]; then
18 echo "Error! Could not find an svn revision for commit $COMMIT!"
17 echo "Error! Could not find an svn/git revision for commit $COMMIT!"
1918 exit 1
2019 fi
2120
21 if [ -n "$(echo $COMMIT | grep '^r[0-9]\+')" ]; then
22 SVN=`echo $COMMIT | sed -e 's/^r//'`
23 GIT=$OTHER
24 else
25 SVN=$OTHER
26 GIT=$COMMIT
27 fi
28
2229 # Grab the one line message for our revert commit message.
23 ONE_LINE_MSG=$(git log --oneline $COMMIT -1 | cut -f2- -d " ")
30 ONE_LINE_MSG=$(git log --oneline $GIT -1 | cut -f2- -d " ")
2431
2532 # Revert the commit.
26 git revert --no-commit $COMMIT 2>/dev/null
33 git revert --no-commit $GIT 2>/dev/null
2734 if [ $? -ne 0 ]; then
28 echo "Error! Failed to revert commit $COMMIT. Resetting to head."
35 echo "Error! Failed to revert commit r$SVN. Resetting to head."
2936 git reset --hard HEAD
3037 exit 1
3138 fi
3542 cat > $TEMPLATE <
3643 Revert "$ONE_LINE_MSG"
3744
38 This reverts commit r$SVN_REVISION.
45 This reverts commit r$SVN.
3946 EOF
4047
4148 # Begin the commit but give our user an opportunity to edit it.
4249 git commit --file="$TEMPLATE" --edit
4350 if [ $? -ne 0 ]; then
44 echo "Error! Failed to commit reverting commit for commit $COMMIT. Reverting to head."
51 echo "Error! Failed to commit reverting commit for commit r$SVN. Reverting to head."
4552 git reset --hard HEAD
4653 rm -rf $TEMPLATE
4754 exit 1