Line data Source code
1 : // Copyright (C) 2020 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.patch.filediff; 16 : 17 : import static com.google.common.collect.ImmutableList.toImmutableList; 18 : 19 : import com.google.auto.value.AutoValue; 20 : import com.google.common.collect.ImmutableList; 21 : import java.util.Optional; 22 : 23 : /** 24 : * An entity class containing the list of edits between two commits for a file, and the old and new 25 : * paths. 26 : */ 27 : @AutoValue 28 93 : public abstract class FileEdits { 29 : public static FileEdits create( 30 : ImmutableList<Edit> edits, Optional<String> oldPath, Optional<String> newPath) { 31 3 : return new AutoValue_FileEdits(edits, oldPath, newPath); 32 : } 33 : 34 : public static FileEdits createFromJgitEdits( 35 : ImmutableList<org.eclipse.jgit.diff.Edit> jgitEdits, 36 : Optional<String> oldPath, 37 : Optional<String> newPath) { 38 0 : return new AutoValue_FileEdits( 39 0 : jgitEdits.stream().map(Edit::fromJGitEdit).collect(toImmutableList()), oldPath, newPath); 40 : } 41 : 42 : public abstract ImmutableList<Edit> edits(); 43 : 44 : public abstract Optional<String> oldPath(); 45 : 46 : public abstract Optional<String> newPath(); 47 : 48 : public static FileEdits empty() { 49 93 : return new AutoValue_FileEdits(ImmutableList.of(), Optional.empty(), Optional.empty()); 50 : } 51 : }