]> source.dussan.org Git - jgit.git/commitdiff
ObjectDirectory: improve reading of shallow file 17/193417/12
authorRobin Müller <eclipse@mail.coder-hugo.de>
Tue, 17 May 2022 12:51:53 +0000 (14:51 +0200)
committerThomas Wolf <twolf@apache.org>
Sun, 31 Jul 2022 12:08:48 +0000 (14:08 +0200)
Use FileUtils.readWithRetries().

Change-Id: I5929184caca6b83a1ee87b462e541620bd68aa90

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 84a7a80d6258a33f078335efb2fa675dc93e3763..f3ecadd6e5c382631d623bf592be170f1d17aa84 100644 (file)
@@ -38,7 +38,7 @@ badIgnorePatternFull=File {0} line {1}: cannot parse pattern ''{2}'': {3}
 badObjectType=Bad object type: {0}
 badRef=Bad ref: {0}: {1}
 badSectionEntry=Bad section entry: {0}
-badShallowLine=Bad shallow line: {0}
+badShallowLine=Shallow file ''{0}'' has bad line: {1}
 bareRepositoryNoWorkdirAndIndex=Bare Repository has neither a working tree, nor an index
 base85invalidChar=Invalid base-85 character: 0x{0}
 base85length=Base-85 encoded data must have a length that is a multiple of 5
@@ -590,6 +590,7 @@ pushNotPermitted=push not permitted
 pushOptionsNotSupported=Push options not supported; received {0}
 rawLogMessageDoesNotParseAsLogEntry=Raw log message does not parse as log entry
 readConfigFailed=Reading config file ''{0}'' failed
+readShallowFailed=Reading shallow file ''{0}'' failed
 readFileStoreAttributesFailed=Reading FileStore attributes from user config failed
 readerIsRequired=Reader is required
 readingObjectsFromLocalRepositoryFailed=reading objects from local repository failed: {0}
index 551a5a8a9d4d171cf7958a13b42e7e48796b969f..964debcccbd97b19795e1cfe301470e369ff182c 100644 (file)
@@ -618,6 +618,7 @@ public class JGitText extends TranslationBundle {
        /***/ public String pushOptionsNotSupported;
        /***/ public String rawLogMessageDoesNotParseAsLogEntry;
        /***/ public String readConfigFailed;
+       /***/ public String readShallowFailed;
        /***/ public String readFileStoreAttributesFailed;
        /***/ public String readerIsRequired;
        /***/ public String readingObjectsFromLocalRepositoryFailed;
index 1a1d31a6321ef0b5a34b799a2fa4caa1887a59ea..7699439128c0e0fe239af4854fd386c506fd0dfb 100644 (file)
@@ -567,22 +567,36 @@ public class ObjectDirectory extends FileObjectDatabase {
 
                if (shallowFileSnapshot == null
                                || shallowFileSnapshot.isModified(shallowFile)) {
-                       shallowCommitsIds = new HashSet<>();
-
-                       try (BufferedReader reader = open(shallowFile)) {
-                               String line;
-                               while ((line = reader.readLine()) != null) {
-                                       try {
-                                               shallowCommitsIds.add(ObjectId.fromString(line));
-                                       } catch (IllegalArgumentException ex) {
-                                               throw new IOException(MessageFormat
-                                                               .format(JGitText.get().badShallowLine, line),
-                                                               ex);
-                                       }
-                               }
+                       try {
+                               shallowCommitsIds = FileUtils.readWithRetries(shallowFile,
+                                               f -> {
+                                                       FileSnapshot newSnapshot = FileSnapshot.save(f);
+                                                       HashSet<ObjectId> result = new HashSet<>();
+                                                       try (BufferedReader reader = open(f)) {
+                                                               String line;
+                                                               while ((line = reader.readLine()) != null) {
+                                                                       if (!ObjectId.isId(line)) {
+                                                                               throw new IOException(
+                                                                                               MessageFormat.format(JGitText
+                                                                                                               .get().badShallowLine,
+                                                                                                               f.getAbsolutePath(),
+                                                                                                               line));
+
+                                                                       }
+                                                                       result.add(ObjectId.fromString(line));
+                                                               }
+                                                       }
+                                                       shallowFileSnapshot = newSnapshot;
+                                                       return result;
+                                               });
+                       } catch (IOException e) {
+                               throw e;
+                       } catch (Exception e) {
+                               throw new IOException(
+                                               MessageFormat.format(JGitText.get().readShallowFailed,
+                                                               shallowFile.getAbsolutePath()),
+                                               e);
                        }
-
-                       shallowFileSnapshot = FileSnapshot.save(shallowFile);
                }
 
                return shallowCommitsIds;