Skip to content
Snippets Groups Projects
Commit 7c82df11 authored by Shawn Pearce's avatar Shawn Pearce
Browse files

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: default avatarShawn O. Pearce <spearce@spearce.org>
parent 0238a21b
No related branches found
No related tags found
No related merge requests found
/* /*
* 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 void testInvalidTagNoTagHeader3() { ...@@ -868,26 +868,7 @@ public void testInvalidTagNoTagHeader3() {
} }
} }
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 void testInvalidTagNoTaggerHeader1() { ...@@ -897,13 +878,7 @@ public void testInvalidTagNoTaggerHeader1() {
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() {
......
/* /*
* 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 void testParseAllFields() throws Exception { ...@@ -140,6 +140,51 @@ public void testParseAllFields() throws Exception {
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");
......
/* /*
* 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 void checkTag(final byte[] raw) throws CorruptObjectException { ...@@ -217,11 +217,11 @@ public void checkTag(final byte[] raw) throws CorruptObjectException {
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';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment