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.server.project; 16 : 17 : import com.google.gerrit.entities.BranchNameKey; 18 : import com.google.gerrit.extensions.restapi.RestView; 19 : import com.google.gerrit.server.CurrentUser; 20 : import com.google.inject.TypeLiteral; 21 : import java.util.Optional; 22 : import org.eclipse.jgit.lib.ObjectId; 23 : import org.eclipse.jgit.lib.Ref; 24 : 25 : public class BranchResource extends RefResource { 26 152 : public static final TypeLiteral<RestView<BranchResource>> BRANCH_KIND = new TypeLiteral<>() {}; 27 : 28 : private final String refName; 29 : private final Optional<String> revision; 30 : 31 : public BranchResource(ProjectState projectState, CurrentUser user, Ref ref) { 32 23 : super(projectState, user); 33 23 : this.refName = ref.getName(); 34 23 : this.revision = Optional.ofNullable(ref.getObjectId()).map(ObjectId::name); 35 23 : } 36 : 37 : public BranchNameKey getBranchKey() { 38 5 : return BranchNameKey.create(getNameKey(), refName); 39 : } 40 : 41 : @Override 42 : public String getRef() { 43 16 : return refName; 44 : } 45 : 46 : @Override 47 : public Optional<String> getRevision() { 48 5 : return revision; 49 : } 50 : }