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  		ObjectChecker.ErrorType errorType;
65  
66  		/**
67  		 * @param id
68  		 *            the object identifier.
69  		 * @param type
70  		 *            type of the object.
71  		 */
72  		public CorruptObject(ObjectId id, int type) {
73  			this.id = id;
74  			this.type = type;
75  		}
76  
77  		void setErrorType(ObjectChecker.ErrorType errorType) {
78  			this.errorType = errorType;
79  		}
80  
81  		/** @return identifier of the object. */
82  		public ObjectId getId() {
83  			return id;
84  		}
85  
86  		/** @return type of the object. */
87  		public int getType() {
88  			return type;
89  		}
90  
91  		/** @return error type of the corruption. */
92  		@Nullable
93  		public ObjectChecker.ErrorType getErrorType() {
94  			return errorType;
95  		}
96  	}
97  
98  	/** Represents a corrupt pack index file. */
99  	public static class CorruptIndex {
100 		String fileName;
101 
102 		CorruptPackIndexException.ErrorType errorType;
103 
104 		/**
105 		 * @param fileName
106 		 *            the file name of the pack index.
107 		 * @param errorType
108 		 *            the type of error as reported in
109 		 *            {@link CorruptPackIndexException}.
110 		 */
111 		public CorruptIndex(String fileName, ErrorType errorType) {
112 			this.fileName = fileName;
113 			this.errorType = errorType;
114 		}
115 
116 		/** @return the file name of the index file. */
117 		public String getFileName() {
118 			return fileName;
119 		}
120 
121 		/** @return the error type of the corruption. */
122 		public ErrorType getErrorType() {
123 			return errorType;
124 		}
125 	}
126 
127 	private final Set<CorruptObject> corruptObjects = new HashSet<>();
128 
129 	private final Set<ObjectId> missingObjects = new HashSet<>();
130 
131 	private final Set<CorruptIndex> corruptIndices = new HashSet<>();
132 
133 	private final Set<String> nonCommitHeads = new HashSet<>();
134 
135 	/**
136 	 * Get corrupt objects from all pack files
137 	 *
138 	 * @return corrupt objects from all pack files
139 	 */
140 	public Set<CorruptObject> getCorruptObjects() {
141 		return corruptObjects;
142 	}
143 
144 	/**
145 	 * Get missing objects that should present in pack files
146 	 *
147 	 * @return missing objects that should present in pack files
148 	 */
149 	public Set<ObjectId> getMissingObjects() {
150 		return missingObjects;
151 	}
152 
153 	/**
154 	 * Get corrupt index files associated with the packs
155 	 *
156 	 * @return corrupt index files associated with the packs
157 	 */
158 	public Set<CorruptIndex> getCorruptIndices() {
159 		return corruptIndices;
160 	}
161 
162 	/**
163 	 * Get refs/heads/* which point to non-commit object
164 	 *
165 	 * @return refs/heads/* which point to non-commit object
166 	 */
167 	public Set<String> getNonCommitHeads() {
168 		return nonCommitHeads;
169 	}
170 }