Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectLoader$SmallObject


    byte[] tr = new byte[gz.length - 1];
    System.arraycopy(gz, 0, tr, 0, tr.length);

    write(id, tr);

    ObjectLoader ol;
    {
      FileInputStream fs = new FileInputStream(path(id));
      try {
        ol = UnpackedObject.open(fs, path(id), id, wc);
      } finally {
        fs.close();
      }
    }

    byte[] tmp = new byte[data.length];
    InputStream in = ol.openStream();
    IO.readFully(in, tmp, 0, tmp.length);
    try {
      in.close();
      fail("close did not throw CorruptObjectException");
    } catch (CorruptObjectException coe) {
View Full Code Here


    byte[] tr = new byte[gz.length + 1];
    System.arraycopy(gz, 0, tr, 0, gz.length);

    write(id, tr);

    ObjectLoader ol;
    {
      FileInputStream fs = new FileInputStream(path(id));
      try {
        ol = UnpackedObject.open(fs, path(id), id, wc);
      } finally {
        fs.close();
      }
    }

    byte[] tmp = new byte[data.length];
    InputStream in = ol.openStream();
    IO.readFully(in, tmp, 0, tmp.length);
    try {
      in.close();
      fail("close did not throw CorruptObjectException");
    } catch (CorruptObjectException coe) {
View Full Code Here

    final int type = Constants.OBJ_BLOB;
    byte[] data = getRng().nextBytes(300);
    byte[] gz = compressPackFormat(type, data);
    ObjectId id = ObjectId.zeroId();

    ObjectLoader ol = UnpackedObject.open(new ByteArrayInputStream(gz),
        path(id), id, wc);
    assertNotNull("created loader", ol);
    assertEquals(type, ol.getType());
    assertEquals(data.length, ol.getSize());
    assertFalse("is not large", ol.isLarge());
    assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));

    ObjectStream in = ol.openStream();
    assertNotNull("have stream", in);
    assertEquals(type, in.getType());
    assertEquals(data.length, in.getSize());
    byte[] data2 = new byte[data.length];
    IO.readFully(in, data2, 0, data.length);
    assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
    in.close();
  }
View Full Code Here

    final int type = Constants.OBJ_BLOB;
    byte[] data = getRng().nextBytes(streamThreshold + 5);
    ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
    write(id, compressPackFormat(type, data));

    ObjectLoader ol;
    {
      FileInputStream fs = new FileInputStream(path(id));
      try {
        ol = UnpackedObject.open(fs, path(id), id, wc);
      } finally {
        fs.close();
      }
    }

    assertNotNull("created loader", ol);
    assertEquals(type, ol.getType());
    assertEquals(data.length, ol.getSize());
    assertTrue("is large", ol.isLarge());
    try {
      ol.getCachedBytes();
      fail("Should have thrown LargeObjectException");
    } catch (LargeObjectException tooBig) {
      assertEquals(MessageFormat.format(
          JGitText.get().largeObjectException, id.name()), tooBig
          .getMessage());
    }

    ObjectStream in = ol.openStream();
    assertNotNull("have stream", in);
    assertEquals(type, in.getType());
    assertEquals(data.length, in.getSize());
    byte[] data2 = new byte[data.length];
    IO.readFully(in, data2, 0, data.length);
View Full Code Here

    final Repository eden = createBareRepository();
    final RevObject o1 = writeBlob(eden, "o1");
    final File[] out1 = pack(eden, o1);
    assertEquals(o1.name(), parse(o1).name());

    final ObjectLoader load1 = db.open(o1, Constants.OBJ_BLOB);
    assertNotNull(load1);

    final RevObject o2 = writeBlob(eden, "o2");
    pack(eden, o2, o1);

    // Force close, and then delete, the old pack.
    //
    whackCache();
    delete(out1);

    // Now here is the interesting thing... can the loader we made
    // earlier still resolve the object, even though its underlying
    // pack is gone, but the object still exists.
    //
    final ObjectLoader load2 = db.open(o1, Constants.OBJ_BLOB);
    assertNotNull(load2);
    assertNotSame(load1, load2);

    final byte[] data2 = load2.getCachedBytes();
    final byte[] data1 = load1.getCachedBytes();
    assertNotNull(data2);
    assertNotNull(data1);
    assertNotSame(data1, data2); // cache should be per-pack, not per object
    assertArrayEquals(data1, data2);
    assertEquals(load2.getType(), load1.getType());
  }
