Line data Source code
1 : // Copyright (C) 2013 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 : 15 : package com.google.gerrit.extensions.client; 16 : 17 : /** Operation performed by a change relative to its parent. */ 18 153 : public enum ChangeKind { 19 : /** Nontrivial content changes. */ 20 153 : REWORK, 21 : 22 : /** Conflict-free merge between the new parent and the prior patch set. */ 23 153 : TRIVIAL_REBASE, 24 : 25 : /** Conflict-free change of first (left) parent of a merge commit. */ 26 153 : MERGE_FIRST_PARENT_UPDATE, 27 : 28 : /** Same tree and same parent tree. */ 29 153 : NO_CODE_CHANGE, 30 : 31 : /** Same tree, parent tree, same commit message. */ 32 153 : NO_CHANGE; 33 : 34 : public boolean matches(ChangeKind changeKind, boolean isMerge) { 35 12 : switch (changeKind) { 36 : case REWORK: 37 : // REWORK inlcudes all other change kinds, since those are just more trivial cases of a 38 : // rework 39 2 : return true; 40 : case TRIVIAL_REBASE: 41 11 : return isTrivialRebase(); 42 : case MERGE_FIRST_PARENT_UPDATE: 43 1 : return isMergeFirstParentUpdate(isMerge); 44 : case NO_CHANGE: 45 11 : return this == NO_CHANGE; 46 : case NO_CODE_CHANGE: 47 3 : return isNoCodeChange(); 48 : } 49 0 : throw new IllegalStateException("unexpected change kind: " + changeKind); 50 : } 51 : 52 : public boolean isNoCodeChange() { 53 : // NO_CHANGE is a more trivial case of NO_CODE_CHANGE and hence matched as well 54 3 : return this == NO_CHANGE || this == NO_CODE_CHANGE; 55 : } 56 : 57 : public boolean isTrivialRebase() { 58 : // NO_CHANGE is a more trivial case of TRIVIAL_REBASE and hence matched as well 59 50 : return this == NO_CHANGE || this == TRIVIAL_REBASE; 60 : } 61 : 62 : public boolean isMergeFirstParentUpdate(boolean isMerge) { 63 1 : if (!isMerge) { 64 1 : return false; 65 : } 66 : 67 : // NO_CHANGE is a more trivial case of MERGE_FIRST_PARENT_UPDATE and hence matched as well 68 1 : return this == NO_CHANGE || this == MERGE_FIRST_PARENT_UPDATE; 69 : } 70 : }