Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectReader


        newHead = continueRebase();

      if (operation == Operation.SKIP)
        newHead = checkoutCurrentHead();

      ObjectReader or = repo.newObjectReader();

      List<Step> steps = loadSteps();
      for (Step step : steps) {
        popSteps(1);
        Collection<ObjectId> ids = or.resolve(step.commit);
        if (ids.size() != 1)
          throw new JGitInternalException(
              "Could not resolve uniquely the abbreviated object ID");
        RevCommit commitToPick = walk
            .parseCommit(ids.iterator().next());
View Full Code Here


    fw.write("# Created by EGit: rebasing " + upstreamCommit.name()
        + " onto " + headId.name());
    fw.newLine();
    try {
      StringBuilder sb = new StringBuilder();
      ObjectReader reader = walk.getObjectReader();
      for (RevCommit commit : cherryPickList) {
        sb.setLength(0);
        sb.append(Action.PICK.toToken());
        sb.append(" ");
        sb.append(reader.abbreviate(commit).name());
        sb.append(" ");
        sb.append(commit.getShortMessage());
        fw.write(sb.toString());
        fw.newLine();
      }
View Full Code Here

      tw.addTree(commit.getTree());
      PathFilter f = PathFilter.create(requestedPath);
      tw.setFilter(f);
      tw.setRecursive(true);
      MutableObjectId id = new MutableObjectId();
      ObjectReader reader = tw.getObjectReader();
      while (tw.next()) {
        FileMode mode = tw.getFileMode(0);
        if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
          continue;
        }
        tw.getObjectId(id, 0);

        String filename = StringUtils.getLastPathElement(requestedPath);
        try {
            String userAgent = request.getHeader("User-Agent");
          if (userAgent != null && userAgent.indexOf("MSIE 5.5") > -1) {
                response.setHeader("Content-Disposition", "filename=\""
                    +  URLEncoder.encode(filename, Constants.ENCODING) + "\"");
          } else if (userAgent != null && userAgent.indexOf("MSIE") > -1) {
                response.setHeader("Content-Disposition", "attachment; filename=\""
                    +  URLEncoder.encode(filename, Constants.ENCODING) + "\"");
          } else {
              response.setHeader("Content-Disposition", "attachment; filename=\""
                    + new String(filename.getBytes(Constants.ENCODING), "latin1") + "\"");
          }
        }
        catch (UnsupportedEncodingException e) {
          response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        }

        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;
View Full Code Here

        PathFilter f = PathFilter.create(basePath);
        tw.setFilter(f);
      }
      tw.setRecursive(true);
      MutableObjectId id = new MutableObjectId();
      ObjectReader reader = tw.getObjectReader();
      long modified = commit.getAuthorIdent().getWhen().getTime();
      while (tw.next()) {
        FileMode mode = tw.getFileMode(0);
        if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
          continue;
        }
        tw.getObjectId(id, 0);

        ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
        entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
        entry.setComment(commit.getName());
        entry.setUnixMode(mode.getBits());
        entry.setTime(modified);
        zos.putArchiveEntry(entry);
View Full Code Here

          tags.put(tag.getReferencedObjectId().getName(), new ArrayList<String>());
        }
        tags.get(tag.getReferencedObjectId().getName()).add(tag.displayName);
      }

      ObjectReader reader = repository.newObjectReader();

      // get the local branches
      List<RefModel> branches = JGitUtils.getLocalBranches(repository, true, -1);

      // sort them by most recently updated
      Collections.sort(branches, new Comparator<RefModel>() {
        @Override
        public int compare(RefModel ref1, RefModel ref2) {
          return ref2.getDate().compareTo(ref1.getDate());
        }
      });

      // reorder default branch to first position
      RefModel defaultBranch = null;
      ObjectId defaultBranchId = JGitUtils.getDefaultBranch(repository);
      for (RefModel branch :  branches) {
        if (branch.getObjectId().equals(defaultBranchId)) {
          defaultBranch = branch;
          break;
        }
      }
      branches.remove(defaultBranch);
      branches.add(0, defaultBranch);

      // walk through each branch
      for (RefModel branch : branches) {

        boolean indexBranch = false;
        if (model.indexedBranches.contains(com.gitblit.Constants.DEFAULT_BRANCH)
            && branch.equals(defaultBranch)) {
          // indexing "default" branch
          indexBranch = true;
        } else if (branch.getName().startsWith(com.gitblit.Constants.R_META)) {
          // skip internal meta branches
          indexBranch = false;
        } else {
          // normal explicit branch check
          indexBranch = model.indexedBranches.contains(branch.getName());
        }

        // if this branch is not specifically indexed then skip
        if (!indexBranch) {
          continue;
        }

        String branchName = branch.getName();
        RevWalk revWalk = new RevWalk(reader);
        RevCommit tip = revWalk.parseCommit(branch.getObjectId());
        String tipId = tip.getId().getName();

        String keyName = getBranchKey(branchName);
        config.setString(CONF_ALIAS, null, keyName, branchName);
        config.setString(CONF_BRANCH, null, keyName, tipId);

        // index the blob contents of the tree
        TreeWalk treeWalk = new TreeWalk(repository);
        treeWalk.addTree(tip.getTree());
        treeWalk.setRecursive(true);

        Map<String, ObjectId> paths = new TreeMap<String, ObjectId>();
        while (treeWalk.next()) {
          // ensure path is not in a submodule
          if (treeWalk.getFileMode(0) != FileMode.GITLINK) {
            paths.put(treeWalk.getPathString(), treeWalk.getObjectId(0));
          }
        }

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        byte[] tmp = new byte[32767];

        RevWalk commitWalk = new RevWalk(reader);
        commitWalk.markStart(tip);

        RevCommit commit;
        while ((paths.size() > 0) && (commit = commitWalk.next()) != null) {
          TreeWalk diffWalk = new TreeWalk(reader);
          int parentCount = commit.getParentCount();
          switch (parentCount) {
          case 0:
            diffWalk.addTree(new EmptyTreeIterator());
            break;
          case 1:
            diffWalk.addTree(getTree(commitWalk, commit.getParent(0)));
            break;
          default:
            // skip merge commits
            continue;
          }
          diffWalk.addTree(getTree(commitWalk, commit));
          diffWalk.setFilter(ANY_DIFF);
          diffWalk.setRecursive(true);
          while ((paths.size() > 0) && diffWalk.next()) {
            String path = diffWalk.getPathString();
            if (!paths.containsKey(path)) {
              continue;
            }

            // remove path from set
            ObjectId blobId = paths.remove(path);
            result.blobCount++;

            // index the blob metadata
            String blobAuthor = getAuthor(commit);
            String blobCommitter = getCommitter(commit);
            String blobDate = DateTools.timeToString(commit.getCommitTime() * 1000L,
                Resolution.MINUTE);

            Document doc = new Document();
            doc.add(new Field(FIELD_OBJECT_TYPE, SearchObjectType.blob.name(), StringField.TYPE_STORED));
            doc.add(new Field(FIELD_BRANCH, branchName, TextField.TYPE_STORED));
            doc.add(new Field(FIELD_COMMIT, commit.getName(), TextField.TYPE_STORED));
            doc.add(new Field(FIELD_PATH, path, TextField.TYPE_STORED));
            doc.add(new Field(FIELD_DATE, blobDate, StringField.TYPE_STORED));
            doc.add(new Field(FIELD_AUTHOR, blobAuthor, TextField.TYPE_STORED));
            doc.add(new Field(FIELD_COMMITTER, blobCommitter, TextField.TYPE_STORED));

            // determine extension to compare to the extension
            // blacklist
            String ext = null;
            String name = path.toLowerCase();
            if (name.indexOf('.') > -1) {
              ext = name.substring(name.lastIndexOf('.') + 1);
            }

            // index the blob content
            if (StringUtils.isEmpty(ext) || !excludedExtensions.contains(ext)) {
              ObjectLoader ldr = repository.open(blobId, Constants.OBJ_BLOB);
              InputStream in = ldr.openStream();
              int n;
              while ((n = in.read(tmp)) > 0) {
                os.write(tmp, 0, n);
              }
              in.close();
              byte[] content = os.toByteArray();
              String str = StringUtils.decodeString(content, encodings);
              doc.add(new Field(FIELD_CONTENT, str, TextField.TYPE_STORED));
              os.reset();
            }

            // add the blob to the index
            writer.addDocument(doc);
          }
        }

        os.close();

        // index the tip commit object
        if (indexedCommits.add(tipId)) {
          Document doc = createDocument(tip, tags.get(tipId));
          doc.add(new Field(FIELD_BRANCH, branchName, TextField.TYPE_STORED));
          writer.addDocument(doc);
          result.commitCount += 1;
          result.branchCount += 1;
        }

        // traverse the log and index the previous commit objects
        RevWalk historyWalk = new RevWalk(reader);
        historyWalk.markStart(historyWalk.parseCommit(tip.getId()));
        RevCommit rev;
        while ((rev = historyWalk.next()) != null) {
          String hash = rev.getId().getName();
          if (indexedCommits.add(hash)) {
            Document doc = createDocument(rev, tags.get(hash));
            doc.add(new Field(FIELD_BRANCH, branchName, TextField.TYPE_STORED));
            writer.addDocument(doc);
            result.commitCount += 1;
          }
        }
      }

      // finished
      reader.release();

      // commit all changes and reset the searcher
      config.setInt(CONF_INDEX, null, CONF_VERSION, INDEX_VERSION);
      config.save();
      writer.commit();