View Full Code Here

        continue;

      if (needBaseObjectIds)
        baseObjectIds.add(baseId);

      final ObjectLoader ldr;
      try {
        ldr = readCurs.open(baseId);
      } catch (MissingObjectException notFound) {
        missing.add(baseId);
        continue;
      }

      final DeltaVisit visit = new DeltaVisit();
      visit.data = ldr.getCachedBytes(Integer.MAX_VALUE);
      visit.id = baseId;
      final int typeCode = ldr.getType();
      final PackedObjectInfo oe = newInfo(baseId, null, null);

      if (onAppendBase(typeCode, visit.data, oe))
        entries[entryCount++] = oe;
View Full Code Here

            e.getMessage()), e);
      }
    }

    try {
      final ObjectLoader ldr = readCurs.open(id, type);
      final byte[] existingData = ldr.getCachedBytes(data.length);
      if (!Arrays.equals(data, existingData)) {
        throw new IOException(MessageFormat.format(
            JGitText.get().collisionOn, id.name()));
      }
    } catch (MissingObjectException notLocal) {
View Full Code Here

  }

  public ObjectLoader open(AnyObjectId objectId, int typeHint)
      throws MissingObjectException, IncorrectObjectTypeException,
      IOException {
    final ObjectLoader ldr = db.openObject(this, objectId);
    if (ldr == null) {
      if (typeHint == OBJ_ANY)
        throw new MissingObjectException(objectId.copy(), "unknown");
      throw new MissingObjectException(objectId.copy(), typeHint);
    }
    if (typeHint != OBJ_ANY && ldr.getType() != typeHint)
      throw new IncorrectObjectTypeException(objectId.copy(), typeHint);
    return ldr;
  }
View Full Code Here

   *            object reader to use for checkout
   * @throws IOException
   */
  public static void checkoutEntry(final Repository repo, File f,
      DirCacheEntry entry, ObjectReader or) throws IOException {
    ObjectLoader ol = or.open(entry.getObjectId());
    File parentDir = f.getParentFile();
    parentDir.mkdirs();
    FS fs = repo.getFS();
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    if (entry.getFileMode() == FileMode.SYMLINK
        && opt.getSymLinks() == SymLinks.TRUE) {
      byte[] bytes = ol.getBytes();
      String target = RawParseUtils.decode(bytes);
      fs.createSymLink(f, target);
      entry.setLength(bytes.length);
      entry.setLastModified(fs.lastModified(f));
    } else {
      File tmpFile = File.createTempFile(
          "._" + f.getName(), null, parentDir); //$NON-NLS-1$
      FileOutputStream rawChannel = new FileOutputStream(tmpFile);
      OutputStream channel;
      if (opt.getAutoCRLF() == AutoCRLF.TRUE)
        channel = new AutoCRLFOutputStream(rawChannel);
      else
        channel = rawChannel;
      try {
        ol.copyTo(channel);
      } finally {
        channel.close();
      }
      if (opt.isFileMode() && fs.supportsExecute()) {
        if (FileMode.EXECUTABLE_FILE.equals(entry.getRawMode())) {
          if (!fs.canExecute(tmpFile))
            fs.setExecute(tmpFile, true);
        } else {
          if (fs.canExecute(tmpFile))
            fs.setExecute(tmpFile, false);
        }
      }
      try {
        FileUtils.rename(tmpFile, f);
      } catch (IOException e) {
        throw new IOException(MessageFormat.format(
            JGitText.get().renameFileFailed, tmpFile.getPath(),
            f.getPath()));
      }
    }
    entry.setLastModified(f.lastModified());
    if (opt.getAutoCRLF() != AutoCRLF.FALSE)
      entry.setLength(f.length()); // AutoCRLF wants on-disk-size
    else
      entry.setLength((int) ol.getSize());
  }
View Full Code Here

  }

  @Override
  ObjectLoader openObject(final WindowCursor curs,
      final AnyObjectId objectId) throws IOException {
    ObjectLoader ldr = openLooseObject(curs, objectId);
    if (ldr != null)
      return ldr;
    ldr = wrapped.openPackedObject(curs, objectId);
    if (ldr != null)
      return ldr;
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.ObjectLoader$SmallObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.