Package org.eclipse.jgit.lib

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


    return null;
  }

  final ObjectLoader openObjectImpl1(final WindowCursor curs,
      final AnyObjectId objectId) throws IOException {
    ObjectLoader ldr;

    ldr = openObject1(curs, objectId);
    if (ldr != null)
      return ldr;
View Full Code Here


  }

  final ObjectLoader openObjectImpl2(final WindowCursor curs,
      final String objectName, final AnyObjectId objectId)
      throws IOException {
    ObjectLoader ldr;

    ldr = openObject2(curs, objectName, objectId);
    if (ldr != null)
      return ldr;
View Full Code Here

    }

    @Override
    public ObjectLoader open(String path, ObjectId id) throws IOException {
      seek(path);
      return new ObjectLoader() {
        @Override
        public long getSize() {
          return ptr.getEntryLength();
        }
View Full Code Here

    @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

      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

   * @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

    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

  @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

      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

   *            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

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.