Browse Source

Merge "Relax ObjectChecker to permit missing tagger lines"

stable-0.7
Robin Rosenberg 15 years ago committed by Code Review
parent
commit
94599930e7
  1. 31
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
  2. 47
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
  3. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

31
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008, Google Inc. * Copyright (C) 2008-2010, Google Inc.
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
@ -868,26 +868,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
public void testInvalidTagNoTagHeader4() { public void testValidTagHasNoTaggerHeader() throws CorruptObjectException {
final StringBuilder b = new StringBuilder();
b.append("object ");
b.append("be9bfa841874ccc9f2ef7c48d0c76226f89b7189");
b.append('\n');
b.append("type commit\n");
b.append("tag foo");
final byte[] data = Constants.encodeASCII(b.toString());
try {
checker.checkTag(data);
fail("incorrectly accepted invalid tag");
} catch (CorruptObjectException e) {
assertEquals("no tagger header", e.getMessage());
}
}
public void testInvalidTagNoTaggerHeader1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
b.append("object "); b.append("object ");
@ -897,13 +878,7 @@ public class ObjectCheckerTest extends TestCase {
b.append("type commit\n"); b.append("type commit\n");
b.append("tag foo\n"); b.append("tag foo\n");
final byte[] data = Constants.encodeASCII(b.toString()); checker.checkTag(Constants.encodeASCII(b.toString()));
try {
checker.checkTag(data);
fail("incorrectly accepted invalid tag");
} catch (CorruptObjectException e) {
assertEquals("no tagger header", e.getMessage());
}
} }
public void testInvalidTagInvalidTaggerHeader1() { public void testInvalidTagInvalidTaggerHeader1() {

47
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008-2009, Google Inc. * Copyright (C) 2008-2010, Google Inc.
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
* This program and the accompanying materials are made available * This program and the accompanying materials are made available
@ -140,6 +140,51 @@ public class RevTagParseTest extends RepositoryTestCase {
assertEquals(taggerEmail, cTagger.getEmailAddress()); assertEquals(taggerEmail, cTagger.getEmailAddress());
} }
public void testParseOldStyleNoTagger() throws Exception {
final ObjectId treeId = id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
final String name = "v1.2.3.4.5";
final String message = "test\n" //
+ "\n" //
+ "-----BEGIN PGP SIGNATURE-----\n" //
+ "Version: GnuPG v1.4.1 (GNU/Linux)\n" //
+ "\n" //
+ "iD8DBQBC0b9oF3Y\n" //
+ "-----END PGP SIGNATURE------n";
final StringBuilder body = new StringBuilder();
body.append("object ");
body.append(treeId.name());
body.append("\n");
body.append("type tree\n");
body.append("tag ");
body.append(name);
body.append("\n");
body.append("\n");
body.append(message);
final RevWalk rw = new RevWalk(db);
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
assertNull(c.getObject());
assertNull(c.getTagName());
c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
assertNotNull(c.getTagName());
assertEquals(name, c.getTagName());
assertEquals("test", c.getShortMessage());
assertEquals(message, c.getFullMessage());
assertNull(c.getTaggerIdent());
}
private RevTag create(final String msg) throws Exception { private RevTag create(final String msg) throws Exception {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
b.append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"); b.append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");

6
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008, Google Inc. * Copyright (C) 2008-2010, Google Inc.
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
@ -217,11 +217,11 @@ public class ObjectChecker {
throw new CorruptObjectException("no tag header"); throw new CorruptObjectException("no tag header");
ptr = nextLF(raw, ptr); ptr = nextLF(raw, ptr);
if ((ptr = match(raw, ptr, tagger)) < 0) if ((ptr = match(raw, ptr, tagger)) > 0) {
throw new CorruptObjectException("no tagger header");
if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n') if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid tagger"); throw new CorruptObjectException("invalid tagger");
} }
}
private static int lastPathChar(final int mode) { private static int lastPathChar(final int mode) {
return FileMode.TREE.equals(mode) ? '/' : '\0'; return FileMode.TREE.equals(mode) ? '/' : '\0';

Loading…
Cancel
Save