summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-03-20 12:49:35 -0700
committerShawn O. Pearce <sop@google.com>2009-03-20 12:49:39 -0700
commit7663ffbb8ef9e2d9d0a4f66c5802e29eadb983d4 (patch)
tree8a40b5da578fca8745e5acdab5896c85356a8114
parent563dd769c4960f3a9d48f7520d82f1b53756b18e (diff)
Quote the line a comment applies to when sending comments by email
Gerrit 1.x and Reitveld included the quoted line from the source file when sending out line level comments by email. For example, they showed the following if the comment was placed on a line declaring "int foo = 4": Line 4: int foo = 4; No foo. Textbooks ain't no good for learn'n. We now (finally) do the same in Gerrit2. Bug: GERRIT-33 Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r--src/main/java/com/google/gerrit/server/ChangeMail.java55
1 files changed, 49 insertions, 6 deletions
diff --git a/src/main/java/com/google/gerrit/server/ChangeMail.java b/src/main/java/com/google/gerrit/server/ChangeMail.java
index 476b113fb7..e7515bca81 100644
--- a/src/main/java/com/google/gerrit/server/ChangeMail.java
+++ b/src/main/java/com/google/gerrit/server/ChangeMail.java
@@ -30,9 +30,12 @@ import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.reviewdb.StarredChange;
import com.google.gerrit.client.reviewdb.UserIdentity;
import com.google.gerrit.client.rpc.Common;
+import com.google.gerrit.git.InvalidRepositoryException;
+import com.google.gerrit.server.patch.PatchFile;
import com.google.gwtorm.client.OrmException;
import org.spearce.jgit.lib.PersonIdent;
+import org.spearce.jgit.lib.Repository;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
@@ -44,6 +47,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.mail.Address;
@@ -224,25 +228,64 @@ public class ChangeMail {
}
}
+ Map<Patch.Key, Patch> patches = Collections.emptyMap();
+ Repository repo = null;
+
if (!comments.isEmpty()) {
+ try {
+ final PatchSet.Id psId = patchSet.getId();
+ patches = db.patches().toMap(db.patches().byPatchSet(psId));
+ } catch (OrmException e) {
+ // Can't read the patch table? Don't quote file lines.
+ patches = Collections.emptyMap();
+ }
+ try {
+ repo = server.getRepositoryCache().get(projectName);
+ } catch (InvalidRepositoryException e) {
+ repo = null;
+ patches = Collections.emptyMap();
+ }
+
body.append("Comments on Patch Set ");
body.append(patchSet.getPatchSetId());
body.append(":\n\n");
}
- String priorFile = "";
+ Patch.Key currentFile = null;
+ PatchFile file = null;
for (final PatchLineComment c : comments) {
- final String fn = c.getKey().getParentKey().get();
- if (!fn.equals(priorFile)) {
+ final Patch.Key pk = c.getKey().getParentKey();
+ final int lineNbr = c.getLine();
+ final short side = c.getSide();
+
+ if (!pk.equals(currentFile)) {
body.append("....................................................\n");
body.append("File ");
- body.append(fn);
+ body.append(pk.get());
body.append("\n");
- priorFile = fn;
+ currentFile = pk;
+
+ final Patch p = patches.get(pk);
+ if (p != null && repo != null) {
+ file = new PatchFile(repo, db, p);
+ } else {
+ file = null;
+ }
}
+
body.append("Line ");
- body.append(c.getLine());
+ body.append(lineNbr);
+ if (file != null) {
+ try {
+ final String lineStr = file.getLine(side, lineNbr);
+ body.append(": ");
+ body.append(lineStr);
+ } catch (Throwable cce) {
+ // Don't quote the line if we can't safely convert it.
+ }
+ }
body.append("\n");
+
body.append(c.getMessage().trim());
body.append("\n\n");
}