View Javadoc
1   /*
2    * Copyright (C) 2017, Google Inc.
3    * and other copyright owners as documented in the project's IP log.
4    *
5    * This program and the accompanying materials are made available
6    * under the terms of the Eclipse Distribution License v1.0 which
7    * accompanies this distribution, is reproduced below, and is
8    * available at http://www.eclipse.org/org/documents/edl-v10.php
9    *
10   * All rights reserved.
11   *
12   * Redistribution and use in source and binary forms, with or
13   * without modification, are permitted provided that the following
14   * conditions are met:
15   *
16   * - Redistributions of source code must retain the above copyright
17   *   notice, this list of conditions and the following disclaimer.
18   *
19   * - Redistributions in binary form must reproduce the above
20   *   copyright notice, this list of conditions and the following
21   *   disclaimer in the documentation and/or other materials provided
22   *   with the distribution.
23   *
24   * - Neither the name of the Eclipse Foundation, Inc. nor the
25   *   names of its contributors may be used to endorse or promote
26   *   products derived from this software without specific prior
27   *   written permission.
28   *
29   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42   */
43  package org.eclipse.jgit.internal.fsck;
44  
45  import java.util.HashSet;
46  import java.util.Set;
47  
48  import org.eclipse.jgit.annotations.Nullable;
49  import org.eclipse.jgit.errors.CorruptPackIndexException;
50  import org.eclipse.jgit.errors.CorruptPackIndexException.ErrorType;
51  import org.eclipse.jgit.lib.ObjectChecker;
52  import org.eclipse.jgit.lib.ObjectId;
53  
54  /**
55   * Holds all fsck errors of a git repository.
56   */
57  public class FsckError {
58  	/** Represents a corrupt object. */
59  	public static class CorruptObject {
60  		final ObjectId id;
61  
62  		final int type;
63  
64  		@Nullable
65  		final ObjectChecker.ErrorType errorType;
66  
67  		/**
68  		 * @param id
69  		 *            the object identifier.
70  		 * @param type
71  		 *            type of the object.
72  		 * @param errorType
73  		 *            kind of error
74  		 */
75  		public CorruptObject(ObjectId id, int type,
76  				@Nullable ObjectChecker.ErrorType errorType) {
77  			this.id = id;
78  			this.type = type;
79  			this.errorType = errorType;
80  		}
81  
82  		/** @return identifier of the object. */
83  		public ObjectId getId() {
84  			return id;
85  		}
86  
87  		/** @return type of the object. */
88  		public int getType() {
89  			return type;
90  		}
91  
92  		/** @return error type of the corruption. */
93  		@Nullable
94  		public ObjectChecker.ErrorType getErrorType() {
95  			return errorType;
96  		}
97  	}
98  
99  	/** Represents a corrupt pack index file. */
100 	public static class CorruptIndex {
101 		String fileName;
102 
103 		CorruptPackIndexException.ErrorType errorType;
104 
105 		/**
106 		 * @param fileName
107 		 *            the file name of the pack index.
108 		 * @param errorType
109 		 *            the type of error as reported in
110 		 *            {@link CorruptPackIndexException}.
111 		 */
112 		public CorruptIndex(String fileName, ErrorType errorType) {
113 			this.fileName = fileName;
114 			this.errorType = errorType;
115 		}
116 
117 		/** @return the file name of the index file. */
118 		public String getFileName() {
119 			return fileName;
120 		}
121 
122 		/** @return the error type of the corruption. */
123 		public ErrorType getErrorType() {
124 			return errorType;
125 		}
126 	}
127 
128 	private final Set<CorruptObject> corruptObjects = new HashSet<>();
129 
130 	private final Set<ObjectId> missingObjects = new HashSet<>();
131 
132 	private final Set<CorruptIndex> corruptIndices = new HashSet<>();
133 
134 	private final Set<String> nonCommitHeads = new HashSet<>();
135 
136 	/**
137 	 * Get corrupt objects from all pack files
138 	 *
139 	 * @return corrupt objects from all pack files
140 	 */
141 	public Set<CorruptObject> getCorruptObjects() {
142 		return corruptObjects;
143 	}
144 
145 	/**
146 	 * Get missing objects that should present in pack files
147 	 *
148 	 * @return missing objects that should present in pack files
149 	 */
150 	public Set<ObjectId> getMissingObjects() {
151 		return missingObjects;
152 	}
153 
154 	/**
155 	 * Get corrupt index files associated with the packs
156 	 *
157 	 * @return corrupt index files associated with the packs
158 	 */
159 	public Set<CorruptIndex> getCorruptIndices() {
160 		return corruptIndices;
161 	}
162 
163 	/**
164 	 * Get refs/heads/* which point to non-commit object
165 	 *
166 	 * @return refs/heads/* which point to non-commit object
167 	 */
168 	public Set<String> getNonCommitHeads() {
169 		return nonCommitHeads;
170 	}
171 }