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.update; 16 : 17 : import java.io.IOException; 18 : import org.eclipse.jgit.lib.ObjectId; 19 : import org.eclipse.jgit.lib.ObjectInserter; 20 : import org.eclipse.jgit.transport.ReceiveCommand; 21 : 22 : /** Context for performing the {@link BatchUpdateOp#updateRepo} phase. */ 23 : public interface RepoContext extends Context { 24 : /** 25 : * Returns inserter for writing to the repo. Callers should not flush; the walk returned by {@link 26 : * #getRevWalk()} is able to read back objects inserted by this inserter without flushing first. 27 : * 28 : * @throws IOException if an error occurred opening the repo. 29 : */ 30 : ObjectInserter getInserter() throws IOException; 31 : 32 : /** 33 : * Add a command to the pending list of commands. 34 : * 35 : * <p>Adding commands to the {@code RepoContext} is the only way of updating refs in the 36 : * repository from a {@link BatchUpdateOp}. 37 : * 38 : * @param cmd ref update command. 39 : * @throws IOException if an error occurred opening the repo. 40 : */ 41 : void addRefUpdate(ReceiveCommand cmd) throws IOException; 42 : 43 : /** 44 : * Add a command to the pending list of commands. 45 : * 46 : * <p>Adding commands to the {@code RepoContext} is the only way of updating refs in the 47 : * repository from a {@link BatchUpdateOp}. 48 : * 49 : * @param oldId the old object ID; must not be null. Use {@link ObjectId#zeroId()} for ref 50 : * creation. 51 : * @param newId the new object ID; must not be null. Use {@link ObjectId#zeroId()} for ref 52 : * deletion. 53 : * @param refName the ref name. 54 : * @throws IOException if an error occurred opening the repo. 55 : */ 56 : default void addRefUpdate(ObjectId oldId, ObjectId newId, String refName) throws IOException { 57 46 : addRefUpdate(new ReceiveCommand(oldId, newId, refName)); 58 46 : } 59 : }