diff options
author | Shawn O. Pearce <sop@google.com> | 2009-06-08 07:04:47 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-06-08 07:04:47 -0700 |
commit | 66eb36819e2d26575a9c8425f7bfabbc5326bb29 (patch) | |
tree | 661e72761f6a1fd94c56482327c13579939dab57 | |
parent | 974daeef21212e0f91c8f2b196b54ab1b9a97ab9 (diff) |
Correctly handle comments after last hunk of patch
If a comment appears after the last hunk of the patch, it won't
match any of the Edit instances in the edit list. Instead we
need to use the last Edit instance's end point to remap the line
number to the other file space.
Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r-- | src/main/java/com/google/gerrit/server/patch/PatchScriptBuilder.java | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/main/java/com/google/gerrit/server/patch/PatchScriptBuilder.java b/src/main/java/com/google/gerrit/server/patch/PatchScriptBuilder.java index 27b57df8c5..e602fcb9ae 100644 --- a/src/main/java/com/google/gerrit/server/patch/PatchScriptBuilder.java +++ b/src/main/java/com/google/gerrit/server/patch/PatchScriptBuilder.java @@ -133,8 +133,7 @@ class PatchScriptBuilder { return new PatchScript(header, context, dstA, dstB, edits); } - private void ensureCommentsVisible(final CommentDetail comments) - throws CorruptEntityException { + private void ensureCommentsVisible(final CommentDetail comments) { if (comments.getCommentsA().isEmpty() && comments.getCommentsB().isEmpty()) { // No comments, no additional dummy edits are required. // @@ -180,7 +179,7 @@ class PatchScriptBuilder { edits = n; } - private int mapA2B(final int a) throws CorruptEntityException { + private int mapA2B(final int a) { if (edits.isEmpty()) { // Magic special case of an unmodified file. // @@ -198,11 +197,12 @@ class PatchScriptBuilder { return e.getBeginB() + (a - e.getBeginA()); } } - log.error("In " + patchKey + " cannot remap A " + a + " to B"); - throw new CorruptEntityException(patchKey); + + final Edit last = edits.get(edits.size() - 1); + return last.getBeginB() + (a - last.getEndA()); } - private int mapB2A(final int b) throws CorruptEntityException { + private int mapB2A(final int b) { if (edits.isEmpty()) { // Magic special case of an unmodified file. // @@ -220,8 +220,9 @@ class PatchScriptBuilder { return e.getBeginA() + (b - e.getBeginB()); } } - log.error("In " + patchKey + " cannot remap B " + b + " to A"); - throw new CorruptEntityException(patchKey); + + final Edit last = edits.get(edits.size() - 1); + return last.getBeginA() + (b - last.getEndB()); } private static boolean eq(final ObjectId a, final ObjectId b) { |