Move commit message length checks to validation plugin

Checks of the commit message's length are removed from the
ReceiveCommits class.  These checks are now done in the commit
message length validation plugin, which is added as a core
plugin.

Change-Id: Ia0858b11e475c48f50ec63fbe0076239edf8f64b
This commit is contained in:
David Pursehouse 2012-11-05 23:48:58 +09:00
parent ec31ddf545
commit 9437b7be9f
3 changed files with 9 additions and 38 deletions

View File

@ -11,6 +11,9 @@ client.
To make use of this feature, a plugin must implement the `CommitValidationListener`
interface.
Out of the box, Gerrit includes a plugin that checks the length of the
subject and body lines of commit messages on uploaded commits.
GERRIT
------

View File

@ -52,6 +52,12 @@ limitations under the License.
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlesource.gerrit.plugins.validators</groupId>
<artifactId>commit-message-length-validator</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -89,7 +89,6 @@ import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
@ -1341,7 +1340,6 @@ public class ReceiveCommits {
CheckedFuture<Void, OrmException> insertChange() throws IOException {
rp.getRevWalk().parseBody(commit);
warnMalformedMessage(commit);
final Thread caller = Thread.currentThread();
ListenableFuture<Void> future = changeUpdateExector.submit(
@ -1632,7 +1630,6 @@ public class ReceiveCommits {
CheckedFuture<PatchSet.Id, OrmException> insertPatchSet()
throws IOException {
rp.getRevWalk().parseBody(newCommit);
warnMalformedMessage(newCommit);
final Thread caller = Thread.currentThread();
ListenableFuture<PatchSet.Id> future = changeUpdateExector.submit(
@ -1904,41 +1901,6 @@ public class ReceiveCommits {
return true;
}
private void warnMalformedMessage(RevCommit c) {
ObjectReader reader = rp.getRevWalk().getObjectReader();
if (65 < c.getShortMessage().length()) {
AbbreviatedObjectId id;
try {
id = reader.abbreviate(c);
} catch (IOException err) {
id = c.abbreviate(6);
}
addMessage("(W) " + id.name() //
+ ": commit subject >65 characters; use shorter first paragraph");
}
int longLineCnt = 0, nonEmptyCnt = 0;
for (String line : c.getFullMessage().split("\n")) {
if (!line.trim().isEmpty()) {
nonEmptyCnt++;
}
if (70 < line.length()) {
longLineCnt++;
}
}
if (0 < longLineCnt && 33 < longLineCnt * 100 / nonEmptyCnt) {
AbbreviatedObjectId id;
try {
id = reader.abbreviate(c);
} catch (IOException err) {
id = c.abbreviate(6);
}
addMessage("(W) " + id.name() //
+ ": commit message lines >70 characters; manually wrap lines");
}
}
private void autoCloseChanges(final ReceiveCommand cmd) {
final RevWalk rw = rp.getRevWalk();
try {