예제 #1
0
  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;

    if (isBinary()) return BINARY;

    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.size() == 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 overLimit) {
      return BINARY;

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

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

    } catch (LargeObjectException tooBig) {
      tooBig.setObjectId(id.toObjectId());
      throw tooBig;
    }
  }
예제 #2
0
 public static GitObject createGitObject(RepositoryData repositoryData, String hash)
     throws MissingObjectException, IOException {
   Repository repository = repositoryData.getRepository();
   ObjectId id = repository.resolve(hash);
   ObjectLoader loader = repository.open(id);
   GitObject object = null;
   switch (loader.getType()) {
     case Constants.OBJ_COMMIT:
       object = new Commit(hash, new String(loader.getCachedBytes()));
       break;
     case Constants.OBJ_TREE:
       object = new Tree(hash, loader.getBytes());
       break;
     case Constants.OBJ_BLOB:
       object = new Blob(hash, new String(loader.getCachedBytes()));
       break;
     case Constants.OBJ_TAG:
       object = new Tag(hash, new String(loader.getCachedBytes()));
       break;
   }
   object.setRepositoryData(repositoryData);
   return object;
 }
예제 #3
0
 private boolean isLfsPointer(@NotNull ObjectLoader loader) {
   return loader.getSize() <= ru.bozaro.gitlfs.pointer.Constants.POINTER_MAX_SIZE
       && Pointer.parsePointer(loader.getBytes()) != null;
 }