Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.TreeWalk


    final DirCacheEditor edit;
    try {
      dc = repo.lockDirCache();
      edit = dc.editor();

      final TreeWalk tw = new TreeWalk(repo);
      tw.addTree(new DirCacheIterator(dc));
      tw.addTree(commit.getTree());
      tw.setFilter(PathFilterGroup.createFromStrings(filepaths));

      while (tw.next()) {
        final String path = tw.getPathString();
        // DirCacheIterator dci = tw.getTree(0, DirCacheIterator.class);
        final CanonicalTreeParser tree = tw.getTree(1,
            CanonicalTreeParser.class);
        if (tree == null)
          // file is not in the commit, remove from index
          edit.add(new DirCacheEditor.DeletePath(path));
        else {
View Full Code Here


    DirCacheBuilder dcBuilder = inCoreIndex.builder();

    onlyProcessed = new boolean[only.size()];
    boolean emptyCommit = true;

    TreeWalk treeWalk = new TreeWalk(repo);
    int dcIdx = treeWalk.addTree(new DirCacheIterator(index));
    int fIdx = treeWalk.addTree(new FileTreeIterator(repo));
    int hIdx = -1;
    if (headId != null)
      hIdx = treeWalk.addTree(new RevWalk(repo).parseTree(headId));
    treeWalk.setRecursive(true);

    while (treeWalk.next()) {
      String path = treeWalk.getPathString();
      // check if current entry's path matches a specified path
      int pos = lookupOnly(path);

      CanonicalTreeParser hTree = null;
      if (hIdx != -1)
        hTree = treeWalk.getTree(hIdx, CanonicalTreeParser.class);

      if (pos >= 0) {
        // include entry in commit

        DirCacheIterator dcTree = treeWalk.getTree(dcIdx,
            DirCacheIterator.class);
        FileTreeIterator fTree = treeWalk.getTree(fIdx,
            FileTreeIterator.class);

        // check if entry refers to a tracked file
        boolean tracked = dcTree != null || hTree != null;
        if (!tracked)
View Full Code Here

  public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
      int estIndexSize, final String title)
      throws IOException {
    dirCache = repository.readDirCache();

    TreeWalk treeWalk = new TreeWalk(repository);
    treeWalk.setRecursive(true);
    // add the trees (tree, dirchache, workdir)
    if (tree != null)
      treeWalk.addTree(tree);
    else
      treeWalk.addTree(new EmptyTreeIterator());
    treeWalk.addTree(new DirCacheIterator(dirCache));
    treeWalk.addTree(initialWorkingTreeIterator);
    Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);

    if (monitor != null) {
      // Get the maximum size of the work tree and index
      // and add some (quite arbitrary)
      if (estIndexSize == 0)
        estIndexSize = dirCache.getEntryCount();
      int total = Math.max(estIndexSize * 10 / 9,
          estWorkTreeSize * 10 / 9);
      monitor.beginTask(title, total);
      filters.add(new ProgressReportingFilter(monitor, total));
    }

    if (filter != null)
      filters.add(filter);
    filters.add(new SkipWorkTreeFilter(INDEX));
    filters.add(new IndexDiffFilter(INDEX, WORKDIR));
    treeWalk.setFilter(AndTreeFilter.create(filters));
    while (treeWalk.next()) {
      AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
          AbstractTreeIterator.class);
      DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
          DirCacheIterator.class);
      WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR,
          WorkingTreeIterator.class);

      if (dirCacheIterator != null) {
        final DirCacheEntry dirCacheEntry = dirCacheIterator
            .getDirCacheEntry();
        if (dirCacheEntry != null && dirCacheEntry.getStage() > 0) {
          conflicts.add(treeWalk.getPathString());
          continue;
        }
      }

      if (treeIterator != null) {
        if (dirCacheIterator != null) {
          if (!treeIterator.idEqual(dirCacheIterator)
              || treeIterator.getEntryRawMode()
              != dirCacheIterator.getEntryRawMode()) {
            // in repo, in index, content diff => changed
            changed.add(treeWalk.getPathString());
          }
        } else {
          // in repo, not in index => removed
          removed.add(treeWalk.getPathString());
          if (workingTreeIterator != null)
            untracked.add(treeWalk.getPathString());
        }
      } else {
        if (dirCacheIterator != null) {
          // not in repo, in index => added
          added.add(treeWalk.getPathString());
        } else {
          // not in repo, not in index => untracked
          if (workingTreeIterator != null
              && !workingTreeIterator.isEntryIgnored()) {
            untracked.add(treeWalk.getPathString());
          }
        }
      }

      if (dirCacheIterator != null) {
        if (workingTreeIterator == null) {
          // in index, not in workdir => missing
          missing.add(treeWalk.getPathString());
        } else {
          if (workingTreeIterator.isModified(
              dirCacheIterator.getDirCacheEntry(), true)) {
            // in index, in workdir, content differs => modified
            modified.add(treeWalk.getPathString());
          }
        }
      }
    }

View Full Code Here

        }

        if (i == rev.length - i)
          return tree.copy();

        TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(),
            new String(rev, i + 1, rev.length - i - 1), tree);
        return tw != null ? tw.getObjectId(0) : null;
      }

      default:
        if (ref != null)
          throw new RevisionSyntaxException(revstr);
