]> source.dussan.org Git - jgit.git/commitdiff
Log reason for ignoring pack when IOException occurred 61/39661/3
authorMatthias Sohn <matthias.sohn@sap.com>
Mon, 22 Dec 2014 14:08:15 +0000 (15:08 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 15 Jan 2015 16:23:24 +0000 (17:23 +0100)
This should help to identify the root cause of the problem discussed on
the Gerrit list [1].

[1] https://groups.google.com/forum/#!topic/repo-discuss/Qdmbl-YZ4NU

Change-Id: I871f70e4bb1227952e1544b789013583b14e2b96
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java

index a753188e888dcf5f7050d0455d879e40225e4a08..b0ce1582d41e05daadec9a6475534239876d91c3 100644 (file)
@@ -207,6 +207,7 @@ exceptionCaughtDuringExecutionOfRmCommand=Exception caught during execution of r
 exceptionCaughtDuringExecutionOfTagCommand=Exception caught during execution of tag command
 exceptionOccurredDuringAddingOfOptionToALogCommand=Exception occurred during adding of {0} as option to a Log command
 exceptionOccurredDuringReadingOfGIT_DIR=Exception occurred during reading of $GIT_DIR/{0}. {1}
+exceptionWhileReadingPack=ERROR: Exception caught while accessing pack file {0}, the pack file might be corrupt
 expectedACKNAKFoundEOF=Expected ACK/NAK, found EOF
 expectedACKNAKGot=Expected ACK/NAK, got: {0}
 expectedBooleanStringValue=Expected boolean string value
index 65272fb0bda6e49d663a2097376b1cd67a70e862..5f42e81893427fb6e19ed8b6186c01e4209425b2 100644 (file)
@@ -266,6 +266,7 @@ public class JGitText extends TranslationBundle {
        /***/ public String exceptionCaughtDuringExecutionOfTagCommand;
        /***/ public String exceptionOccurredDuringAddingOfOptionToALogCommand;
        /***/ public String exceptionOccurredDuringReadingOfGIT_DIR;
+       /***/ public String exceptionWhileReadingPack;
        /***/ public String expectedACKNAKFoundEOF;
        /***/ public String expectedACKNAKGot;
        /***/ public String expectedBooleanStringValue;
index 58276051eaf410ec32f37d6fe851e6238712e4ab..0b83efa62aeb18e6cae0ee17f35345621ac24b35 100644 (file)
@@ -52,6 +52,8 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -329,7 +331,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                                        p.resolve(matches, id, RESOLVE_ABBREV_LIMIT);
                                } catch (IOException e) {
                                        // Assume the pack is corrupted.
-                                       //
+                                       logCorruptPackError(e, p);
                                        removePack(p);
                                }
                                if (matches.size() > RESOLVE_ABBREV_LIMIT)
@@ -418,6 +420,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                                                        continue SEARCH;
                                        } catch (IOException e) {
                                                // Assume the pack is corrupted.
+                                               logCorruptPackError(e, p);
                                                removePack(p);
                                        }
                                }
@@ -499,6 +502,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                                                        continue SEARCH;
                                        } catch (IOException e) {
                                                // Assume the pack is corrupted.
+                                               logCorruptPackError(e, p);
                                                removePack(p);
                                        }
                                }
@@ -541,7 +545,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                                        continue SEARCH;
                                } catch (IOException e) {
                                        // Assume the pack is corrupted.
-                                       //
+                                       logCorruptPackError(e, p);
                                        removePack(p);
                                }
                        }
@@ -552,6 +556,18 @@ public class ObjectDirectory extends FileObjectDatabase {
                        h.db.selectObjectRepresentation(packer, otp, curs);
        }
 
+       private static void logCorruptPackError(IOException e, PackFile p) {
+               StringBuilder buf = new StringBuilder(MessageFormat.format(
+                               JGitText.get().exceptionWhileReadingPack,
+                               p.getPackFile().getAbsolutePath()));
+               StringWriter sw = new StringWriter();
+               e.printStackTrace(new PrintWriter(sw));
+               buf.append('\n');
+               buf.append(sw.toString());
+               // TODO instead of syserr we should use a logging framework
+               System.err.println(buf.toString());
+       }
+
        @Override
        InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId id,
                        boolean createDuplicate) throws IOException {