When RevObject overrode equals() to provide only reference equality we used to need to convert a RevObject into an ObjectId by copy() just to use standard Java tools like JUnit assertEquals(), or to use contains() or get() on standard java.util collection types. Now that we have removed this override and made ObjectId's equals() final (preventing any of this mess in the future), some copy() calls are unnecessary. Anytime the value is being used as an input to a lookup routine, or to an equals, we can avoid the copy(). However we still want to use copy() anytime we are given an ObjectId that may exist long-term, where we don't want the high cost of the additional storage from a RevCommit extension. So we can't remove all uses of copy(), just some of them. Change-Id: Ief275dace435c0ddfa362ac8e5d93558bc7e9fc3 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>tags/v0.9.1
} | } | ||||
protected static void assertEquals(AnyObjectId exp, AnyObjectId act) { | protected static void assertEquals(AnyObjectId exp, AnyObjectId act) { | ||||
if (exp != null) | |||||
exp = exp.copy(); | |||||
if (act != null) | |||||
act = act.copy(); | |||||
Assert.assertEquals(exp, act); | Assert.assertEquals(exp, act); | ||||
} | } | ||||
md.update(Constants.encodeASCII(bin.length)); | md.update(Constants.encodeASCII(bin.length)); | ||||
md.update((byte) 0); | md.update((byte) 0); | ||||
md.update(bin); | md.update(bin); | ||||
Assert.assertEquals(id.copy(), ObjectId.fromRaw(md.digest())); | |||||
Assert.assertEquals(id, ObjectId.fromRaw(md.digest())); | |||||
} | } | ||||
/** | /** |
out.print(" "); | out.print(" "); | ||||
c.getId().copyTo(outbuffer, out); | c.getId().copyTo(outbuffer, out); | ||||
if (decorate) { | if (decorate) { | ||||
Collection<Ref> list = allRefsByPeeledObjectId.get(c.copy()); | |||||
Collection<Ref> list = allRefsByPeeledObjectId.get(c); | |||||
if (list != null) { | if (list != null) { | ||||
out.print(" ("); | out.print(" ("); | ||||
for (Iterator<Ref> i = list.iterator(); i.hasNext(); ) { | for (Iterator<Ref> i = list.iterator(); i.hasNext(); ) { |
assertTrue(a1.equals((Object) a1)); | assertTrue(a1.equals((Object) a1)); | ||||
assertFalse(a1.equals(b1)); | assertFalse(a1.equals(b1)); | ||||
assertTrue(a1.equals(a1.copy())); | |||||
assertTrue(a1.equals((Object) a1.copy())); | |||||
assertTrue(a1.equals(a1)); | |||||
assertTrue(a1.equals((Object) a1)); | |||||
assertFalse(a1.equals("")); | assertFalse(a1.equals("")); | ||||
final RevWalk rw2 = new RevWalk(db); | final RevWalk rw2 = new RevWalk(db); |
assertNotNull(r.getObjectId()); | assertNotNull(r.getObjectId()); | ||||
assertNotSame(newid, r.getObjectId()); | assertNotSame(newid, r.getObjectId()); | ||||
assertSame(ObjectId.class, r.getObjectId().getClass()); | assertSame(ObjectId.class, r.getObjectId().getClass()); | ||||
assertEquals(newid.copy(), r.getObjectId()); | |||||
assertEquals(newid, r.getObjectId()); | |||||
List<org.eclipse.jgit.storage.file.ReflogReader.Entry> reverseEntries1 = db.getReflogReader("refs/heads/abc").getReverseEntries(); | List<org.eclipse.jgit.storage.file.ReflogReader.Entry> reverseEntries1 = db.getReflogReader("refs/heads/abc").getReverseEntries(); | ||||
org.eclipse.jgit.storage.file.ReflogReader.Entry entry1 = reverseEntries1.get(0); | org.eclipse.jgit.storage.file.ReflogReader.Entry entry1 = reverseEntries1.get(0); | ||||
assertEquals(1, reverseEntries1.size()); | assertEquals(1, reverseEntries1.size()); |
Transport t = Transport.open(src, uriOf(dst)); | Transport t = Transport.open(src, uriOf(dst)); | ||||
try { | try { | ||||
t.fetch(PM, Collections.singleton(new RefSpec("+refs/*:refs/*"))); | t.fetch(PM, Collections.singleton(new RefSpec("+refs/*:refs/*"))); | ||||
assertEquals(B.copy(), src.resolve(R_MASTER)); | |||||
assertEquals(B, src.resolve(R_MASTER)); | |||||
} finally { | } finally { | ||||
t.close(); | t.close(); | ||||
} | } | ||||
Ref master = refs.get(R_MASTER); | Ref master = refs.get(R_MASTER); | ||||
assertNotNull("has master", master); | assertNotNull("has master", master); | ||||
assertEquals(B.copy(), master.getObjectId()); | |||||
assertEquals(B, master.getObjectId()); | |||||
} | } | ||||
public void testSuccess() throws Exception { | public void testSuccess() throws Exception { | ||||
assertNotNull("have result", r); | assertNotNull("have result", r); | ||||
assertNull("private not advertised", r.getAdvertisedRef(R_PRIVATE)); | assertNull("private not advertised", r.getAdvertisedRef(R_PRIVATE)); | ||||
assertSame("master updated", RemoteRefUpdate.Status.OK, u.getStatus()); | assertSame("master updated", RemoteRefUpdate.Status.OK, u.getStatus()); | ||||
assertEquals(N.copy(), dst.resolve(R_MASTER)); | |||||
assertEquals(N, dst.resolve(R_MASTER)); | |||||
} | } | ||||
public void testCreateBranchAtHiddenCommitFails() throws Exception { | public void testCreateBranchAtHiddenCommitFails() throws Exception { |
// If we had any prior errors fetching this object they are | // If we had any prior errors fetching this object they are | ||||
// now resolved, as the object was parsed successfully. | // now resolved, as the object was parsed successfully. | ||||
// | // | ||||
fetchErrors.remove(id.copy()); | |||||
fetchErrors.remove(id); | |||||
} | } | ||||
private void processBlob(final RevObject obj) throws TransportException { | private void processBlob(final RevObject obj) throws TransportException { | ||||
// We could not obtain the object. There may be reasons why. | // We could not obtain the object. There may be reasons why. | ||||
// | // | ||||
List<Throwable> failures = fetchErrors.get(id.copy()); | |||||
List<Throwable> failures = fetchErrors.get(id); | |||||
final TransportException te; | final TransportException te; | ||||
te = new TransportException(MessageFormat.format(JGitText.get().cannotGet, id.name())); | te = new TransportException(MessageFormat.format(JGitText.get().cannotGet, id.name())); |