View Full Code Here

    boolean hasUnmergedPaths = dc.hasUnmergedPaths();
    if (hasUnmergedPaths)
      throw new UnmergedPathsException();

    // determine whether we need to commit
    TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.reset();
    treeWalk.setRecursive(true);
    treeWalk.addTree(new DirCacheIterator(dc));
    ObjectId id = repo.resolve(Constants.HEAD + "^{tree}");
    if (id == null)
      throw new NoHeadException(
          JGitText.get().cannotRebaseWithoutCurrentHead);

    treeWalk.addTree(id);

    treeWalk.setFilter(TreeFilter.ANY_DIFF);

    boolean needsCommit = treeWalk.next();
    treeWalk.release();

    if (needsCommit) {
      CommitCommand commit = new Git(repo).commit();
      commit.setMessage(readFile(rebaseDir, MESSAGE));
      commit.setAuthor(parseAuthor());
View Full Code Here

  private final Repository repository;

  RewriteTreeFilter(final RevWalk walker, final TreeFilter t) {
    repository = walker.repository;
    pathFilter = new TreeWalk(walker.reader);
    pathFilter.setFilter(t);
    pathFilter.setRecursive(t.shouldBeRecursive());
  }
View Full Code Here

      IncorrectObjectTypeException, IOException {
    // Reset the tree filter to scan this commit and parents.
    //
    final RevCommit[] pList = c.parents;
    final int nParents = pList.length;
    final TreeWalk tw = pathFilter;
    final ObjectId[] trees = new ObjectId[nParents + 1];
    for (int i = 0; i < nParents; i++) {
      final RevCommit p = c.parents[i];
      if ((p.flags & PARSED) == 0)
        p.parseHeaders(walker);
      trees[i] = p.getTree();
    }
    trees[nParents] = c.getTree();
    tw.reset(trees);

    if (nParents == 1) {
      // We have exactly one parent. This is a very common case.
      //
      int chgs = 0, adds = 0;
      while (tw.next()) {
        chgs++;
        if (tw.getRawMode(0) == 0 && tw.getRawMode(1) != 0)
          adds++;
        else
          break; // no point in looking at this further.
      }

      if (chgs == 0) {
        // No changes, so our tree is effectively the same as
        // our parent tree. We pass the buck to our parent.
        //
        c.flags |= REWRITE;
        return false;
      } else {
        // We have interesting items, but neither of the special
        // cases denoted above.
        //
        if (adds > 0 && tw.getFilter() instanceof FollowFilter) {
          // One of the paths we care about was added in this
          // commit. We need to update our filter to its older
          // name, if we can discover it. Find out what that is.
          //
          updateFollowFilter(trees);
        }
        return true;
      }
    } else if (nParents == 0) {
      // We have no parents to compare against. Consider us to be
      // REWRITE only if we have no paths matching our filter.
      //
      if (tw.next())
        return true;
      c.flags |= REWRITE;
      return false;
    }

    // We are a merge commit. We can only be REWRITE if we are same
    // to _all_ parents. We may also be able to eliminate a parent if
    // it does not contribute changes to us. Such a parent may be an
    // uninteresting side branch.
    //
    final int[] chgs = new int[nParents];
    final int[] adds = new int[nParents];
    while (tw.next()) {
      final int myMode = tw.getRawMode(nParents);
      for (int i = 0; i < nParents; i++) {
        final int pMode = tw.getRawMode(i);
        if (myMode == pMode && tw.idEqual(i, nParents))
          continue;

        chgs[i]++;
        if (pMode == 0 && myMode != 0)
          adds[i]++;
View Full Code Here

  }

  private void updateFollowFilter(ObjectId[] trees)
      throws MissingObjectException, IncorrectObjectTypeException,
      CorruptObjectException, IOException {
    TreeWalk tw = pathFilter;
    FollowFilter oldFilter = (FollowFilter) tw.getFilter();
    tw.setFilter(TreeFilter.ANY_DIFF);
    tw.reset(trees);

    List<DiffEntry> files = DiffEntry.scan(tw);
    RenameDetector rd = new RenameDetector(repository);
    rd.addAll(files);
    files = rd.compute();

    TreeFilter newFilter = oldFilter;
    for (DiffEntry ent : files) {
      if (isRename(ent) && ent.getNewPath().equals(oldFilter.getPath())) {
        newFilter = FollowFilter.create(ent.getOldPath());
        break;
      }
    }
    tw.setFilter(newFilter);
  }
View Full Code Here

   */
  public List<DiffEntry> scan(AbstractTreeIterator a, AbstractTreeIterator b)
      throws IOException {
    assertHaveRepository();

    TreeWalk walk = new TreeWalk(reader);
    walk.addTree(a);
    walk.addTree(b);
    walk.setRecursive(true);

    TreeFilter filter = getDiffTreeFilterFor(a, b);
    if (pathFilter instanceof FollowFilter) {
      walk.setFilter(AndTreeFilter.create(
          PathFilter.create(((FollowFilter) pathFilter).getPath()),
          filter));
    } else {
      walk.setFilter(AndTreeFilter.create(pathFilter, filter));
    }

    source = new ContentSource.Pair(source(a), source(b));

    List<DiffEntry> files = DiffEntry.scan(walk);
    if (pathFilter instanceof FollowFilter && isAdd(files)) {
      // The file we are following was added here, find where it
      // came from so we can properly show the rename or copy,
      // then continue digging backwards.
      //
      a.reset();
      b.reset();
      walk.reset();
      walk.addTree(a);
      walk.addTree(b);
      walk.setFilter(filter);

      if (renameDetector == null)
        setDetectRenames(true);
      files = updateFollowFilter(detectRenames(DiffEntry.scan(walk)));

View Full Code Here

      revPool = new RevWalk(getRepository());

    revPool.setRetainBody(true);
    SEEN = revPool.newFlag("SEEN");
    reader = revPool.getObjectReader();
    treeWalk = new TreeWalk(reader);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.treewalk.TreeWalk

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.