public void test17_FromString() { const string s = "7b6e8067ec96acef9"; AbbreviatedObjectId i = AbbreviatedObjectId.FromString(s); Assert.IsNotNull(i); Assert.AreEqual(s.Length, i.Length); Assert.IsFalse(i.isComplete()); Assert.AreEqual(s, i.name()); Assert.IsNull(i.ToObjectId()); }
/// <exception cref="System.IO.IOException"></exception> public override ICollection <ObjectId> Resolve(AbbreviatedObjectId id) { if (id.IsComplete) { return(Sharpen.Collections.Singleton(id.ToObjectId())); } HashSet <ObjectId> matches = new HashSet <ObjectId>(); db.Resolve(matches, id); return(matches); }
private string Format(AbbreviatedObjectId id) { if (id.IsComplete && db != null) { try { id = reader.Abbreviate(id.ToObjectId(), abbreviationLength); } catch (IOException) { } } // Ignore this. We'll report the full identity. return(id.Name); }
public void testFull_FromString() { const string s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; AbbreviatedObjectId i = AbbreviatedObjectId.FromString(s); Assert.IsNotNull(i); Assert.AreEqual(s.Length, i.Length); Assert.IsTrue(i.isComplete()); Assert.AreEqual(s, i.name()); ObjectId f = i.ToObjectId(); Assert.IsNotNull(f); Assert.AreEqual(ObjectId.FromString(s), f); Assert.AreEqual(f.GetHashCode(), i.GetHashCode()); }
/// <exception cref="System.IO.IOException"></exception> private byte[] Open(DiffEntry.Side side, DiffEntry entry) { if (entry.GetMode(side) == FileMode.MISSING) { return(EMPTY); } if (entry.GetMode(side).GetObjectType() != Constants.OBJ_BLOB) { return(EMPTY); } if (IsBinary()) { return(BINARY); } AbbreviatedObjectId id = entry.GetId(side); if (!id.IsComplete) { ICollection <ObjectId> ids = reader.Resolve(id); if (ids.Count == 1) { id = AbbreviatedObjectId.FromObjectId(ids.Iterator().Next()); switch (side) { case DiffEntry.Side.OLD: { entry.oldId = id; break; } case DiffEntry.Side.NEW: { entry.newId = id; break; } } } else { if (ids.Count == 0) { throw new MissingObjectException(id, Constants.OBJ_BLOB); } else { throw new AmbiguousObjectException(id, ids); } } } try { ObjectLoader ldr = source.Open(side, entry); return(ldr.GetBytes(binaryFileThreshold)); } catch (LargeObjectException.ExceedsLimit) { return(BINARY); } catch (LargeObjectException.ExceedsByteArrayLimit) { return(BINARY); } catch (LargeObjectException.OutOfMemory) { return(BINARY); } catch (LargeObjectException tooBig) { tooBig.SetObjectId(id.ToObjectId()); throw; } }