View Full Code Here

          Assert.formatNotNull("Repository"));
    if (commitId == null)
      throw new IllegalArgumentException(
          Assert.formatNotNull("Commit id"));

    final ObjectReader reader = repository.newObjectReader();
    final RevWalk walk = new RevWalk(reader);
    try {
      return withParents(reader, walk, walk.parseCommit(commitId));
    } catch (IOException e) {
      walk.release();
View Full Code Here

    if (revision.length() == 0)
      throw new IllegalArgumentException(
          Assert.formatNotEmpty("Revision"));

    final ObjectId commit = CommitUtils.strictResolve(repository, revision);
    final ObjectReader reader = repository.newObjectReader();
    final RevWalk walk = new RevWalk(reader);
    try {
      return withParents(reader, walk, walk.parseCommit(commit));
    } catch (IOException e) {
      walk.release();
View Full Code Here

  @Override
  public boolean include(RevWalk walker, RevCommit commit,
      Collection<DiffEntry> diffs) {
    count = 0;
    final ObjectReader reader = walker.getObjectReader();
    for (DiffEntry diff : diffs) {
      if (!isFileDiff(diff))
        continue;
      final AbbreviatedObjectId oldId = diff.getOldId();
      if (oldId == null)
View Full Code Here

  @Override
  public boolean include(final RevWalk walker, final RevCommit commit,
      final Collection<DiffEntry> diffs) {
    markStart(commit);
    final ObjectReader reader = walker.getObjectReader();
    for (DiffEntry diff : diffs) {
      if (!isFileDiff(diff))
        continue;
      final AbbreviatedObjectId oldId = diff.getOldId();
      if (oldId == null)
View Full Code Here

  }

  public static void validateIndex(Git git) throws NoWorkTreeException,
      IOException {
    DirCache dc = git.getRepository().lockDirCache();
    ObjectReader r = git.getRepository().getObjectDatabase().newReader();
    try {
      for (int i = 0; i < dc.getEntryCount(); ++i) {
        DirCacheEntry entry = dc.getEntry(i);
        if (entry.getLength() > 0)
          assertEquals(entry.getLength(), r.getObjectSize(
              entry.getObjectId(), ObjectReader.OBJ_ANY));
      }
    } finally {
      dc.unlock();
      r.release();
    }
  }
View Full Code Here

TOP

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

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.