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));
      tw.setRecursive(true);

      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 { // revert index to commit
View Full Code Here


    try {
      dc = repo.lockDirCache();
      DirCacheIterator c;

      DirCacheBuilder builder = dc.builder();
      final TreeWalk tw = new TreeWalk(repo);
      tw.addTree(new DirCacheBuildIterator(builder));
      if (workingTreeIterator == null)
        workingTreeIterator = new FileTreeIterator(repo);
      tw.addTree(workingTreeIterator);
      tw.setRecursive(true);
      if (!addAll)
        tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));

      String lastAddedFile = null;

      while (tw.next()) {
        String path = tw.getPathString();

        WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class);
        if (tw.getTree(0, DirCacheIterator.class) == null &&
            f != null && f.isEntryIgnored()) {
          // file is not in index but is ignored, do nothing
        }
        // In case of an existing merge conflict the
        // DirCacheBuildIterator iterates over all stages of
        // this path, we however want to add only one
        // new DirCacheEntry per path.
        else if (!(path.equals(lastAddedFile))) {
          if (!(update && tw.getTree(0, DirCacheIterator.class) == null)) {
            c = tw.getTree(0, DirCacheIterator.class);
            if (f != null) { // the file exists
              long sz = f.getEntryLength();
              DirCacheEntry entry = new DirCacheEntry(path);
              if (c == null || c.getDirCacheEntry() == null
                  || !c.getDirCacheEntry().isAssumeValid()) {
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

      revPool = new RevWalk(getRepository());

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

      RefNotFoundException {
    RevWalk revWalk = new RevWalk(repo);
    DirCache dc = repo.lockDirCache();
    try {
      DirCacheEditor editor = dc.editor();
      TreeWalk startWalk = new TreeWalk(revWalk.getObjectReader());
      startWalk.setRecursive(true);
      startWalk.setFilter(PathFilterGroup.createFromStrings(paths));
      boolean checkoutIndex = startCommit == null && startPoint == null;
      if (!checkoutIndex)
        startWalk.addTree(revWalk.parseCommit(getStartPoint())
            .getTree());
      else
        startWalk.addTree(new DirCacheIterator(dc));

      final File workTree = repo.getWorkTree();
      final ObjectReader r = repo.getObjectDatabase().newReader();
      try {
        while (startWalk.next()) {
          final ObjectId blobId = startWalk.getObjectId(0);
          final FileMode mode = startWalk.getFileMode(0);
          editor.add(new PathEdit(startWalk.getPathString()) {
            public void apply(DirCacheEntry ent) {
              ent.setObjectId(blobId);
              ent.setFileMode(mode);
              try {
                DirCacheCheckout.checkoutEntry(repo, new File(
                    workTree, ent.getPathString()), ent, r);
              } catch (IOException e) {
                throw new JGitInternalException(
                    MessageFormat.format(
                        JGitText.get().checkoutConflictWithFile,
                        ent.getPathString()), e);
              }
            }
          });
        }
        editor.commit();
      } finally {
        startWalk.release();
        r.release();
      }
    } finally {
      dc.unlock();
      revWalk.release();
View Full Code Here

   * @throws IOException
   */
  public SubmoduleWalk(final Repository repository) throws IOException {
    this.repository = repository;
    repoConfig = repository.getConfig();
    walk = new TreeWalk(repository);
    walk.setRecursive(true);
  }
View Full Code Here

        }

        if (i == rev.length - 1)
          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

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

    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

  protected CheckoutCommand checkoutPaths() throws IOException,
      RefNotFoundException {
    RevWalk revWalk = new RevWalk(repo);
    DirCache dc = repo.lockDirCache();
    try {
      TreeWalk treeWalk = new TreeWalk(revWalk.getObjectReader());
      treeWalk.setRecursive(true);
      treeWalk.addTree(new DirCacheIterator(dc));
      treeWalk.setFilter(PathFilterGroup.createFromStrings(paths));
      List<String> files = new LinkedList<String>();
      while (treeWalk.next())
        files.add(treeWalk.getPathString());

      if (startCommit != null || startPoint != null) {
        DirCacheEditor editor = dc.editor();
        TreeWalk startWalk = new TreeWalk(revWalk.getObjectReader());
        startWalk.setRecursive(true);
        startWalk.setFilter(treeWalk.getFilter());
        startWalk.addTree(revWalk.parseCommit(getStartPoint())
            .getTree());
        while (startWalk.next()) {
          final ObjectId blobId = startWalk.getObjectId(0);
          editor.add(new PathEdit(startWalk.getPathString()) {

            public void apply(DirCacheEntry ent) {
              ent.setObjectId(blobId);
            }
          });
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.