diff options
author | Robin Müller <eclipse@mail.coder-hugo.de> | 2022-05-17 14:51:53 +0200 |
---|---|---|
committer | Thomas Wolf <twolf@apache.org> | 2022-07-31 14:08:48 +0200 |
commit | 673007d52909eb02e301b900f315f5dc91b16209 (patch) | |
tree | 649f75c2ebba09313bffb13b1bc6042feed031be /org.eclipse.jgit/src/org/eclipse/jgit | |
parent | 207dd4c938830e84c9101d30edb7fe626e04bbe1 (diff) | |
download | jgit-673007d52909eb02e301b900f315f5dc91b16209.tar.gz jgit-673007d52909eb02e301b900f315f5dc91b16209.zip |
ObjectDirectory: improve reading of shallow file
Use FileUtils.readWithRetries().
Change-Id: I5929184caca6b83a1ee87b462e541620bd68aa90
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java | 1 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java | 44 |
2 files changed, 30 insertions, 15 deletions
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 551a5a8a9d..964debcccb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -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; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java index 1a1d31a632..7699439128 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java @@ -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; |