use of com.google.gerrit.server.patch.MagicFile in project gerrit by GerritCodeReview.
the class FixReplacementInterpreter method getNewCommitMessage.
private static String getNewCommitMessage(Repository repository, ObjectId patchSetCommitId, List<FixReplacement> fixReplacements) throws ResourceConflictException, IOException {
try (ObjectReader reader = repository.newObjectReader()) {
// In the magic /COMMIT_MSG file, the actual commit message is placed after some generated
// header lines. -> Need to find out to which actual line of the commit message a replacement
// refers.
MagicFile commitMessageFile = MagicFile.forCommitMessage(reader, patchSetCommitId);
int commitMessageStartLine = commitMessageFile.getStartLineOfModifiableContent();
// Line numbers are 1-based. -> Add 1 to not move first line.
// Move up for any additionally found lines.
int necessaryRangeShift = -commitMessageStartLine + 1;
ImmutableList<FixReplacement> adjustedReplacements = shiftRangesBy(fixReplacements, necessaryRangeShift);
if (referToNonPositiveLine(adjustedReplacements)) {
throw new ResourceConflictException(String.format("The header of the %s file cannot be modified.", Patch.COMMIT_MSG));
}
String commitMessage = commitMessageFile.modifiableContent();
return FixCalculator.getNewFileContent(commitMessage, adjustedReplacements);
}
}
Aggregations