Switch usage of AnyObjectId.toString() to new AnyObjectId.name()
PATCH 1/2 Switch usage of AnyObjectId.toString() to new AnyObjectId.name()
This allows objects that extend AnyObjectId to override toString() to their needs. With this it is possible to subclass for example RevCommit and provide a custom toString() implementation without breaking the revision walker.
AnyObjectId's toString() implementation is changed to make sure that users relying on the old behavior will break. This patch passes the test suite.
--- .../tst/org/spearce/jgit/lib/PackIndexTest.java | 24 ++++++++++---------- .../tst/org/spearce/jgit/lib/PackWriterTest.java | 4 +- .../src/org/spearce/jgit/lib/AnyObjectId.java | 7 +++++- .../src/org/spearce/jgit/lib/ObjectId.java | 4 +- .../src/org/spearce/jgit/lib/RefLogWriter.java | 2 +- .../src/org/spearce/jgit/lib/Repository.java | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java +12 -12
@@ -111,21 +111,21 @@ public void testIteratorMethodsContract() { public void testIteratorReturnedValues1() { Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator(); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter.next() - .toString()); + .name()); assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab", iter.next() - .toString()); + .name()); assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259", iter.next() - .toString()); + .name()); assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3", iter.next() - .toString()); + .name()); assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7", iter.next() - .toString()); + .name()); assertEquals("902d5476fa249b7abc9d84c611577a81381f0327", iter.next() - .toString()); + .name()); assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035", iter.next() - .toString()); + .name()); assertEquals("c59759f143fb1fe21c197981df75a7ee00290799", iter.next() - .toString()); + .name()); assertFalse(iter.hasNext()); }
@@ -147,16 +147,16 @@ public void testCompareEntriesOffsetsWithFindOffsets() { */ public void testIteratorReturnedValues2() { Iterator<PackIndex.MutableEntry> iter = denseIdx.iterator(); - while (!iter.next().toString().equals( + while (!iter.next().name().equals( "0a3d7772488b6b106fb62813c4d6d627918d9181")) { // just iterating } assertEquals("1004d0d7ac26fbf63050a234c9b88a46075719d3", iter.next() - .toString()); // same level-1 + .name()); // same level-1 assertEquals("10da5895682013006950e7da534b705252b03be6", iter.next() - .toString()); // same level-1 + .name()); // same level-1 assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8", iter.next() - .toString()); + .name()); } }
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java +2 -2
@@ -125,7 +125,7 @@ public void testWriteEmptyPack1() throws IOException { assertEquals(0, writer.getObjectsNumber()); assertEquals(0, pack.getObjectCount()); assertEquals("da39a3ee5e6b4b0d3255bfef95601890afd80709", writer - .computeName().toString()); + .computeName().name()); } /**
@@ -273,7 +273,7 @@ public void testWritePack3() throws MissingObjectException, IOException { assertEquals(forcedOrder.length, writer.getObjectsNumber()); verifyObjectsOrder(forcedOrder); assertEquals("ed3f96b8327c7c66b0f8f70056129f0769323d86", writer - .computeName().toString()); + .computeName().name()); } /**
org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java +6 -1
@@ -406,7 +406,12 @@ private static void formatHexChar(final char[] dst, final int p, int w) { dst[o--] = '0'; } + @Override public String toString() { + return "AnyObjectId[" + name() + "]"; + } + + public String name() { return new String(toHexCharArray()); }
@@ -422,7 +427,7 @@ public String toString() { */ public String abbreviate(final Repository repo) { // TODO implement checking for uniqueness - return toString().substring(0, 7); + return name().substring(0, 7); } /**
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java +2 -2
@@ -52,7 +52,7 @@ static { ZEROID = new ObjectId(0, 0, 0, 0, 0); - ZEROID_STR = ZEROID.toString(); + ZEROID_STR = ZEROID.name(); } /**
@@ -94,7 +94,7 @@ public static final boolean isId(final String id) { * @return the hex string conversion of this id's content. */ public static final String toString(final ObjectId i) { - return i != null ? i.toString() : ZEROID_STR; + return i != null ? i.name() : ZEROID_STR; } /**
org.spearce.jgit/src/org/spearce/jgit/lib/RefLogWriter.java +1 -1
@@ -88,7 +88,7 @@ private static String buildReflogString(Repository repo, oldCommit = ObjectId.zeroId(); initial = " (initial)"; } - String s = oldCommit.toString() + " " + commit.toString() + " " + String s = oldCommit.name() + " " + commit.name() + " " + me.toExternalString() + "\t" + message + initial; return s; }
org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +1 -1
@@ -209,7 +209,7 @@ public RepositoryConfig getConfig() { * @return suggested file name */ public File toFile(final AnyObjectId objectId) { - final String n = objectId.toString(); + final String n = objectId.name(); String d=n.substring(0, 2); String f=n.substring(2); for (int i=0; i<objectsDirs.length; ++i) {
Signature · 3 lines
1.6.0.336.ga07ba -- Jonas Fonseca
Quoted 9 lines · Jonas Fonseca
This allows objects that extend AnyObjectId to override
toString()to their needs. With this it is possible to subclass for example RevCommit and provide a customtoString()implementation without breaking the revision walker.AnyObjectId's
toString()implementation is changed to make sure that users relying on the old behavior will break. This patch passes the test suite.
Quoted 8 lines
--- .../tst/org/spearce/jgit/lib/PackIndexTest.java | 24 ++++++++++---------- .../tst/org/spearce/jgit/lib/PackWriterTest.java | 4 +- .../src/org/spearce/jgit/lib/AnyObjectId.java | 7 +++++- .../src/org/spearce/jgit/lib/ObjectId.java | 4 +- .../src/org/spearce/jgit/lib/RefLogWriter.java | 2 +- .../src/org/spearce/jgit/lib/Repository.java | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-)
Hmm. I had to squash this into it just to fix most of the code and make it pass tests, let alone fix the fetch and push implementations. Most of the library plain up and broke with this toString change.
Missing T0001_ObjectId suggests to me that your method of running the tests isn't working right.
And this is only JGit. I haven't even started to look into EGit. Though I don't expect you to fix EGit since you are working on NetBeans. :-)
.../src/org/spearce/jgit/pgm/DiffTree.java | 2 +- .../src/org/spearce/jgit/pgm/LsRemote.java | 2 +- .../src/org/spearce/jgit/pgm/LsTree.java | 2 +- .../src/org/spearce/jgit/pgm/MergeBase.java | 2 +- .../src/org/spearce/jgit/pgm/ShowRef.java | 2 +- .../org/spearce/jgit/pgm/debug/ShowDirCache.java | 2 +- .../tst/org/spearce/jgit/lib/PackWriterTest.java | 6 +- .../tst/org/spearce/jgit/lib/T0001_ObjectId.java | 4 +- .../tst/org/spearce/jgit/lib/T0003_Basic.java | 36 ++++++------ .../tst/org/spearce/jgit/lib/T0007_Index.java | 6 +- .../org/spearce/jgit/lib/T0008_testparserev.java | 64 ++++++++++---------- .../spearce/jgit/revwalk/RevCommitParseTest.java | 2 +- .../jgit/errors/CorruptObjectException.java | 2 +- .../jgit/errors/IncorrectObjectTypeException.java | 2 +- .../jgit/errors/MissingObjectException.java | 2 +- .../src/org/spearce/jgit/lib/AnyObjectId.java | 5 +- .../src/org/spearce/jgit/lib/Commit.java | 2 +- .../src/org/spearce/jgit/lib/GitIndex.java | 2 +- org.spearce.jgit/src/org/spearce/jgit/lib/Ref.java | 2 +- .../src/org/spearce/jgit/revwalk/DateRevQueue.java | 2 +- .../src/org/spearce/jgit/revwalk/FIFORevQueue.java | 2 +- .../src/org/spearce/jgit/revwalk/LIFORevQueue.java | 2 +- .../spearce/jgit/revwalk/MergeBaseGenerator.java | 2 +- .../src/org/spearce/jgit/revwalk/ObjectWalk.java | 4 +- .../jgit/transport/BasePackFetchConnection.java | 4 +- .../jgit/transport/BasePackPushConnection.java | 4 +- .../spearce/jgit/transport/FetchHeadRecord.java | 2 +- .../src/org/spearce/jgit/transport/IndexPack.java | 2 +- .../jgit/transport/WalkFetchConnection.java | 38 ++++++------ .../spearce/jgit/transport/WalkPushConnection.java | 2 +- 30 files changed, 107 insertions(+), 104 deletions(-)
org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/DiffTree.java +1 -1
@@ -87,7 +87,7 @@ protected void run() throws Exception { } for (int i = 0; i < nTree; i++) { - out.print(walk.getObjectId(i)); + out.print(walk.getObjectId(i).name()); out.print(' '); }
org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsRemote.java +1 -1
@@ -64,7 +64,7 @@ protected void run() throws Exception { } private void show(final AnyObjectId id, final String name) { - out.print(id); + out.print(id.name()); out.print('\t'); out.print(name); out.println();
org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java +1 -1
@@ -67,7 +67,7 @@ protected void run() throws Exception { out.print(Constants.typeString(mode.getObjectType())); out.print(' '); - out.print(walk.getObjectId(0)); + out.print(walk.getObjectId(0).name()); out.print('\t'); out.print(walk.getPathString());
org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/MergeBase.java +1 -1
@@ -67,7 +67,7 @@ protected void run() throws Exception { final RevCommit b = argWalk.next(); if (b == null) break; - out.println(b.getId()); + out.println(b.getId().name()); } } }
org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/ShowRef.java +1 -1
@@ -53,7 +53,7 @@ protected void run() throws Exception { } private void show(final AnyObjectId id, final String name) { - out.print(id); + out.print(id.name()); out.print('\t'); out.print(name); out.println();
org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/debug/ShowDirCache.java +1 -1
@@ -63,7 +63,7 @@ protected void run() throws Exception { out.print(' '); out.print(fmt.format(mtime)); out.print(' '); - out.print(ent.getObjectId()); + out.print(ent.getObjectId().name()); out.print('\t'); out.print(ent.getPathString()); out.println();
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java +3 -3
@@ -372,7 +372,7 @@ private void writeVerifyPack1() throws IOException { assertEquals(expectedOrder.length, writer.getObjectsNumber()); verifyObjectsOrder(expectedOrder); assertEquals("34be9032ac282b11fa9babdc2b2a93ca996c9c2f", writer - .computeName().toString()); + .computeName().name()); } private void writeVerifyPack2(boolean deltaReuse) throws IOException {
@@ -401,7 +401,7 @@ private void writeVerifyPack2(boolean deltaReuse) throws IOException { assertEquals(expectedOrder.length, writer.getObjectsNumber()); verifyObjectsOrder(expectedOrder); assertEquals("ed3f96b8327c7c66b0f8f70056129f0769323d86", writer - .computeName().toString()); + .computeName().name()); } private void writeVerifyPack4(final boolean thin) throws IOException {
@@ -431,7 +431,7 @@ private void writeVerifyPack4(final boolean thin) throws IOException { } verifyObjectsOrder(expectedObjects); assertEquals("cded4b74176b4456afa456768b2b5aafb41c44fc", writer - .computeName().toString()); + .computeName().name()); } private void createVerifyOpenPack(final Collection<ObjectId> interestings,
org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0001_ObjectId.java +2 -2
@@ -43,13 +43,13 @@ public void test001_toString() { final String x = "def4c620bc3713bb1bb26b808ec9312548e73946"; final ObjectId oid = ObjectId.fromString(x); - assertEquals(x, oid.toString()); + assertEquals(x, oid.name()); } public void test002_toString() { final String x = "ff00eedd003713bb1bb26b808ec9312548e73946"; final ObjectId oid = ObjectId.fromString(x); - assertEquals(x, oid.toString()); + assertEquals(x, oid.name()); } public void test003_equals() {
org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0003_Basic.java +18 -18
@@ -80,7 +80,7 @@ public void test002_WriteEmptyTree() throws IOException { final Tree t = new Tree(db); t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId() - .toString()); + .name()); final File o = new File(new File(new File(trash_git, "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904"); assertTrue("Exists " + o, o.isFile());
@@ -93,7 +93,7 @@ public void test002_WriteEmptyTree2() throws IOException { final Tree t = new Tree(db); t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId() - .toString()); + .name()); final File o = new File(new File(new File(trash_git, "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904"); assertFalse("Exists " + o, o.isFile());
@@ -105,7 +105,7 @@ public void test003_WriteShouldBeEmptyTree() throws IOException { t.addFile("should-be-empty").setId(emptyId); t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); assertEquals("7bb943559a305bdd6bdee2cef6e5df2413c3d30a", t.getId() - .toString()); + .name()); File o; o = new File(new File(new File(trash_git, "objects"), "7b"),
@@ -264,13 +264,13 @@ public void test020_createBlobTag() throws IOException { t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); t.setMessage("test020 tagged\n"); t.tag(); - assertEquals("6759556b09fbb4fd8ae5e315134481cc25d46954", t.getTagId().toString()); + assertEquals("6759556b09fbb4fd8ae5e315134481cc25d46954", t.getTagId().name()); Tag mapTag = db.mapTag("test020"); assertEquals("blob", mapTag.getType()); assertEquals("test020 tagged\n", mapTag.getMessage()); assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); - assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().toString()); + assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().name()); } public void test020b_createBlobPlainTag() throws IOException {
@@ -281,7 +281,7 @@ public void test020b_createBlobPlainTag() throws IOException { t.tag(); Tag mapTag = db.mapTag("test020b"); - assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().toString()); + assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().name()); // We do not repeat the plain tag test for other object types }
@@ -298,13 +298,13 @@ public void test021_createTreeTag() throws IOException { t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); t.setMessage("test021 tagged\n"); t.tag(); - assertEquals("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.getTagId().toString()); + assertEquals("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.getTagId().name()); Tag mapTag = db.mapTag("test021"); assertEquals("tree", mapTag.getType()); assertEquals("test021 tagged\n", mapTag.getMessage()); assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); - assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag.getObjId().toString()); + assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag.getObjId().name()); } public void test022_createCommitTag() throws IOException {
@@ -325,13 +325,13 @@ public void test022_createCommitTag() throws IOException { t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); t.setMessage("test022 tagged\n"); t.tag(); - assertEquals("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.getTagId().toString()); + assertEquals("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.getTagId().name()); Tag mapTag = db.mapTag("test022"); assertEquals("commit", mapTag.getType()); assertEquals("test022 tagged\n", mapTag.getMessage()); assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); - assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.getObjId().toString()); + assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.getObjId().name()); } public void test023_createCommitNonAnullii() throws IOException {
@@ -346,7 +346,7 @@ public void test023_createCommitNonAnullii() throws IOException { commit.setEncoding("UTF-8"); commit.setMessage("\u00dcbergeeks"); ObjectId cid = new ObjectWriter(db).writeCommit(commit); - assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.toString()); + assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name()); } public void test024_createCommitNonAscii() throws IOException {
@@ -361,7 +361,7 @@ public void test024_createCommitNonAscii() throws IOException { commit.setEncoding("ISO-8859-1"); commit.setMessage("\u00dcbergeeks"); ObjectId cid = new ObjectWriter(db).writeCommit(commit); - assertEquals("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.toString()); + assertEquals("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.name()); } public void test025_packedRefs() throws IOException {
@@ -393,19 +393,19 @@ public void test025_packedRefs() throws IOException { assertEquals("blob", mapTag20.getType()); assertEquals("test020 tagged\n", mapTag20.getMessage()); assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag20.getAuthor()); - assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag20.getObjId().toString()); + assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag20.getObjId().name()); Tag mapTag21 = db.mapTag("test021"); assertEquals("tree", mapTag21.getType()); assertEquals("test021 tagged\n", mapTag21.getMessage()); assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag21.getAuthor()); - assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag21.getObjId().toString()); + assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag21.getObjId().name()); Tag mapTag22 = db.mapTag("test022"); assertEquals("commit", mapTag22.getType()); assertEquals("test022 tagged\n", mapTag22.getMessage()); assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag22.getAuthor()); - assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag22.getObjId().toString()); + assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag22.getObjId().name()); } public void test025_computeSha1NoStore() throws IOException {
@@ -414,7 +414,7 @@ public void test025_computeSha1NoStore() throws IOException { // TODO: but we do not test legacy header writing final ObjectId id = new ObjectWriter(db).computeBlobSha1(data.length, new ByteArrayInputStream(data)); - assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.toString()); + assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name()); } public void test026_CreateCommitMultipleparents() throws IOException {
@@ -512,7 +512,7 @@ public void test027_UnpackedRefHigherPriorityThanPacked() throws IOException { writer.close(); ObjectId resolved = db.resolve("refs/heads/a"); - assertEquals(unpackedId, resolved.toString()); + assertEquals(unpackedId, resolved.name()); } public void test028_LockPackedRef() throws IOException {
@@ -520,7 +520,7 @@ public void test028_LockPackedRef() throws IOException { writeTrashFile(".git/HEAD", "ref: refs/heads/foobar\n"); ObjectId resolve = db.resolve("HEAD"); - assertEquals("7f822839a2fe9760f386cbbbcb3f92c5fe81def7", resolve.toString()); + assertEquals("7f822839a2fe9760f386cbbbcb3f92c5fe81def7", resolve.name()); RefUpdate lockRef = db.updateRef("HEAD"); ObjectId newId = ObjectId.fromString("07f822839a2fe9760f386cbbbcb3f92c5fe81def");
org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java +3 -3
@@ -171,7 +171,7 @@ public void testWriteTree() throws Exception { index.write(); ObjectId id = index.writeTree(); - assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.toString()); + assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); writeTrashFile("a/b", "data:a/b"); index.add(trash, new File(trash, "a/b"));
@@ -193,7 +193,7 @@ public void testReadTree() throws Exception { ObjectId id = index.writeTree(); System.out.println("wrote id " + id); - assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.toString()); + assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); GitIndex index2 = new GitIndex(db); index2.readTree(db.mapTree(ObjectId.fromString(
@@ -236,7 +236,7 @@ public void testReadTree2() throws Exception { index.write(); ObjectId id = index.writeTree(); System.out.println("wrote id " + id); - assertEquals("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.toString()); + assertEquals("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.name()); GitIndex index2 = new GitIndex(db); index2.readTree(db.mapTree(ObjectId.fromString(
org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java +32 -32
107 lines not on this page · raw message
org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/RevCommitParseTest.java +1 -1
@@ -54,7 +54,7 @@ public void testParse_NoParents() throws Exception { final StringBuilder body = new StringBuilder(); body.append("tree "); - body.append(treeId); + body.append(treeId.name()); body.append("\n"); body.append("author ");
org.spearce.jgit/src/org/spearce/jgit/errors/CorruptObjectException.java +1 -1
@@ -56,7 +56,7 @@ * @param why */ public CorruptObjectException(final ObjectId id, final String why) { - super("Object " + id + " is corrupt: " + why); + super("Object " + id.name() + " is corrupt: " + why); } /**
org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java +1 -1
@@ -60,6 +60,6 @@ * @param type object type */ public IncorrectObjectTypeException(final ObjectId id, final String type) { - super("Object " + id + " is not a " + type + "."); + super("Object " + id.name() + " is not a " + type + "."); } }
org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java +1 -1
@@ -56,6 +56,6 @@ * @param type object type */ public MissingObjectException(final ObjectId id, final String type) { - super("Missing " + type + " " + id); + super("Missing " + type + " " + id.name()); } }
org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java +4 -1
@@ -411,7 +411,10 @@ public String toString() { return "AnyObjectId[" + name() + "]"; } - public String name() { + /** + * @return string form of the SHA-1, in lower case hexadecimal. + */ + public final String name() { return new String(toHexCharArray()); }
org.spearce.jgit/src/org/spearce/jgit/lib/Commit.java +1 -1
@@ -332,7 +332,7 @@ public void commit() throws IOException { } public String toString() { - return "Commit[" + getCommitId() + " " + getAuthor() + "]"; + return "Commit[" + ObjectId.toString(getCommitId()) + " " + getAuthor() + "]"; } /**
org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java +1 -1
@@ -580,7 +580,7 @@ private File getFile(File wd) { } public String toString() { - return new String(name) + "/SHA-1(" + sha1 + ")/M:" + return new String(name) + "/SHA-1(" + sha1.name() + ")/M:" + new Date(ctime / 1000000L) + "/C:" + new Date(mtime / 1000000L) + "/d" + dev + "/i" + ino + "/m" + Integer.toString(mode, 8) + "/u" + uid + "/g"
org.spearce.jgit/src/org/spearce/jgit/lib/Ref.java +1 -1
@@ -200,6 +200,6 @@ public Storage getStorage() { } public String toString() { - return "Ref[" + name + "=" + getObjectId() + "]"; + return "Ref[" + name + "=" + ObjectId.toString(getObjectId()) + "]"; } }
org.spearce.jgit/src/org/spearce/jgit/revwalk/DateRevQueue.java +1 -1
@@ -128,7 +128,7 @@ int outputType() { public String toString() { final StringBuffer s = new StringBuffer(); for (Entry q = head; q != null; q = q.next) { - s.append(q.commit); + s.append(q.commit.name()); s.append(' '); s.append(q.commit.commitTime); s.append('\n');
org.spearce.jgit/src/org/spearce/jgit/revwalk/FIFORevQueue.java +1 -1
@@ -152,7 +152,7 @@ public String toString() { final StringBuffer s = new StringBuffer(); for (Block q = head; q != null; q = q.next) { for (int i = q.headIndex; i < q.tailIndex; i++) { - s.append(q.commits[i]); + s.append(q.commits[i].name()); s.append(' '); s.append(q.commits[i].commitTime); s.append('\n');
org.spearce.jgit/src/org/spearce/jgit/revwalk/LIFORevQueue.java +1 -1
@@ -107,7 +107,7 @@ public String toString() { final StringBuffer s = new StringBuffer(); for (Block q = head; q != null; q = q.next) { for (int i = q.headIndex; i < q.tailIndex; i++) { - s.append(q.commits[i]); + s.append(q.commits[i].name()); s.append(' '); s.append(q.commits[i].commitTime); s.append('\n');
org.spearce.jgit/src/org/spearce/jgit/revwalk/MergeBaseGenerator.java +1 -1
@@ -102,7 +102,7 @@ private void add(final RevCommit c) { // commit admitted to the initial queue only once. If // we see this marks aren't correctly erased. // - throw new IllegalStateException("Stale RevFlags found on " + c); + throw new IllegalStateException("Stale RevFlags on " + c.name()); } c.flags |= flag; pending.add(c);
org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java +2 -2
@@ -277,7 +277,7 @@ public RevObject nextObject() throws MissingObjectException, if (FileMode.GITLINK.equals(mode)) continue; throw new CorruptObjectException("Invalid mode " + mode - + " for " + treeWalk.getObjectId(0) + " " + + " for " + treeWalk.getObjectId(0).name() + " " + treeWalk.getPathString() + " in " + currentTree + "."); } }
@@ -407,7 +407,7 @@ private void markTreeUninteresting(final RevTree tree) if (FileMode.GITLINK.equals(mode)) continue; throw new CorruptObjectException("Invalid mode " + mode - + " for " + treeWalk.getObjectId(0) + " " + + " for " + treeWalk.getObjectId(0).name() + " " + treeWalk.getPathString() + " in " + tree + "."); } }
org.spearce.jgit/src/org/spearce/jgit/transport/BasePackFetchConnection.java +2 -2
@@ -244,7 +244,7 @@ private boolean sendWants(final Collection<Ref> want) throws IOException { final StringBuilder line = new StringBuilder(46); line.append("want "); - line.append(r.getObjectId()); + line.append(r.getObjectId().name()); if (first) { line.append(enableCapabilities()); first = false;
@@ -288,7 +288,7 @@ private void negotiate(final ProgressMonitor monitor) throws IOException, if (c == null) break; - pckOut.writeString("have " + c.getId() + "\n"); + pckOut.writeString("have " + c.getId().name() + "\n"); havesSent++; havesSinceLastContinue++;
org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java +2 -2
@@ -154,9 +154,9 @@ private void writeCommands(final Collection<RemoteRefUpdate> refUpdates, final Ref advertisedRef = getRef(rru.getRemoteName()); final ObjectId oldId = (advertisedRef == null ? ObjectId.zeroId() : advertisedRef.getObjectId()); - sb.append(oldId); + sb.append(oldId.name()); sb.append(' '); - sb.append(rru.getNewObjectId()); + sb.append(rru.getNewObjectId().name()); sb.append(' '); sb.append(rru.getRemoteName()); if (!sentCommand) {
org.spearce.jgit/src/org/spearce/jgit/transport/FetchHeadRecord.java +1 -1
@@ -71,7 +71,7 @@ void write(final PrintWriter pw) { name = sourceName; } - pw.print(newValue); + pw.print(newValue.name()); pw.print('\t'); if (notForMerge) pw.print("not-for-merge");
org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java +1 -1
@@ -842,7 +842,7 @@ public void renameAndOpenPack() throws IOException { d.update(oeBytes); } - final ObjectId name = ObjectId.fromRaw(d.digest()); + final String name = ObjectId.fromRaw(d.digest()).name(); final File packDir = new File(repo.getObjectsDirectory(), "pack"); final File finalPack = new File(packDir, "pack-" + name + ".pack"); final File finalIdx = new File(packDir, "pack-" + name + ".idx");
org.spearce.jgit/src/org/spearce/jgit/transport/WalkFetchConnection.java +19 -19
@@ -224,7 +224,7 @@ private void queueWants(final Collection<Ref> want) if (inWorkQueue.add(id)) workQueue.add(id); } catch (IOException e) { - throw new TransportException("Object read error " + id + ".", e); + throw new TransportException("Cannot read " + id.name(), e); } } }
@@ -243,7 +243,7 @@ private void process(final ObjectId id) throws TransportException { return; } } catch (IOException e) { - throw new TransportException("Object read error " + id + ".", e); + throw new TransportException("Cannot read " + id.name(), e); } // We only care about traversal; disposing an object throws its
@@ -266,7 +266,7 @@ private void process(final ObjectId id) throws TransportException { processTag(obj); break; default: - throw new TransportException("Unknown object type " + obj.getId()); + throw new TransportException("Unknown object type " + id.name()); } // If we had any prior errors fetching this object they are
@@ -277,7 +277,7 @@ private void process(final ObjectId id) throws TransportException { private void processBlob(final RevObject obj) throws TransportException { if (!local.hasObject(obj)) - throw new TransportException("Cannot read blob " + obj, + throw new TransportException("Cannot read blob " + obj.name(), new MissingObjectException(obj, Constants.TYPE_BLOB)); obj.add(COMPLETE); }
@@ -300,13 +300,13 @@ private void processTree(final RevObject obj) throws TransportException { if (FileMode.GITLINK.equals(mode)) continue; throw new CorruptObjectException("Invalid mode " + mode - + " for " + treeWalk.getObjectId(0) + " " - + treeWalk.getPathString() + " in " + obj.getId() - + "."); + + " for " + treeWalk.getObjectId(0).name() + " " + + treeWalk.getPathString() + " in " + + obj.getId().name() + "."); } } } catch (IOException ioe) { - throw new TransportException("Cannot read tree " + obj, ioe); + throw new TransportException("Cannot read tree " + obj.name(), ioe); } obj.add(COMPLETE); }
@@ -351,7 +351,7 @@ private void downloadObject(final ProgressMonitor pm, final AnyObjectId id) // Search for a loose object over all alternates, starting // from the one we last successfully located an object through. // - final String idStr = id.toString(); + final String idStr = id.name(); final String subdir = idStr.substring(0, 2); final String file = idStr.substring(2); final String looseName = subdir + "/" + file;
@@ -413,7 +413,7 @@ private void downloadObject(final ProgressMonitor pm, final AnyObjectId id) List<Throwable> failures = fetchErrors.get(id.copy()); final TransportException te; - te = new TransportException("Cannot get " + id + "."); + te = new TransportException("Cannot get " + id.name() + "."); if (failures != null && !failures.isEmpty()) { if (failures.size() == 1) te.initCause(failures.get(0));
@@ -489,7 +489,7 @@ private boolean downloadPackedObject(final ProgressMonitor monitor, // the object, but after indexing we didn't // actually find it in the pack. // - recordError(id, new FileNotFoundException("Object " + id + recordError(id, new FileNotFoundException("Object " + id.name() + " not found in " + pack.packName + ".")); continue; }
@@ -533,7 +533,7 @@ private boolean downloadLooseObject(final AnyObjectId id, recordError(id, e); return false; } catch (IOException e) { - throw new TransportException("Cannot download " + id + ".", e); + throw new TransportException("Cannot download " + id.name(), e); } }
@@ -555,15 +555,15 @@ private void verifyLooseObject(final AnyObjectId id, final byte[] compressed) // source. // final FileNotFoundException e; - e = new FileNotFoundException(id.toString()); + e = new FileNotFoundException(id.name()); e.initCause(parsingError); throw e; } if (!AnyObjectId.equals(id, uol.getId())) - throw new TransportException("Incorrect hash for " + id - + "; computed " + uol.getId() + " as a " + uol.getType() - + " from " + compressed.length + " bytes."); + throw new TransportException("Incorrect hash for " + id.name() + + "; computed " + uol.getId().name() + " as a " + + uol.getType() + " from " + compressed.length + " bytes."); } private void saveLooseObject(final AnyObjectId id, final byte[] compressed)
@@ -599,7 +599,7 @@ private void saveLooseObject(final AnyObjectId id, final byte[] compressed) tmp.delete(); if (local.hasObject(id)) return; - throw new ObjectWritingException("Unable to store " + id + "."); + throw new ObjectWritingException("Unable to store " + id.name() + "."); } private Collection<WalkRemoteObjectDatabase> expandOneAlternate(
@@ -713,8 +713,8 @@ private void markTreeComplete(final RevTree tree) throws IOException { if (FileMode.GITLINK.equals(mode)) continue; throw new CorruptObjectException("Invalid mode " + mode - + " for " + treeWalk.getObjectId(0) + " " - + treeWalk.getPathString() + " in " + tree + "."); + + " for " + treeWalk.getObjectId(0).name() + " " + + treeWalk.getPathString() + " in " + tree.name() + "."); } } }
org.spearce.jgit/src/org/spearce/jgit/transport/WalkPushConnection.java +1 -1
@@ -223,7 +223,7 @@ private void sendpack(final List<RemoteRefUpdate> updates, for (final String n : dest.getPackNames()) packNames.put(n, n); - final String base = "pack-" + pw.computeName(); + final String base = "pack-" + pw.computeName().name(); final String packName = base + ".pack"; pathPack = "pack/" + packName; pathIdx = "pack/" + base + ".idx";
Signature · 1 line
Shawn.
PATCH 3/4 Switch usage of AnyObjectId.toString() to new AnyObjectId.name() in Eclipse plugin
--- .../core/internal/storage/CommitFileRevision.java | 2 +- .../actions/HardResetToRevisionAction.java | 6 ++++-- .../actions/MixedResetToRevisionAction.java | 6 ++++-- .../actions/SetQuickdiffBaselineAction.java | 2 +- .../actions/SoftResetToRevisionAction.java | 6 ++++-- .../egit/ui/internal/components/RefSpecPanel.java | 2 +- .../egit/ui/internal/history/CommitGraphTable.java | 2 +- .../ui/internal/history/CommitMessageViewer.java | 4 ++-- .../ui/internal/history/FindToolbarThread.java | 2 +- 9 files changed, 19 insertions(+), 13 deletions(-)
org.spearce.egit.core/src/org/spearce/egit/core/internal/storage/CommitFileRevision.java +1 -1
@@ -76,7 +76,7 @@ public long getTimestamp() { } public String getContentIdentifier() { - return commit.getId().toString(); + return commit.getId().name(); } public String getAuthor() {
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/HardResetToRevisionAction.java +4 -2
@@ -12,6 +12,7 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.jface.action.IAction; import org.spearce.egit.core.op.ResetOperation; +import org.spearce.jgit.lib.AnyObjectId; /** * Hard reset to selected revision
@@ -20,7 +21,8 @@ @Override protected IWorkspaceRunnable createOperation(IAction act, List selection) { - return new ResetOperation(getActiveRepository(), selection.get(0) - .toString(), ResetOperation.ResetType.HARD); + return new ResetOperation(getActiveRepository(), + ((AnyObjectId) selection.get(0)).name(), + ResetOperation.ResetType.HARD); } }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/MixedResetToRevisionAction.java +4 -2
@@ -12,6 +12,7 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.jface.action.IAction; import org.spearce.egit.core.op.ResetOperation; +import org.spearce.jgit.lib.AnyObjectId; /** * Mixed reset to selected revision
@@ -20,7 +21,8 @@ @Override protected IWorkspaceRunnable createOperation(IAction act, List selection) { - return new ResetOperation(getActiveRepository(), selection.get(0) - .toString(), ResetOperation.ResetType.MIXED); + return new ResetOperation(getActiveRepository(), + ((AnyObjectId) selection.get(0)).name(), + ResetOperation.ResetType.MIXED); } }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/SetQuickdiffBaselineAction.java +1 -1
@@ -20,7 +20,7 @@ @Override protected IWorkspaceRunnable createOperation(IAction act, List selection) { - return new QuickdiffBaselineOperation(getActiveRepository(), ((RevObject)selection.get(0)).getId().toString()); + return new QuickdiffBaselineOperation(getActiveRepository(), ((RevObject)selection.get(0)).getId().name()); } }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/SoftResetToRevisionAction.java +4 -2
@@ -12,6 +12,7 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.jface.action.IAction; import org.spearce.egit.core.op.ResetOperation; +import org.spearce.jgit.lib.AnyObjectId; /** * Soft reset to selected revision
@@ -20,7 +21,8 @@ @Override protected IWorkspaceRunnable createOperation(IAction act, List selection) { - return new ResetOperation(getActiveRepository(), selection.get(0) - .toString(), ResetOperation.ResetType.SOFT); + return new ResetOperation(getActiveRepository(), + ((AnyObjectId) selection.get(0)).name(), + ResetOperation.ResetType.SOFT); } }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/components/RefSpecPanel.java +1 -1
@@ -1095,7 +1095,7 @@ protected Object getValue(final Object element) { @Override protected void setValue(final Object element, final Object value) { if (value == null || ((String) value).length() == 0 - || ObjectId.zeroId().toString().equals(value)) { + || ObjectId.zeroId().name().equals(value)) { // Ignore empty strings or null objects - do not set them in // model.User won't loose any information if we just fall // back to the old value.
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/CommitGraphTable.java +1 -1
@@ -146,7 +146,7 @@ void doCopy() { final PlotCommit d = itr.next(); if (r.length() > 0) r.append("\n"); - r.append(d.getId().toString()); + r.append(d.getId().name()); } clipboard.setContents(new Object[] { r.toString() },
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/CommitMessageViewer.java +2 -2
@@ -130,7 +130,7 @@ private void format() { final ArrayList<StyleRange> styles = new ArrayList<StyleRange>(); d.append("commit "); - d.append(commit.getId()); + d.append(commit.getId().name()); d.append("\n"); if (author != null) {
@@ -221,7 +221,7 @@ private void addLink(final StringBuilder d, sr.foreground = sys_linkColor; sr.underline = true; sr.start = d.length(); - d.append(to.getId().toString()); + d.append(to.getId().name()); sr.length = d.length() - sr.start; styles.add(sr); }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/FindToolbarThread.java +1 -1
@@ -115,7 +115,7 @@ public void run() { SWTCommit revision = fileRevisions[i]; if (findInCommitId) { - String contentId = revision.getId().toString(); + String contentId = revision.getId().name(); if (contentId != null) { if (ignoreCase) { contentId = contentId.toLowerCase();
Signature · 1 line
1.6.0.1.161.g7f314
PATCH 4/4 Switch usage of AnyObjectId.toString() to new AnyObjectId.name()
Two more places
--- .../spearce/jgit/lib/T0005_ShallowSpeedTest.java | 2 +- .../org/spearce/jgit/lib/T0006_DeepSpeedTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
org.spearce.jgit.test/exttst/org/spearce/jgit/lib/T0005_ShallowSpeedTest.java +1 -1
@@ -60,7 +60,7 @@ public void testShallowHistoryScan() throws IOException { break; ObjectId parentId = parents[0]; commit = db.mapCommit(parentId); - commit.getCommitId().toString(); + commit.getCommitId().name(); ++n; } assertEquals(12275, n);
org.spearce.jgit.test/exttst/org/spearce/jgit/lib/T0006_DeepSpeedTest.java +1 -1
@@ -62,7 +62,7 @@ public void testDeepHistoryScan() throws IOException { commit = db.mapCommit(parentId); TreeEntry m = commit.getTree().findBlobMember("net/netfilter/nf_queue.c"); if (m != null) - commit.getCommitId().toString(); + commit.getCommitId().name(); ++n; }
Signature · 1 line
1.6.0.1.161.g7f314
The order of the patches should be Add name to AnyObjectId
Switch usage.. in jgit
Switch usage.. in egit
Change toString to the new behaviour
-- robin
Quoted 6 lines · Robin Rosenberg
The order of the patches should be Add name to AnyObjectId
Switch usage.. in jgit
Switch usage.. in egit
Change toString to the new behaviour
Yup. I'll take care of it. I'll split the toString change out of the first hunk and toss it into a final patch at the end of the series.
Signature · 1 line
Shawn.
Shawn O. Pearce <[email protected]> wrote Wed, Sep 03, 2008:
Quoted 6 lines
Hmm. I had to squash this into it just to fix most of the code and make it pass tests, let alone fix the fetch and push implementations. Most of the library plain up and broke with this toString change.
Missing
T0001_ObjectIdsuggests to me that your method of running the tests isn't working right.
I can see that I am off to a good start leaving everything in a nice broken mess. My only excuse is that while writing the patch I was still trying to set up the tests to run properly. After applying your fix and rerunning the tests pass here also.
And, lessons learnt: also run the jgit programs to get wider coverage. (Uh, sounds like wiki material ... :)
Quoted 3 lines
And this is only JGit. I haven't even started to look into EGit. Though I don't expect you to fix EGit since you are working on NetBeans. :-)
It is clearly a bigger tasks than I had expected and maybe not a good starting point for contributing to JGit. However, in the longer run this interface change will remove some unpleasant surprises.
Signature · 1 line
Jonas Fonseca
Quoted 8 lines · Jonas Fonseca
Shawn O. Pearce <[email protected]> wrote Wed, Sep 03, 2008:
Quoted 6 lines
Hmm. I had to squash this into it just to fix most of the code and make it pass tests, let alone fix the fetch and push implementations. Most of the library plain up and broke with this toString change.
Missing
T0001_ObjectIdsuggests to me that your method of running the tests isn't working right.
Quoted 7 lines
I can see that I am off to a good start leaving everything in a nice broken mess. My only excuse is that while writing the patch I was still trying to set up the tests to run properly. After applying your fix and rerunning the tests pass here also.
And, lessons learnt: also run the jgit programs to get wider coverage. (Uh, sounds like wiki material ... :)
No big deal. The jgit pgm package has no tests. It needs tests. Running them by hand to test the sucks. Really I was just trying to make you aware of the fact that your test runner wasn't working correctly.
Quoted 7 lines
Quoted 3 lines
And this is only JGit. I haven't even started to look into EGit. Though I don't expect you to fix EGit since you are working on NetBeans. :-)
It is clearly a bigger tasks than I had expected and maybe not a good starting point for contributing to JGit. However, in the longer run this interface change will remove some unpleasant surprises.
Robin filled in the EGit stuff. I'll go through it again once more tomorrow and hopefully we can apply the whole series and move on.
Signature · 1 line
Shawn.