Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / v8 / tools / merge-to-branch.sh
index 260dc8a..ccdae6c 100755 (executable)
@@ -69,8 +69,9 @@ restore_patch_commit_hashes_if_unset() {
 }
 
 ########## Option parsing
+REVERT_FROM_BLEEDING_EDGE=0
 
-while getopts ":hs:fp:rm:" OPTION ; do
+while getopts ":hs:fp:rm:R" OPTION ; do
   case $OPTION in
     h)  usage
         exit 0
@@ -85,6 +86,9 @@ while getopts ":hs:fp:rm:" OPTION ; do
         ;;
     s)  START_STEP=$OPTARG
         ;;
+    R)  REVERSE_PATCH="--reverse"
+        REVERT_FROM_BLEEDING_EDGE=1
+        ;;
     ?)  echo "Illegal option: -$OPTARG"
         usage
         exit 1
@@ -104,7 +108,8 @@ touch "$ALREADY_MERGING_SENTINEL_FILE"
 initial_environment_checks
 
 if [ $START_STEP -le $CURRENT_STEP ] ; then
-  if [ ${#@} -lt 2 ] ; then
+  let MIN_EXPECTED_ARGS=2-$REVERT_FROM_BLEEDING_EDGE
+  if [ ${#@} -lt $MIN_EXPECTED_ARGS ] ; then
     if [ -z "$EXTRA_PATCH" ] ; then
       die "Either a patch file or revision numbers must be specified"
     fi
@@ -113,9 +118,13 @@ if [ $START_STEP -le $CURRENT_STEP ] ; then
     fi
   fi
   echo ">>> Step $CURRENT_STEP: Preparation"
-  MERGE_TO_BRANCH=$1
-  [[ -n "$MERGE_TO_BRANCH" ]] || die "Please specify a branch to merge to"
-  shift
+  if [ $REVERT_FROM_BLEEDING_EDGE -eq 1 ] ; then
+    MERGE_TO_BRANCH="bleeding_edge"
+  else
+    MERGE_TO_BRANCH=$1
+    [[ -n "$MERGE_TO_BRANCH" ]] || die "Please specify a branch to merge to"
+    shift
+  fi
   persist "MERGE_TO_BRANCH"
   common_prepare
 fi
@@ -130,10 +139,54 @@ fi
 
 let CURRENT_STEP+=1
 if [ $START_STEP -le $CURRENT_STEP ] ; then
+  echo ">>> Step $CURRENT_STEP: Search for corresponding architecture ports."
+  for REVISION in "$@" ; do
+    # Add the revision to the array if it isn't already added.
+    if  [[ ! "${FULL_REVISION_LIST[@]}" =~ (^| )$REVISION($| ) ]] ; then
+      FULL_REVISION_LIST=("${FULL_REVISION_LIST[@]}" "$REVISION")
+    fi
+    # Search for commits which matches the "Port rXXX" pattern.
+    GIT_HASHES=$(git log svn/bleeding_edge --reverse \
+                 --format=%H --grep="Port r$REVISION")
+    if [ -n "$GIT_HASHES" ]; then
+      while read -r NEXT_GIT_HASH; do
+        NEXT_SVN_REVISION=$(git svn find-rev $NEXT_GIT_HASH svn/bleeding_edge)
+        [[ -n "$NEXT_SVN_REVISION" ]] \
+          || die "Cannot determine svn revision for $NEXT_GIT_HASH"
+        FULL_REVISION_LIST=("${FULL_REVISION_LIST[@]}" "$NEXT_SVN_REVISION")
+        REVISION_TITLE=$(git log -1 --format=%s $NEXT_GIT_HASH)
+        # Is this revision included in the original revision list?
+        if [[ $@ =~ (^| )$NEXT_SVN_REVISION($| ) ]] ; then
+          echo "Found port of r$REVISION -> \
+r$NEXT_SVN_REVISION (already included): $REVISION_TITLE"
+        else
+          echo "Found port of r$REVISION -> \
+r$NEXT_SVN_REVISION: $REVISION_TITLE"
+          PORT_REVISION_LIST=("${PORT_REVISION_LIST[@]}" "$NEXT_SVN_REVISION")
+        fi
+      done <<< "$GIT_HASHES"
+    fi
+  done
+  # Next step expects a list, not an array.
+  FULL_REVISION_LIST="${FULL_REVISION_LIST[@]}"
+  # Do we find any port?
+  if [ ${#PORT_REVISION_LIST[@]} -ne 0 ] ; then
+    confirm "Automatically add corresponding ports (${PORT_REVISION_LIST[*]})?"
+    #: 'n': Restore the original revision list.
+    if [ $? -ne 0 ] ; then
+      FULL_REVISION_LIST="$@"
+    fi
+  fi
+  persist "FULL_REVISION_LIST"
+fi
+
+let CURRENT_STEP+=1
+if [ $START_STEP -le $CURRENT_STEP ] ; then
   echo ">>> Step $CURRENT_STEP: Find the git \
 revisions associated with the patches."
+  restore_if_unset "FULL_REVISION_LIST"
   current=0
-  for REVISION in "$@" ; do
+  for REVISION in $FULL_REVISION_LIST ; do
     NEXT_HASH=$(git svn find-rev "r$REVISION" svn/bleeding_edge)
     [[ -n "$NEXT_HASH" ]] \
       || die "Cannot determine git hash for r$REVISION"
@@ -144,7 +197,11 @@ revisions associated with the patches."
   done
   if [ -n "$REVISION_LIST" ] ; then
     if [ -n "$REVERSE_PATCH" ] ; then
-      NEW_COMMIT_MSG="Rollback of$REVISION_LIST in $MERGE_TO_BRANCH branch."
+      if [ $REVERT_FROM_BLEEDING_EDGE -eq 0 ] ; then
+        NEW_COMMIT_MSG="Rollback of$REVISION_LIST in $MERGE_TO_BRANCH branch."
+      else
+        NEW_COMMIT_MSG="Revert$REVISION_LIST."
+      fi
     else
       NEW_COMMIT_MSG="Merged$REVISION_LIST into $MERGE_TO_BRANCH branch."
     fi;
@@ -166,6 +223,7 @@ revisions associated with the patches."
   done
   if [ -n "$BUG_AGGREGATE" ] ; then
     echo "BUG=$BUG_AGGREGATE" >> $COMMITMSG_FILE
+    echo "LOG=N" >> $COMMITMSG_FILE
   fi
   persist "NEW_COMMIT_MSG"
   persist "REVISION_LIST"
@@ -189,14 +247,14 @@ if [ $START_STEP -le $CURRENT_STEP ] ; then
 fi
 
 let CURRENT_STEP+=1
-if [ $START_STEP -le $CURRENT_STEP ] ; then
+if [ $START_STEP -le $CURRENT_STEP ] && [ $REVERT_FROM_BLEEDING_EDGE -eq 0 ] ; then
   echo ">>> Step $CURRENT_STEP: Prepare $VERSION_FILE."
   # These version numbers are used again for creating the tag
   read_and_persist_version
 fi
 
 let CURRENT_STEP+=1
-if [ $START_STEP -le $CURRENT_STEP ] ; then
+if [ $START_STEP -le $CURRENT_STEP ] && [ $REVERT_FROM_BLEEDING_EDGE -eq 0 ] ; then
   echo ">>> Step $CURRENT_STEP: Increment version number."
   restore_if_unset "PATCH"
   NEWPATCH=$(($PATCH + 1))
@@ -229,12 +287,14 @@ if [ $START_STEP -le $CURRENT_STEP ] ; then
   git checkout $BRANCHNAME \
     || die "cannot ensure that the current branch is $BRANCHNAME"
   wait_for_lgtm
-  PRESUBMIT_TREE_CHECK="skip" git cl dcommit \
+  PRESUBMIT_TREE_CHECK="skip" git cl presubmit \
+    || die "presubmit failed"
+  PRESUBMIT_TREE_CHECK="skip" git cl dcommit --bypass-hooks \
     || die "failed to commit to $MERGE_TO_BRANCH"
 fi
 
 let CURRENT_STEP+=1
-if [ $START_STEP -le $CURRENT_STEP ] ; then
+if [ $START_STEP -le $CURRENT_STEP ] && [ $REVERT_FROM_BLEEDING_EDGE -eq 0 ] ; then
   echo ">>> Step $CURRENT_STEP: Determine svn commit revision"
   restore_if_unset "NEW_COMMIT_MSG"
   restore_if_unset "MERGE_TO_BRANCH"
@@ -248,7 +308,7 @@ if [ $START_STEP -le $CURRENT_STEP ] ; then
 fi
 
 let CURRENT_STEP+=1
-if [ $START_STEP -le $CURRENT_STEP ] ; then
+if [ $START_STEP -le $CURRENT_STEP ] && [ $REVERT_FROM_BLEEDING_EDGE -eq 0 ] ; then
   echo ">>> Step $CURRENT_STEP: Create the tag."
   restore_if_unset "SVN_REVISION"
   restore_version_if_unset "NEW"
@@ -273,9 +333,11 @@ if [ $START_STEP -le $CURRENT_STEP ] ; then
   restore_if_unset "REVISION_LIST"
   restore_version_if_unset "NEW"
   common_cleanup
-  echo "*** SUMMARY ***"
-  echo "version: $NEWMAJOR.$NEWMINOR.$NEWBUILD.$NEWPATCH"
-  echo "branch: $TO_URL"
-  echo "svn revision: $SVN_REVISION"
-  [[ -n "$REVISION_LIST" ]] && echo "patches:$REVISION_LIST"
+  if [ $REVERT_FROM_BLEEDING_EDGE==0 ] ; then
+    echo "*** SUMMARY ***"
+    echo "version: $NEWMAJOR.$NEWMINOR.$NEWBUILD.$NEWPATCH"
+    echo "branch: $TO_URL"
+    echo "svn revision: $SVN_REVISION"
+    [[ -n "$REVISION_LIST" ]] && echo "patches:$REVISION_LIST"
+  fi
 fi