Examples of ObjectLoader


Examples of org.eclipse.jgit.lib.ObjectLoader

    @Override
    public ObjectLoader open(String path, ObjectId id) throws IOException {
      final File p = new File(root, path);
      if (!p.isFile())
        throw new FileNotFoundException(path);
      return new ObjectLoader() {
        @Override
        public long getSize() {
          return p.length();
        }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

      return new byte[] {};
    }

    TreeWalk tw = TreeWalk.forPath(reader, fileName, revision.getTree());
    if (tw != null) {
      ObjectLoader obj = reader.open(tw.getObjectId(0), Constants.OBJ_BLOB);
      return obj.getCachedBytes(Integer.MAX_VALUE);

    } else {
      return new byte[] {};
    }
  }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

   * @throws IOException
   *             the repository cannot be read.
   */
  public BlameGenerator push(String description, AnyObjectId id)
      throws IOException {
    ObjectLoader ldr = reader.open(id);
    if (ldr.getType() == OBJ_BLOB) {
      if (description == null)
        description = JGitText.get().blameNotCommittedYet;
      BlobCandidate c = new BlobCandidate(description, resultPath);
      c.sourceBlob = id.toObjectId();
      c.sourceText = new RawText(ldr.getCachedBytes(Integer.MAX_VALUE));
      c.regionList = new Region(0, 0, c.sourceText.size());
      remaining = c.sourceText.size();
      push(c);
      return this;
    }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

    r.renameScore = renameScore;
    return r;
  }

  void loadText(ObjectReader reader) throws IOException {
    ObjectLoader ldr = reader.open(sourceBlob, Constants.OBJ_BLOB);
    sourceText = new RawText(ldr.getCachedBytes(Integer.MAX_VALUE));
  }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

  @Override
  public ObjectLoader open(AnyObjectId objectId, int typeHint)
      throws MissingObjectException, IncorrectObjectTypeException,
      IOException {
    if (last != null) {
      ObjectLoader ldr = last.get(this, objectId);
      if (ldr != null)
        return ldr;
    }

    for (DfsPackFile pack : db.getPacks()) {
      if (pack == last)
        continue;
      ObjectLoader ldr = pack.get(this, objectId);
      if (ldr != null) {
        last = pack;
        return ldr;
      }
    }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

      getServletContext().log("Cannot open repository", e);
      rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    final ObjectLoader blobLoader;
    final RevCommit fromCommit;
    final String suffix;
    final String path = patchKey.getFileName();
    try {
      final ObjectReader reader = repo.newObjectReader();
      try {
        final RevWalk rw = new RevWalk(reader);
        final RevCommit c;
        final TreeWalk tw;

        c = rw.parseCommit(ObjectId.fromString(patchSet.getRevision().get()));
        if (side == 0) {
          fromCommit = c;
          suffix = "new";

        } else if (1 <= side && side - 1 < c.getParentCount()) {
          fromCommit = rw.parseCommit(c.getParent(side - 1));
          if (c.getParentCount() == 1) {
            suffix = "old";
          } else {
            suffix = "old" + side;
          }

        } else {
          rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
        }

        tw = TreeWalk.forPath(reader, path, fromCommit.getTree());
        if (tw == null) {
          rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
        }

        if (tw.getFileMode(0).getObjectType() == Constants.OBJ_BLOB) {
          blobLoader = reader.open(tw.getObjectId(0), Constants.OBJ_BLOB);

        } else {
          rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
          return;
        }
      } finally {
        reader.release();
      }
    } catch (IOException e) {
      getServletContext().log("Cannot read repository", e);
      rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    } catch (RuntimeException e) {
      getServletContext().log("Cannot read repository", e);
      rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    } finally {
      repo.close();
    }

    final byte[] raw =
        blobLoader.isLarge() ? null : blobLoader.getCachedBytes();
    final long when = fromCommit.getCommitTime() * 1000L;

    rsp.setDateHeader("Last-Modified", when);
    rsp.setDateHeader("Expires", 0L);
    rsp.setHeader("Pragma", "no-cache");
    rsp.setHeader("Cache-Control", "no-cache, must-revalidate");

    OutputStream out;
    ZipOutputStream zo;

    final MimeType contentType = registry.getMimeType(path, raw);
    if (!registry.isSafeInline(contentType)) {
      // The content may not be safe to transmit inline, as a browser might
      // interpret it as HTML or JavaScript hosted by this site. Such code
      // might then run in the site's security domain, and may be able to use
      // the user's cookies to perform unauthorized actions.
      //
      // Usually, wrapping the content into a ZIP file forces the browser to
      // save the content to the local system instead.
      //

      rsp.setContentType(ZIP.toString());
      rsp.setHeader("Content-Disposition", "attachment; filename=\""
          + safeFileName(path, suffix) + ".zip" + "\"");

      zo = new ZipOutputStream(rsp.getOutputStream());

      final ZipEntry e = new ZipEntry(safeFileName(path, rand(req, suffix)));
      e.setComment(fromCommit.name() + ":" + path);
      e.setSize(blobLoader.getSize());
      e.setTime(when);
      zo.putNextEntry(e);
      out = zo;

    } else {
      rsp.setContentType(contentType.toString());
      rsp.setHeader("Content-Length", "" + blobLoader.getSize());

      out = rsp.getOutputStream();
      zo = null;
    }

    if (raw != null) {
      out.write(raw);
    } else {
      blobLoader.copyTo(out);
    }

    if (zo != null) {
      zo.closeEntry();
    }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

   *            the entry containing new mode and content
   * @throws IOException
   */
  public static void checkoutEntry(final Repository repo, File f,
      DirCacheEntry entry) throws IOException {
    ObjectLoader ol = repo.open(entry.getObjectId());
    File parentDir = f.getParentFile();
    File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
    FileOutputStream channel = new FileOutputStream(tmpFile);
    try {
      ol.copyTo(channel);
    } finally {
      channel.close();
    }
    FS fs = repo.getFS();
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    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);
      }
    }
    if (!tmpFile.renameTo(f)) {
      // tried to rename which failed. Let' delete the target file and try
      // again
      FileUtils.delete(f);
      if (!tmpFile.renameTo(f)) {
        throw new IOException(MessageFormat.format(
            JGitText.get().couldNotWriteFile, tmpFile.getPath(),
            f.getPath()));
      }
    }
    entry.setLastModified(f.lastModified());
    entry.setLength((int) ol.getSize());
  }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

          return objItr.next();
        if (!lItr.next())
          return null;

        ObjectId id = lItr.getObjectId();
        ObjectLoader ldr = lItr.open();
        RevObject r = objects.get(id);
        if (r == null)
          r = parseNew(id, ldr);
        else if (r instanceof RevCommit) {
          byte[] raw = ldr.getCachedBytes();
          ((RevCommit) r).parseCanonical(RevWalk.this, raw);
        } else if (r instanceof RevTag) {
          byte[] raw = ldr.getCachedBytes();
          ((RevTag) r).parseCanonical(RevWalk.this, raw);
        } else
          r.flags |= PARSED;
        return r;
      }
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

    // The loose format is going to be faster to access than a
    // delta applied on top of a base. Use that whenever we can.
    //
    final ObjectId myId = getObjectId();
    final WindowCursor wc = new WindowCursor(db);
    ObjectLoader ldr = db.openObject2(wc, myId.name(), myId);
    if (ldr != null)
      return ldr.openStream();

    InputStream in = open(wc);
    in = new BufferedInputStream(in, 8192);

    // While we inflate the object, also deflate it back as a loose
