Example usage for org.eclipse.jgit.lib AbbreviatedObjectId isComplete

List of usage examples for org.eclipse.jgit.lib AbbreviatedObjectId isComplete

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib AbbreviatedObjectId isComplete.

Prototype

public boolean isComplete() 

Source Link

Document

Whether this ObjectId is actually a complete id.

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

private String format(AbbreviatedObjectId id) {
    if (id.isComplete() && db != null) {
        try {//from  w  w w. j  av a  2  s . c  o  m
            int abbreviationLength = 7;
            id = reader.abbreviate(id.toObjectId(), abbreviationLength);
        } catch (IOException cannotAbbreviate) {
            // Ignore this. We'll report the full identity.
        }
    }
    return id.name();
}

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

private byte[] open(DiffEntry.Side side, DiffEntry entry) throws IOException {
    if (entry.getMode(side) == FileMode.MISSING)
        return EMPTY;

    if (entry.getMode(side).getObjectType() != Constants.OBJ_BLOB)
        return EMPTY;

    AbbreviatedObjectId id = entry.getId(side);
    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1) {
            throw new IllegalStateException();
            //                id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
            //                switch (side) {
            //                    case OLD:
            //                        entry.oldId = id;
            //                        break;
            //                    case NEW:
            //                        entry.newId = id;
            //                        break;
            //                }
        } else if (ids.size() == 0)
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        else/*from   www  .j  av a  2  s .  c  o  m*/
            throw new AmbiguousObjectException(id, ids);
    }

    try {
        ObjectLoader ldr = source.open(side, entry);
        int binaryFileThreshold = DEFAULT_BINARY_FILE_THRESHOLD;
        return ldr.getBytes(binaryFileThreshold);

    } catch (LargeObjectException.ExceedsLimit overLimit) {
        return BINARY;

    } catch (LargeObjectException.ExceedsByteArrayLimit overLimit) {
        return BINARY;

    } catch (LargeObjectException.OutOfMemory tooBig) {
        return BINARY;

    } catch (LargeObjectException tooBig) {
        tooBig.setObjectId(id.toObjectId());
        throw tooBig;
    }
}

From source file:com.madgag.agit.diff.LineContextDiffer.java

License:Open Source License

private String format(AbbreviatedObjectId id) {
    if (id.isComplete()) {
        try {//from w  w  w.  j  a va 2 s. com
            id = objectReader.abbreviate(id.toObjectId(), abbreviationLength);
        } catch (IOException cannotAbbreviate) {
            // Ignore this. We'll report the full identity.
        } finally {
            // reader.release();
        }
    }
    return id.name();
}

From source file:com.madgag.agit.diff.LineContextDiffer.java

License:Open Source License

private byte[] open(ObjectReader reader, FileMode mode, AbbreviatedObjectId id) throws IOException {
    if (mode == FileMode.MISSING)
        return new byte[] {};

    if (mode.getObjectType() != Constants.OBJ_BLOB)
        return new byte[] {};

    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1)
            id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
        else if (ids.size() == 0)
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        else//from w  w  w.j av  a  2s.c  om
            throw new AmbiguousObjectException(id, ids);
    }

    ObjectLoader ldr = reader.open(id.toObjectId());
    return ldr.getCachedBytes(bigFileThreshold);
}

From source file:jbenchmarker.trace.git.GitExtraction.java

License:Open Source License

byte[] open(DiffEntry.Side side, DiffEntry entry) throws IOException {
    if (entry.getMode(side) == FileMode.MISSING) {
        return EMPTY;
    }/*  w w  w  .j  a va 2  s .c  o m*/

    if (entry.getMode(side).getObjectType() != Constants.OBJ_BLOB) {
        return EMPTY;
    }

    AbbreviatedObjectId id = entry.getId(side);
    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1) {
            //                id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
            //                switch (side) {
            //                    case OLD:
            //                        entry.oldId = id;
            //                        break;
            //                    case NEW:
            //                        entry.newId = id;
            //                        break;
            //                }
        } else if (ids.isEmpty()) {
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        } else {
            throw new AmbiguousObjectException(id, ids);
        }
    }
    ObjectLoader ldr = pairSource.open(side, entry);
    return getBytes(ldr, id.toObjectId());
}