Tag message must not include the signature
Signatures on tags are just tacked onto the end of the message. Getting the message must not return the signature. Compare [1] and [2] in C git, which both drop a signature at the end of an object body. [1] https://github.com/git/git/blob/21bf933/builtin/tag.c#L173 [2] https://github.com/git/git/blob/21bf933/ref-filter.c#L1276 Change-Id: Ic8a1062b8bc77f2d7c138c3fe8a7fd13b1253f38 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
parent
db48fcedbc
commit
dd3846513b
|
@ -41,6 +41,7 @@
|
|||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
||||
import org.eclipse.jgit.util.RawParseUtils;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
|
@ -219,13 +220,17 @@ private void show(RevTag tag) throws IOException {
|
|||
}
|
||||
|
||||
outw.println();
|
||||
final String[] lines = tag.getFullMessage().split("\n"); //$NON-NLS-1$
|
||||
String[] lines = tag.getFullMessage().split("\n"); //$NON-NLS-1$
|
||||
for (String s : lines) {
|
||||
outw.print(" "); //$NON-NLS-1$
|
||||
outw.print(s);
|
||||
outw.println();
|
||||
outw.println(s);
|
||||
}
|
||||
byte[] rawSignature = tag.getRawGpgSignature();
|
||||
if (rawSignature != null) {
|
||||
lines = RawParseUtils.decode(rawSignature).split("\n"); //$NON-NLS-1$
|
||||
for (String s : lines) {
|
||||
outw.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
outw.println();
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public void testParseOldStyleNoTagger() throws Exception {
|
|||
+ "\n" //
|
||||
+ "iD8DBQBC0b9oF3Y\n" //
|
||||
+ "-----END PGP SIGNATURE-----";
|
||||
final String message = "test\n\n" + fakeSignature + '\n';
|
||||
final String message = "test\n" + fakeSignature + '\n';
|
||||
|
||||
final StringBuilder body = new StringBuilder();
|
||||
|
||||
|
@ -168,7 +168,7 @@ public void testParseOldStyleNoTagger() throws Exception {
|
|||
assertNotNull(c.getTagName());
|
||||
assertEquals(name, c.getTagName());
|
||||
assertEquals("test", c.getShortMessage());
|
||||
assertEquals(message, c.getFullMessage());
|
||||
assertEquals("test\n", c.getFullMessage());
|
||||
assertEquals(fakeSignature + '\n',
|
||||
new String(c.getRawGpgSignature(), US_ASCII));
|
||||
|
||||
|
@ -406,7 +406,7 @@ public void testParse_gpgSignature() throws Exception {
|
|||
b.write("tag v1.0\n".getBytes(UTF_8));
|
||||
b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8));
|
||||
b.write('\n');
|
||||
b.write("message\n\n".getBytes(UTF_8));
|
||||
b.write("message\n".getBytes(UTF_8));
|
||||
b.write(signature.getBytes(US_ASCII));
|
||||
b.write('\n');
|
||||
|
||||
|
@ -417,7 +417,7 @@ public void testParse_gpgSignature() throws Exception {
|
|||
|
||||
assertEquals("t", t.getTaggerIdent().getName());
|
||||
assertEquals("message", t.getShortMessage());
|
||||
assertEquals("message\n\n" + signature + '\n', t.getFullMessage());
|
||||
assertEquals("message\n", t.getFullMessage());
|
||||
String gpgSig = new String(t.getRawGpgSignature(), UTF_8);
|
||||
assertEquals(signature + '\n', gpgSig);
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ public void testParse_gpgSignature2() throws Exception {
|
|||
|
||||
assertEquals("t", t.getTaggerIdent().getName());
|
||||
assertEquals("message", t.getShortMessage());
|
||||
assertEquals(message + signature + '\n', t.getFullMessage());
|
||||
assertEquals(message, t.getFullMessage());
|
||||
String gpgSig = new String(t.getRawGpgSignature(), UTF_8);
|
||||
assertEquals(signature + '\n', gpgSig);
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ public void testParse_gpgSignature3() throws Exception {
|
|||
|
||||
assertEquals("t", t.getTaggerIdent().getName());
|
||||
assertEquals("message", t.getShortMessage());
|
||||
assertEquals(message + signature + '\n', t.getFullMessage());
|
||||
assertEquals(message, t.getFullMessage());
|
||||
String gpgSig = new String(t.getRawGpgSignature(), UTF_8);
|
||||
assertEquals(signature + '\n', gpgSig);
|
||||
}
|
||||
|
|
|
@ -202,6 +202,29 @@ private static int nextStart(byte[] prefix, byte[] buffer, int from) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
private int getSignatureStart() {
|
||||
byte[] raw = buffer;
|
||||
int msgB = RawParseUtils.tagMessage(raw, 0);
|
||||
if (msgB < 0) {
|
||||
return msgB;
|
||||
}
|
||||
// Find the last signature start and return the rest
|
||||
int start = nextStart(hSignature, raw, msgB);
|
||||
if (start < 0) {
|
||||
return start;
|
||||
}
|
||||
int next = RawParseUtils.nextLF(raw, start);
|
||||
while (next < raw.length) {
|
||||
int newStart = nextStart(hSignature, raw, next);
|
||||
if (newStart < 0) {
|
||||
break;
|
||||
}
|
||||
start = newStart;
|
||||
next = RawParseUtils.nextLF(raw, start);
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the GPG signature from the raw buffer.
|
||||
*
|
||||
|
@ -212,24 +235,10 @@ private static int nextStart(byte[] prefix, byte[] buffer, int from) {
|
|||
@Nullable
|
||||
public final byte[] getRawGpgSignature() {
|
||||
byte[] raw = buffer;
|
||||
int msgB = RawParseUtils.tagMessage(raw, 0);
|
||||
if (msgB < 0) {
|
||||
return null;
|
||||
}
|
||||
// Find the last signature start and return the rest
|
||||
int start = nextStart(hSignature, raw, msgB);
|
||||
int start = getSignatureStart();
|
||||
if (start < 0) {
|
||||
return null;
|
||||
}
|
||||
int next = RawParseUtils.nextLF(raw, start);
|
||||
while (next < raw.length) {
|
||||
int newStart = nextStart(hSignature, raw, next);
|
||||
if (newStart < 0) {
|
||||
break;
|
||||
}
|
||||
start = newStart;
|
||||
next = RawParseUtils.nextLF(raw, start);
|
||||
}
|
||||
return Arrays.copyOfRange(raw, start, raw.length);
|
||||
}
|
||||
|
||||
|
@ -249,7 +258,12 @@ public final String getFullMessage() {
|
|||
if (msgB < 0) {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
return RawParseUtils.decode(guessEncoding(), raw, msgB, raw.length);
|
||||
int signatureStart = getSignatureStart();
|
||||
int end = signatureStart < 0 ? raw.length : signatureStart;
|
||||
if (end == msgB) {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
return RawParseUtils.decode(guessEncoding(), raw, msgB, end);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,6 +289,16 @@ public final String getShortMessage() {
|
|||
}
|
||||
|
||||
int msgE = RawParseUtils.endOfParagraph(raw, msgB);
|
||||
int signatureStart = getSignatureStart();
|
||||
if (signatureStart >= msgB && msgE > signatureStart) {
|
||||
msgE = signatureStart;
|
||||
if (msgE > msgB) {
|
||||
msgE--;
|
||||
}
|
||||
if (msgB == msgE) {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
String str = RawParseUtils.decode(guessEncoding(), raw, msgB, msgE);
|
||||
if (RevCommit.hasLF(raw, msgB, msgE)) {
|
||||
str = StringUtils.replaceLineBreaksWithSpace(str);
|
||||
|
|
Loading…
Reference in New Issue