LCOV - code coverage report
Current view: top level - common/data - PatchScript.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 47 49 95.9 %
Date: 2022-11-19 15:00:39 Functions: 19 20 95.0 %

          Line data    Source code
       1             : // Copyright (C) 2009 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.common.data;
      16             : 
      17             : import com.google.common.collect.ImmutableList;
      18             : import com.google.common.collect.ImmutableSet;
      19             : import com.google.gerrit.entities.Patch.ChangeType;
      20             : import com.google.gerrit.extensions.client.DiffPreferencesInfo;
      21             : import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
      22             : import com.google.gerrit.prettify.common.SparseFileContent;
      23             : import java.util.List;
      24             : import java.util.Set;
      25             : import org.eclipse.jgit.diff.Edit;
      26             : 
      27             : public class PatchScript {
      28          14 :   public enum DisplayMethod {
      29          14 :     NONE,
      30          14 :     DIFF,
      31          14 :     IMG
      32             :   }
      33             : 
      34          25 :   public enum FileMode {
      35          25 :     FILE,
      36          25 :     SYMLINK,
      37          25 :     GITLINK;
      38             : 
      39             :     public static FileMode fromJgitFileMode(org.eclipse.jgit.lib.FileMode jgitFileMode) {
      40          15 :       PatchScript.FileMode fileMode = PatchScript.FileMode.FILE;
      41          15 :       if (jgitFileMode == org.eclipse.jgit.lib.FileMode.SYMLINK) {
      42           0 :         fileMode = FileMode.SYMLINK;
      43          15 :       } else if (jgitFileMode == org.eclipse.jgit.lib.FileMode.GITLINK) {
      44           1 :         fileMode = FileMode.GITLINK;
      45             :       }
      46          15 :       return fileMode;
      47             :     }
      48             :   }
      49             : 
      50             :   public static class PatchScriptFileInfo {
      51             :     public final String name;
      52             :     public final FileMode mode;
      53             :     public final SparseFileContent content;
      54             :     public final DisplayMethod displayMethod;
      55             :     public final String mimeType;
      56             :     public final String commitId;
      57             : 
      58             :     PatchScriptFileInfo(
      59             :         String name,
      60             :         FileMode mode,
      61             :         SparseFileContent content,
      62             :         DisplayMethod displayMethod,
      63             :         String mimeType,
      64          14 :         String commitId) {
      65          14 :       this.name = name;
      66          14 :       this.mode = mode;
      67          14 :       this.content = content;
      68          14 :       this.displayMethod = displayMethod;
      69          14 :       this.mimeType = mimeType;
      70          14 :       this.commitId = commitId;
      71          14 :     }
      72             :   }
      73             : 
      74             :   private final ChangeType changeType;
      75             :   private final ImmutableList<String> header;
      76             :   private final DiffPreferencesInfo diffPrefs;
      77             :   private final ImmutableList<Edit> edits;
      78             :   private final ImmutableSet<Edit> editsDueToRebase;
      79             :   private final boolean intralineFailure;
      80             :   private final boolean intralineTimeout;
      81             :   private final boolean binary;
      82             :   private final PatchScriptFileInfo fileInfoA;
      83             :   private final PatchScriptFileInfo fileInfoB;
      84             : 
      85             :   public PatchScript(
      86             :       ChangeType ct,
      87             :       String on,
      88             :       String nn,
      89             :       FileMode om,
      90             :       FileMode nm,
      91             :       ImmutableList<String> h,
      92             :       DiffPreferencesInfo dp,
      93             :       SparseFileContent ca,
      94             :       SparseFileContent cb,
      95             :       ImmutableList<Edit> e,
      96             :       ImmutableSet<Edit> editsDueToRebase,
      97             :       DisplayMethod ma,
      98             :       DisplayMethod mb,
      99             :       String mta,
     100             :       String mtb,
     101             :       boolean idf,
     102             :       boolean idt,
     103             :       boolean bin,
     104             :       String cma,
     105          14 :       String cmb) {
     106          14 :     changeType = ct;
     107          14 :     header = h;
     108          14 :     diffPrefs = dp;
     109          14 :     edits = e;
     110          14 :     this.editsDueToRebase = editsDueToRebase;
     111          14 :     intralineFailure = idf;
     112          14 :     intralineTimeout = idt;
     113          14 :     binary = bin;
     114             : 
     115          14 :     fileInfoA = new PatchScriptFileInfo(on, om, ca, ma, mta, cma);
     116          14 :     fileInfoB = new PatchScriptFileInfo(nn, nm, cb, mb, mtb, cmb);
     117          14 :   }
     118             : 
     119             :   public List<String> getPatchHeader() {
     120          10 :     return header;
     121             :   }
     122             : 
     123             :   public ChangeType getChangeType() {
     124          14 :     return changeType;
     125             :   }
     126             : 
     127             :   public String getOldName() {
     128          14 :     return fileInfoA.name;
     129             :   }
     130             : 
     131             :   public String getNewName() {
     132          14 :     return fileInfoB.name;
     133             :   }
     134             : 
     135             :   public DiffPreferencesInfo getDiffPrefs() {
     136           0 :     return diffPrefs;
     137             :   }
     138             : 
     139             :   public boolean isIgnoreWhitespace() {
     140          10 :     return diffPrefs.ignoreWhitespace != Whitespace.IGNORE_NONE;
     141             :   }
     142             : 
     143             :   public boolean hasIntralineFailure() {
     144           4 :     return intralineFailure;
     145             :   }
     146             : 
     147             :   public boolean hasIntralineTimeout() {
     148           4 :     return intralineTimeout;
     149             :   }
     150             : 
     151             :   public SparseFileContent getA() {
     152          10 :     return fileInfoA.content;
     153             :   }
     154             : 
     155             :   public SparseFileContent getB() {
     156          10 :     return fileInfoB.content;
     157             :   }
     158             : 
     159             :   public List<Edit> getEdits() {
     160          10 :     return edits;
     161             :   }
     162             : 
     163             :   public Set<Edit> getEditsDueToRebase() {
     164          10 :     return editsDueToRebase;
     165             :   }
     166             : 
     167             :   public boolean isBinary() {
     168          10 :     return binary;
     169             :   }
     170             : 
     171             :   public PatchScriptFileInfo getFileInfoA() {
     172          10 :     return fileInfoA;
     173             :   }
     174             : 
     175             :   public PatchScriptFileInfo getFileInfoB() {
     176          10 :     return fileInfoB;
     177             :   }
     178             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750