ObjectDirectory: improve reading of shallow file
Use FileUtils.readWithRetries(). Change-Id: I5929184caca6b83a1ee87b462e541620bd68aa90
This commit is contained in:
parent
207dd4c938
commit
673007d529
|
@ -38,7 +38,7 @@ badIgnorePatternFull=File {0} line {1}: cannot parse pattern ''{2}'': {3}
|
||||||
badObjectType=Bad object type: {0}
|
badObjectType=Bad object type: {0}
|
||||||
badRef=Bad ref: {0}: {1}
|
badRef=Bad ref: {0}: {1}
|
||||||
badSectionEntry=Bad section entry: {0}
|
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
|
bareRepositoryNoWorkdirAndIndex=Bare Repository has neither a working tree, nor an index
|
||||||
base85invalidChar=Invalid base-85 character: 0x{0}
|
base85invalidChar=Invalid base-85 character: 0x{0}
|
||||||
base85length=Base-85 encoded data must have a length that is a multiple of 5
|
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}
|
pushOptionsNotSupported=Push options not supported; received {0}
|
||||||
rawLogMessageDoesNotParseAsLogEntry=Raw log message does not parse as log entry
|
rawLogMessageDoesNotParseAsLogEntry=Raw log message does not parse as log entry
|
||||||
readConfigFailed=Reading config file ''{0}'' failed
|
readConfigFailed=Reading config file ''{0}'' failed
|
||||||
|
readShallowFailed=Reading shallow file ''{0}'' failed
|
||||||
readFileStoreAttributesFailed=Reading FileStore attributes from user config failed
|
readFileStoreAttributesFailed=Reading FileStore attributes from user config failed
|
||||||
readerIsRequired=Reader is required
|
readerIsRequired=Reader is required
|
||||||
readingObjectsFromLocalRepositoryFailed=reading objects from local repository failed: {0}
|
readingObjectsFromLocalRepositoryFailed=reading objects from local repository failed: {0}
|
||||||
|
|
|
@ -618,6 +618,7 @@ public static JGitText get() {
|
||||||
/***/ public String pushOptionsNotSupported;
|
/***/ public String pushOptionsNotSupported;
|
||||||
/***/ public String rawLogMessageDoesNotParseAsLogEntry;
|
/***/ public String rawLogMessageDoesNotParseAsLogEntry;
|
||||||
/***/ public String readConfigFailed;
|
/***/ public String readConfigFailed;
|
||||||
|
/***/ public String readShallowFailed;
|
||||||
/***/ public String readFileStoreAttributesFailed;
|
/***/ public String readFileStoreAttributesFailed;
|
||||||
/***/ public String readerIsRequired;
|
/***/ public String readerIsRequired;
|
||||||
/***/ public String readingObjectsFromLocalRepositoryFailed;
|
/***/ public String readingObjectsFromLocalRepositoryFailed;
|
||||||
|
|
|
@ -567,22 +567,36 @@ public Set<ObjectId> getShallowCommits() throws IOException {
|
||||||
|
|
||||||
if (shallowFileSnapshot == null
|
if (shallowFileSnapshot == null
|
||||||
|| shallowFileSnapshot.isModified(shallowFile)) {
|
|| shallowFileSnapshot.isModified(shallowFile)) {
|
||||||
shallowCommitsIds = new HashSet<>();
|
try {
|
||||||
|
shallowCommitsIds = FileUtils.readWithRetries(shallowFile,
|
||||||
try (BufferedReader reader = open(shallowFile)) {
|
f -> {
|
||||||
|
FileSnapshot newSnapshot = FileSnapshot.save(f);
|
||||||
|
HashSet<ObjectId> result = new HashSet<>();
|
||||||
|
try (BufferedReader reader = open(f)) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
try {
|
if (!ObjectId.isId(line)) {
|
||||||
shallowCommitsIds.add(ObjectId.fromString(line));
|
throw new IOException(
|
||||||
} catch (IllegalArgumentException ex) {
|
MessageFormat.format(JGitText
|
||||||
throw new IOException(MessageFormat
|
.get().badShallowLine,
|
||||||
.format(JGitText.get().badShallowLine, line),
|
f.getAbsolutePath(),
|
||||||
ex);
|
line));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shallowFileSnapshot = FileSnapshot.save(shallowFile);
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shallowCommitsIds;
|
return shallowCommitsIds;
|
||||||
|
|
Loading…
Reference in New Issue