FsckError.java

  1. /*
  2.  * Copyright (C) 2017, Google Inc. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */
  10. package org.eclipse.jgit.internal.fsck;

  11. import java.util.HashSet;
  12. import java.util.Set;

  13. import org.eclipse.jgit.annotations.Nullable;
  14. import org.eclipse.jgit.errors.CorruptPackIndexException;
  15. import org.eclipse.jgit.errors.CorruptPackIndexException.ErrorType;
  16. import org.eclipse.jgit.lib.ObjectChecker;
  17. import org.eclipse.jgit.lib.ObjectId;

  18. /**
  19.  * Holds all fsck errors of a git repository.
  20.  */
  21. public class FsckError {
  22.     /** Represents a corrupt object. */
  23.     public static class CorruptObject {
  24.         final ObjectId id;

  25.         final int type;

  26.         @Nullable
  27.         final ObjectChecker.ErrorType errorType;

  28.         /**
  29.          * @param id
  30.          *            the object identifier.
  31.          * @param type
  32.          *            type of the object.
  33.          * @param errorType
  34.          *            kind of error
  35.          */
  36.         public CorruptObject(ObjectId id, int type,
  37.                 @Nullable ObjectChecker.ErrorType errorType) {
  38.             this.id = id;
  39.             this.type = type;
  40.             this.errorType = errorType;
  41.         }

  42.         /** @return identifier of the object. */
  43.         public ObjectId getId() {
  44.             return id;
  45.         }

  46.         /** @return type of the object. */
  47.         public int getType() {
  48.             return type;
  49.         }

  50.         /** @return error type of the corruption. */
  51.         @Nullable
  52.         public ObjectChecker.ErrorType getErrorType() {
  53.             return errorType;
  54.         }
  55.     }

  56.     /** Represents a corrupt pack index file. */
  57.     public static class CorruptIndex {
  58.         String fileName;

  59.         CorruptPackIndexException.ErrorType errorType;

  60.         /**
  61.          * @param fileName
  62.          *            the file name of the pack index.
  63.          * @param errorType
  64.          *            the type of error as reported in
  65.          *            {@link CorruptPackIndexException}.
  66.          */
  67.         public CorruptIndex(String fileName, ErrorType errorType) {
  68.             this.fileName = fileName;
  69.             this.errorType = errorType;
  70.         }

  71.         /** @return the file name of the index file. */
  72.         public String getFileName() {
  73.             return fileName;
  74.         }

  75.         /** @return the error type of the corruption. */
  76.         public ErrorType getErrorType() {
  77.             return errorType;
  78.         }
  79.     }

  80.     private final Set<CorruptObject> corruptObjects = new HashSet<>();

  81.     private final Set<ObjectId> missingObjects = new HashSet<>();

  82.     private final Set<CorruptIndex> corruptIndices = new HashSet<>();

  83.     private final Set<String> nonCommitHeads = new HashSet<>();

  84.     /**
  85.      * Get corrupt objects from all pack files
  86.      *
  87.      * @return corrupt objects from all pack files
  88.      */
  89.     public Set<CorruptObject> getCorruptObjects() {
  90.         return corruptObjects;
  91.     }

  92.     /**
  93.      * Get missing objects that should present in pack files
  94.      *
  95.      * @return missing objects that should present in pack files
  96.      */
  97.     public Set<ObjectId> getMissingObjects() {
  98.         return missingObjects;
  99.     }

  100.     /**
  101.      * Get corrupt index files associated with the packs
  102.      *
  103.      * @return corrupt index files associated with the packs
  104.      */
  105.     public Set<CorruptIndex> getCorruptIndices() {
  106.         return corruptIndices;
  107.     }

  108.     /**
  109.      * Get refs/heads/* which point to non-commit object
  110.      *
  111.      * @return refs/heads/* which point to non-commit object
  112.      */
  113.     public Set<String> getNonCommitHeads() {
  114.         return nonCommitHeads;
  115.     }
  116. }