PackDirectory: Handle errors in getPack() like other lookups

getPack(), which backs ObjectDirectory.has() and the restore of
preserved packs, logged every IOException from Pack.hasObject() as a
warning with a stack trace and removed the pack from the list. All other
lookups (resolve, open, getSize, selectRepresentation) pass the error to
handlePackError(), which since 772ee0e5f ("Log pruned packfiles as debug
and not warn logs") and b994eb49a ("Do not log packfiles moved away or
pruned") only logs a pack that was deleted at debug level.

A pack disappearing is common for the preserved directory: an external
gc or GC with prunePreserved removes preserved/ while the pack list
still holds the previous packs. When the index of such a pack is no
longer in memory, e.g. after core.packedIndexGitUseStrongRefs=false let
it be cleared, the next object lookup miss reopens the deleted index
and logged "Unable to read packfile .../preserved/...". On a busy server
this was tens of thousands of warnings a day.

Use handlePackError() in getPack() too, so that it logs the same way
as the other lookups: deleted packs at debug level, corrupt packs and
stale file handles as warnings, other errors as errors with exponential
backoff. Which packs leave the list is effectively unchanged: a failed
index load already marks the pack invalid, so a pack that is not
removed here is dropped on the next rescan of the directory.

Remove the now unused unableToReadPackfile message.

Change-Id: I6921d33270234b1af0c58fb8b01edad57918e980
Signed-off-by: Ajay Gupta <ajagup@qti.qualcomm.com>
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
index f649472..744d88a 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
@@ -830,7 +830,6 @@
 unableToCreateNewObject=Unable to create new object: {0}
 unableToReadFullArray=Unable to read an array with {0} elements from the stream
 unableToReadFullInt=Unable to read a full int from the stream
-unableToReadPackfile=Unable to read packfile {0}
 unableToRemovePath=Unable to remove path ''{0}''
 unableToWrite=Unable to write {0}
 unableToSignCommitNoSecretKey=Unable to sign commit. Signing key not available.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
index 1776f21..43d514d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
@@ -860,7 +860,6 @@ public static JGitText get() {
 	/***/ public String unableToCreateNewObject;
 	/***/ public String unableToReadFullInt;
 	/***/ public String unableToReadFullArray;
-	/***/ public String unableToReadPackfile;
 	/***/ public String unableToRemovePath;
 	/***/ public String unableToWrite;
 	/***/ public String unableToSignCommitNoSecretKey;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java
index 02a9a53..fefee22 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java
@@ -172,13 +172,7 @@ Pack getPack(AnyObjectId objectId) {
 						return p;
 					}
 				} catch (IOException e) {
-					// The hasObject call should have only touched the index, so
-					// any failure here indicates the index is unreadable by
-					// this process, and the pack is likewise not readable.
-					LOG.warn(MessageFormat.format(
-							JGitText.get().unableToReadPackfile,
-							p.getPackFile().getAbsolutePath()), e);
-					remove(p);
+					handlePackError(e, p);
 				}
 			}
 		} while (searchPacksAgain(pList));