Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectLoader


        if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
          continue;
        }
        tw.getObjectId(id, 0);

        ObjectLoader loader = repository.open(id);
        if (FileMode.SYMLINK == mode) {
          TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString(),TarArchiveEntry.LF_SYMLINK);
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          loader.copyTo(bos);
          entry.setLinkName(bos.toString());
          entry.setModTime(modified);
          tos.putArchiveEntry(entry);
          tos.closeArchiveEntry();
        } else {
          TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString());
          entry.setMode(mode.getBits());
          entry.setModTime(modified);
          entry.setSize(loader.getSize());
          tos.putArchiveEntry(entry);
          loader.copyTo(tos);
          tos.closeArchiveEntry();
        }
      }
      tos.finish();
      tos.close();
View Full Code Here


    }
  }

  private void verifyAndInsertLooseObject(final AnyObjectId id,
      final byte[] compressed) throws IOException {
    final ObjectLoader uol;
    try {
      uol = UnpackedObject.parse(compressed, id);
    } catch (CorruptObjectException parsingError) {
      // Some HTTP servers send back a "200 OK" status with an HTML
      // page that explains the requested file could not be found.
      // These servers are most certainly misconfigured, but many
      // of them exist in the world, and many of those are hosting
      // Git repositories.
      //
      // Since an HTML page is unlikely to hash to one of our loose
      // objects we treat this condition as a FileNotFoundException
      // and attempt to recover by getting the object from another
      // source.
      //
      final FileNotFoundException e;
      e = new FileNotFoundException(id.name());
      e.initCause(parsingError);
      throw e;
    }

    final int type = uol.getType();
    final byte[] raw = uol.getCachedBytes();
    if (objCheck != null) {
      try {
        objCheck.check(type, raw);
      } catch (CorruptObjectException e) {
        throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionInvalid
View Full Code Here

            if (!ObjectId.isId(revision)) {
                throw new StoreException.ReadException("Malformed id " + revision);
            }
            final ObjectId blobOrCommitId = ObjectId.fromString(revision);

            final ObjectLoader loader = git.getRepository().open(blobOrCommitId);

            if (loader.getType() == Constants.OBJ_COMMIT) {
                // look up the file at this revision
                final RevCommit commit = RevCommit.parse(loader.getCachedBytes());

                final TreeWalk treeWalk2 = new TreeWalk(git.getRepository());
                treeWalk2.addTree(commit.getTree());
                treeWalk2.setRecursive(true);
                //final String joinedPath = "matrices" + "/" + Joiner.on("/").join(path);
                final String joinedPath = Joiner.on("/").join(path);
                treeWalk2.setFilter(PathFilter.create(joinedPath));

                if (!treeWalk2.next()) {
                    throw new StoreException.ReadException("Did not find expected file '" + joinedPath + "'");
                }
                final ObjectId blobId = treeWalk2.getObjectId(0);
                return getFileContents(c, blobId);
            } else if (loader.getType() == Constants.OBJ_BLOB) {
                return getFileContents(c, blobOrCommitId);
            } else {
                throw new StoreException.ReadException("Invalid Object Type " + loader.getType() + " for id " + revision);
            }
        } catch (IOException e) {
            throw new StoreException.ReadException(e);
        }
    }
View Full Code Here

        }
    }

    private <C> C getFileContents(final Class<C> c,
            final ObjectId blobId) throws IOException {
        ObjectLoader loader = git.getRepository().open(blobId);
        final ObjectMapper mapper = Serializers.lenient();
        return mapper.readValue(loader.getBytes(), c);
    }
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

        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

      }
    }

    if (isCheckObjectCollisions()) {
      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

        }

        long len = reader.getObjectSize(id, org.eclipse.jgit.lib.Constants.OBJ_BLOB);
        setContentType(response, "application/octet-stream");
        response.setIntHeader("Content-Length", (int) len);
        ObjectLoader ldr = repository.open(id);
        ldr.copyTo(response.getOutputStream());
        served = true;
      }
    } finally {
      tw.release();
      rw.dispose();
View Full Code Here

          continue;
        }
        ObjectId entid = tw.getObjectId(0);
        FileMode entmode = tw.getFileMode(0);
        if (entmode != FileMode.GITLINK) {
          ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
          content = ldr.getCachedBytes();
        }
      }
    } catch (Throwable t) {
      if (throwError) {
        error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name());
View Full Code Here

  public static byte[] getByteContent(Repository repository, String objectId) {
    RevWalk rw = new RevWalk(repository);
    byte[] content = null;
    try {
      RevBlob blob = rw.lookupBlob(ObjectId.fromString(objectId));
      ObjectLoader ldr = repository.open(blob.getId(), Constants.OBJ_BLOB);
      content = ldr.getCachedBytes();
    } catch (Throwable t) {
      error(t, repository, "{0} can't find blob {1}", objectId);
    } finally {
      rw.dispose();
    }
View Full Code Here

TOP

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

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.