Line data Source code
1 : // Copyright (C) 2017 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.git.receive; 16 : 17 : import static com.google.common.base.Preconditions.checkState; 18 : 19 : import com.google.gerrit.server.git.HookUtil; 20 : import java.util.Map; 21 : import org.eclipse.jgit.lib.Ref; 22 : import org.eclipse.jgit.transport.AdvertiseRefsHook; 23 : import org.eclipse.jgit.transport.ReceivePack; 24 : import org.eclipse.jgit.transport.ServiceMayNotContinueException; 25 : import org.eclipse.jgit.transport.UploadPack; 26 : 27 : /** 28 : * Hook that scans all refs and holds onto the results reference. 29 : * 30 : * <p>This allows a caller who has an {@code AllRefsWatcher} instance to get the full map of refs in 31 : * the repo, even if refs are filtered by a later hook or filter. 32 : */ 33 97 : class AllRefsWatcher implements AdvertiseRefsHook { 34 : private Map<String, Ref> allRefs; 35 : 36 : @Override 37 : public void advertiseRefs(ReceivePack rp) throws ServiceMayNotContinueException { 38 97 : allRefs = HookUtil.ensureAllRefsAdvertised(rp); 39 97 : } 40 : 41 : @Override 42 : public void advertiseRefs(UploadPack uploadPack) { 43 0 : throw new UnsupportedOperationException(); 44 : } 45 : 46 : Map<String, Ref> getAllRefs() { 47 96 : checkState(allRefs != null, "getAllRefs() only valid after refs were advertised"); 48 96 : return allRefs; 49 : } 50 : }