View Full Code Here

Examples of org.eclipse.jgit.lib.ObjectLoader

      //
      return wc.open(getObjectId()).openStream();
    }
    delta = new InflaterInputStream(delta);

    final ObjectLoader base = pack.load(wc, baseOffset);
    DeltaStream ds = new DeltaStream(delta) {
      private long baseSize = SIZE_UNKNOWN;

      @Override
      protected InputStream openBase() throws IOException {
        InputStream in;
        if (base instanceof LargePackedDeltaObject)
          in = ((LargePackedDeltaObject) base).open(wc);
        else
          in = base.openStream();
        if (baseSize == SIZE_UNKNOWN) {
          if (in instanceof DeltaStream)
            baseSize = ((DeltaStream) in).getSize();
          else if (in instanceof ObjectStream)
            baseSize = ((ObjectStream) in).getSize();
        }
        return in;
      }

      @Override
      protected long getBaseSize() throws IOException {
        if (baseSize == SIZE_UNKNOWN) {
          // This code path should never be used as DeltaStream
          // is supposed to open the stream first, which would
          // initialize the size for us directly from the stream.
          baseSize = base.getSize();
        }
        return baseSize;
      }
    };
    if (type == Constants.OBJ_BAD) {
      if (!(base instanceof LargePackedDeltaObject))
        type = base.getType();
    }
    if (size == SIZE_UNKNOWN)
      size = ds.getSize();
    return ds;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.