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.edit.tree; 16 : 17 : import com.google.common.collect.ImmutableList; 18 : import com.google.common.collect.ImmutableSet; 19 : import java.util.Collections; 20 : import java.util.List; 21 : import org.eclipse.jgit.dircache.DirCacheEditor; 22 : import org.eclipse.jgit.lib.ObjectId; 23 : import org.eclipse.jgit.lib.Repository; 24 : 25 : /** A {@code TreeModification} which deletes a file. */ 26 : public class DeleteFileModification implements TreeModification { 27 : 28 : private final String filePath; 29 : 30 13 : public DeleteFileModification(String filePath) { 31 13 : this.filePath = filePath; 32 13 : } 33 : 34 : @Override 35 : public List<DirCacheEditor.PathEdit> getPathEdits( 36 : Repository repository, ObjectId treeId, ImmutableList<? extends ObjectId> parents) { 37 13 : DirCacheEditor.DeletePath deletePathEdit = new DirCacheEditor.DeletePath(filePath); 38 13 : return Collections.singletonList(deletePathEdit); 39 : } 40 : 41 : @Override 42 : public ImmutableSet<String> getFilePaths() { 43 13 : return ImmutableSet.of(filePath); 44 : } 45 : }