Restrict long RevCommit.getShortMessage() to first line Some commit messages in the wild have hundreds of lines in the message body with no double LF to denote a break between paragraphs. When parsed using the traditional oneline view this creates a very disjoint layout in Gitiles, as the entire message is presented interleaved with other more well formed online commits. Short messages are encouraged to be < 65 characters so an abbreviated SHA-1 can be added to the start of the line by `git log --oneline`. If the traditional short message is more than 80 characters (well above the recommended length), display only the first line. Change-Id: Iba6ad060c0e74a6a0ff37d84c9b4e2fbe9171732
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java b/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java index b968d89..107f1e1 100644 --- a/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java +++ b/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java
@@ -152,9 +152,6 @@ if (fs.contains(Field.PARENTS)) { result.parents = Arrays.asList(c.getParents()); } - if (fs.contains(Field.SHORT_MESSAGE)) { - result.shortMessage = c.getShortMessage(); - } if (fs.contains(Field.BRANCHES)) { result.branches = getRefsById(repo, c, Constants.R_HEADS); } @@ -164,6 +161,20 @@ if (fs.contains(Field.MESSAGE)) { result.message = c.getFullMessage(); } + if (fs.contains(Field.SHORT_MESSAGE)) { + String msg = c.getShortMessage(); + if (msg.length() > 80) { + String ft = result.message; + if (ft == null) { + ft = c.getFullMessage(); + } + int lf = ft.indexOf('\n'); + if (lf > 0) { + msg = ft.substring(0, lf); + } + } + result.shortMessage = msg; + } if (fs.contains(Field.DIFF_TREE)) { result.diffEntries = computeDiffEntries(repo, view, c); }