View Javadoc
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  
12  import java.util.HashSet;
13  import java.util.Set;
14  
15  import org.eclipse.jgit.annotations.Nullable;
16  import org.eclipse.jgit.errors.CorruptPackIndexException;
17  import org.eclipse.jgit.errors.CorruptPackIndexException.ErrorType;
18  import org.eclipse.jgit.lib.ObjectChecker;
19  import org.eclipse.jgit.lib.ObjectId;
20  
21  /**
22   * Holds all fsck errors of a git repository.
23   */
24  public class FsckError {
25  	/** Represents a corrupt object. */
26  	public static class CorruptObject {
27  		final ObjectId id;
28  
29  		final int type;
30  
31  		@Nullable
32  		final ObjectChecker.ErrorType errorType;
33  
34  		/**
35  		 * @param id
36  		 *            the object identifier.
37  		 * @param type
38  		 *            type of the object.
39  		 * @param errorType
40  		 *            kind of error
41  		 */
42  		public CorruptObject(ObjectId id, int type,
43  				@Nullable ObjectChecker.ErrorType errorType) {
44  			this.id = id;
45  			this.type = type;
46  			this.errorType = errorType;
47  		}
48  
49  		/** @return identifier of the object. */
50  		public ObjectId getId() {
51  			return id;
52  		}
53  
54  		/** @return type of the object. */
55  		public int getType() {
56  			return type;
57  		}
58  
59  		/** @return error type of the corruption. */
60  		@Nullable
61  		public ObjectChecker.ErrorType getErrorType() {
62  			return errorType;
63  		}
64  	}
65  
66  	/** Represents a corrupt pack index file. */
67  	public static class CorruptIndex {
68  		String fileName;
69  
70  		CorruptPackIndexException.ErrorType errorType;
71  
72  		/**
73  		 * @param fileName
74  		 *            the file name of the pack index.
75  		 * @param errorType
76  		 *            the type of error as reported in
77  		 *            {@link CorruptPackIndexException}.
78  		 */
79  		public CorruptIndex(String fileName, ErrorType errorType) {
80  			this.fileName = fileName;
81  			this.errorType = errorType;
82  		}
83  
84  		/** @return the file name of the index file. */
85  		public String getFileName() {
86  			return fileName;
87  		}
88  
89  		/** @return the error type of the corruption. */
90  		public ErrorType getErrorType() {
91  			return errorType;
92  		}
93  	}
94  
95  	private final Set<CorruptObject> corruptObjects = new HashSet<>();
96  
97  	private final Set<ObjectId> missingObjects = new HashSet<>();
98  
99  	private final Set<CorruptIndex> corruptIndices = new HashSet<>();
100 
101 	private final Set<String> nonCommitHeads = new HashSet<>();
102 
103 	/**
104 	 * Get corrupt objects from all pack files
105 	 *
106 	 * @return corrupt objects from all pack files
107 	 */
108 	public Set<CorruptObject> getCorruptObjects() {
109 		return corruptObjects;
110 	}
111 
112 	/**
113 	 * Get missing objects that should present in pack files
114 	 *
115 	 * @return missing objects that should present in pack files
116 	 */
117 	public Set<ObjectId> getMissingObjects() {
118 		return missingObjects;
119 	}
120 
121 	/**
122 	 * Get corrupt index files associated with the packs
123 	 *
124 	 * @return corrupt index files associated with the packs
125 	 */
126 	public Set<CorruptIndex> getCorruptIndices() {
127 		return corruptIndices;
128 	}
129 
130 	/**
131 	 * Get refs/heads/* which point to non-commit object
132 	 *
133 	 * @return refs/heads/* which point to non-commit object
134 	 */
135 	public Set<String> getNonCommitHeads() {
136 		return nonCommitHeads;
137 	}
138 }