Example usage for org.eclipse.jgit.diff DiffEntry getMode

List of usage examples for org.eclipse.jgit.diff DiffEntry getMode

Introduction

In this page you can find the example usage for org.eclipse.jgit.diff DiffEntry getMode.

Prototype

public FileMode getMode(Side side) 

Source Link

Document

Get the mode associated with this file.

Usage

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  .  java 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: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 .  ja va 2  s .  com

    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());
}