From 7c82df1114537fe221eeb2d8ac79b3eab9fa7225 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 23 Jan 2010 12:11:38 -0800 Subject: [PATCH] Relax ObjectChecker to permit missing tagger lines Annotated tags created with C Git versions before the introduction of c818566 ([PATCH] Update tags to record who made them, 2005-07-14), do not have a "tagger" line present in the object header. This line did not appear in C Git until v0.99.1~9. Ancient projects such as the Linux kernel contain such tags, for example Linux 2.6.12 is older than when this feature first appeared in C Git. Linux v2.6.13-rc4 in late July 2005 is the first kernel version tag to actually contain a tagger line. It is therefore acceptable for the header to be missing, and for the RevTag.getTaggerIdent() method to return null. Since the Javadoc for getTaggerIdent() already explained that the identity may be null, we just need to test that this is true when the header is missing, and allow the ObjectChecker to pass anyway. Change-Id: I34ba82e0624a0d1a7edcf62ffba72260af6f7e5d See: http://code.google.com/p/gerrit/issues/detail?id=399 Signed-off-by: Shawn O. Pearce --- .../eclipse/jgit/lib/ObjectCheckerTest.java | 31 ++---------- .../eclipse/jgit/revwalk/RevTagParseTest.java | 47 ++++++++++++++++++- .../org/eclipse/jgit/lib/ObjectChecker.java | 10 ++-- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java index 7c2676bc7..2e470b386 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java +++ b/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 * and other copyright owners as documented in the project's IP log. * @@ -868,26 +868,7 @@ public class ObjectCheckerTest extends TestCase { } } - public void testInvalidTagNoTagHeader4() { - 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() { + public void testValidTagHasNoTaggerHeader() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); b.append("object "); @@ -897,13 +878,7 @@ public class ObjectCheckerTest extends TestCase { b.append("type commit\n"); b.append("tag foo\n"); - 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()); - } + checker.checkTag(Constants.encodeASCII(b.toString())); } public void testInvalidTagInvalidTaggerHeader1() { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java index 8800536d2..b3e62f49e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java +++ b/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. * * This program and the accompanying materials are made available @@ -140,6 +140,51 @@ public class RevTagParseTest extends RepositoryTestCase { 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 { final StringBuilder b = new StringBuilder(); b.append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java index 82a8c3825..5906802d1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java +++ b/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 * and other copyright owners as documented in the project's IP log. * @@ -217,10 +217,10 @@ public class ObjectChecker { throw new CorruptObjectException("no tag header"); ptr = nextLF(raw, ptr); - if ((ptr = match(raw, ptr, tagger)) < 0) - throw new CorruptObjectException("no tagger header"); - if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n') - throw new CorruptObjectException("invalid tagger"); + if ((ptr = match(raw, ptr, tagger)) > 0) { + if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n') + throw new CorruptObjectException("invalid tagger"); + } } private static int lastPathChar(final int mode) {