Fabio Ponciroli | 380e391 | 2019-09-03 14:11:56 -0700 | [diff] [blame] | 1 | # Copyright (C) 2019 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | #!/usr/bin/env bash |
| 15 | |
| 16 | set -e |
| 17 | |
| 18 | if [[ "$#" -lt "2" ]] ; then |
| 19 | cat <<EOF |
| 20 | Usage: run "$0 /path/to/git/dir [project...]" or "$0 /path/to/git/dir ALL" |
| 21 | |
| 22 | This util script can be used in case of rollback to ReviewDB during an unsuccessful |
| 23 | migration to NoteDB or simply while testing the migration process. |
| 24 | |
| 25 | It will remove all the refs used by NoteDB added during the migration (i.e.: change meta refs and sequence ref). |
| 26 | EOF |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | GERRIT_GIT_DIR=$1 |
| 31 | shift |
| 32 | |
| 33 | ALL_PROJECTS=$@ |
| 34 | if [[ "$2" -eq "ALL" ]] ; then |
| 35 | ALL_PROJECTS=`find "${GERRIT_GIT_DIR}" -type d -name "*.git"` |
| 36 | fi |
| 37 | |
| 38 | ALL_PROJECTS_ARRAY=(${ALL_PROJECTS// / }) |
| 39 | |
| 40 | for project in "${ALL_PROJECTS_ARRAY[@]}" |
| 41 | do |
| 42 | if [[ "$project" =~ /All-Users\.git$ ]]; then |
| 43 | echo "Skipping $project ..." |
| 44 | else |
| 45 | echo "Removing meta ref for $project ..." |
| 46 | cd "$project" |
| 47 | if `git show-ref meta | grep -q "/meta$"`; then |
| 48 | git show-ref meta | grep "/meta$" | cut -d' ' -f2 | xargs -L1 git update-ref -d |
| 49 | fi |
| 50 | fi |
| 51 | done |
| 52 | |
| 53 | echo "Remove sequence ref" |
| 54 | allProjectDir="$GERRIT_GIT_DIR/All-Projects.git" |
| 55 | cd $allProjectDir |
| 56 | git update-ref -d refs/sequences/changes |