Package org.eclipse.compare.structuremergeviewer

Examples of org.eclipse.compare.structuremergeviewer.DiffNode


            return super.compare(viewer, e1, e2);
        }

        private ErlNode getErlNode(final Object e) {
            if (e instanceof DiffNode) {
                final DiffNode d = (DiffNode) e;
                final ITypedElement left = d.getLeft();
                if (left instanceof ErlNode) {
                    return (ErlNode) left;
                }
                final ITypedElement right = d.getRight();
                if (right instanceof ErlNode) {
                    return (ErlNode) right;
                }
            }
            return null;
View Full Code Here


          throw new InvocationTargetException(
              new IllegalStateException(
                  UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge));
        String repoRelativePath = map.getRepoRelativePath(resource);
        filterPathStrings.add(repoRelativePath);
        DiffNode node = new DiffNode(Differencer.NO_CHANGE) {
          @Override
          public Image getImage() {
            return FOLDER_IMAGE;
          }
        };
View Full Code Here

      RevCommit compareCommit, IProgressMonitor monitor)
      throws IOException, InterruptedException {
    boolean useIndex = compareVersion.equals(CompareTreeView.INDEX_VERSION);
    boolean checkIgnored = false;

    IDiffContainer result = new DiffNode(Differencer.CONFLICTING);

    TreeWalk tw = new TreeWalk(repository);

    // filter by selected resources
    if (filterPathStrings.size() > 1) {
      List<TreeFilter> suffixFilters = new ArrayList<TreeFilter>();
      for (String filterPath : filterPathStrings)
        suffixFilters.add(PathFilter.create(filterPath));
      TreeFilter otf = OrTreeFilter.create(suffixFilters);
      tw.setFilter(otf);
    } else if (filterPathStrings.size() > 0) {
      String path = filterPathStrings.get(0);
      if (path.length() != 0)
        tw.setFilter(PathFilter.create(path));
    }

    tw.setRecursive(true);

    int baseTreeIndex;
    if (baseCommit == null) {
      // compare workspace with something
      checkIgnored = true;
      baseTreeIndex = tw.addTree(new AdaptableFileTreeIterator(
          repository, ResourcesPlugin.getWorkspace().getRoot()));
    } else
      baseTreeIndex = tw.addTree(new CanonicalTreeParser(null, repository
          .newObjectReader(), baseCommit.getTree()));
    int compareTreeIndex;
    if (!useIndex)
      compareTreeIndex = tw.addTree(new CanonicalTreeParser(null,
          repository.newObjectReader(), compareCommit.getTree()));
    else
      // compare something with the index
      compareTreeIndex = tw.addTree(new DirCacheIterator(repository
          .readDirCache()));

    try {
      while (tw.next()) {
        if (monitor.isCanceled())
          throw new InterruptedException();
        AbstractTreeIterator compareVersionIterator = tw.getTree(
            compareTreeIndex, AbstractTreeIterator.class);
        AbstractTreeIterator baseVersionIterator = tw.getTree(
            baseTreeIndex, AbstractTreeIterator.class);
        if (checkIgnored
            && baseVersionIterator != null
            && ((WorkingTreeIterator) baseVersionIterator)
                .isEntryIgnored())
          continue;


        if (compareVersionIterator != null
            && baseVersionIterator != null) {
          boolean equalContent = compareVersionIterator
              .getEntryObjectId().equals(
                  baseVersionIterator.getEntryObjectId());
          if (equalContent)
            continue;
        }

        String encoding = null;

        GitFileRevision compareRev = null;
        if (compareVersionIterator != null) {
          String entryPath = compareVersionIterator.getEntryPathString();
          encoding = CompareCoreUtils.getResourceEncoding(repository, entryPath);
          if (!useIndex)
            compareRev = GitFileRevision.inCommit(repository,
                compareCommit, entryPath,
                tw.getObjectId(compareTreeIndex));
          else
            compareRev = GitFileRevision.inIndex(repository,
                entryPath);
        }

        GitFileRevision baseRev = null;
        if (baseVersionIterator != null) {
          String entryPath = baseVersionIterator.getEntryPathString();
          if (encoding == null) {
            encoding = CompareCoreUtils.getResourceEncoding(repository, entryPath);
          }
          baseRev = GitFileRevision.inCommit(repository, baseCommit,
              entryPath, tw.getObjectId(baseTreeIndex));
        }

        if (compareVersionIterator != null
            && baseVersionIterator != null) {
          monitor.setTaskName(baseVersionIterator
              .getEntryPathString());
          // content exists on both sides
          add(result, baseVersionIterator.getEntryPathString(),
              new DiffNode(new FileRevisionTypedElement(compareRev, encoding),
                  new FileRevisionTypedElement(baseRev, encoding)));
        } else if (baseVersionIterator != null
            && compareVersionIterator == null) {
          monitor.setTaskName(baseVersionIterator
              .getEntryPathString());
          // only on base side
          add(result, baseVersionIterator.getEntryPathString(),
              new DiffNode(Differencer.DELETION | Differencer.RIGHT, null, null,
                  new FileRevisionTypedElement(baseRev, encoding)));
        } else if (compareVersionIterator != null
            && baseVersionIterator == null) {
          monitor.setTaskName(compareVersionIterator
              .getEntryPathString());
          // only on compare side
          add(result, compareVersionIterator.getEntryPathString(),
              new DiffNode(Differencer.ADDITION | Differencer.RIGHT, null,
                  new FileRevisionTypedElement(compareRev, encoding), null));
        }

        if (monitor.isCanceled())
          throw new InterruptedException();
View Full Code Here

    for (IDiffElement child : parent.getChildren()) {
      if (child.getName().equals(name)) {
        return ((DiffNode) child);
      }
    }
    DiffNode child = new DiffNode(parent, Differencer.NO_CHANGE) {

      @Override
      public String getName() {
        return name;
      }
View Full Code Here

  @Override
  public Object getAdapter(Class adapter) {
    if (adapter == IFile.class || adapter == IResource.class) {
      Object selectedEdition = getSelectedEdition();
      if (selectedEdition instanceof DiffNode) {
        DiffNode diffNode = (DiffNode) selectedEdition;
        ITypedElement element = diffNode.getLeft();
        if (element instanceof ResourceEditableRevision) {
          ResourceEditableRevision resourceRevision = (ResourceEditableRevision) element;
          return resourceRevision.getFile();
        }
      }
View Full Code Here

      RevCommit headCommit,
      RevCommit ancestorCommit, List<String> filterPaths, RevWalk rw,
      IProgressMonitor monitor) throws IOException, InterruptedException {

    monitor.setTaskName(UIText.GitMergeEditorInput_CalculatingDiffTaskName);
    IDiffContainer result = new DiffNode(Differencer.CONFLICTING);

    TreeWalk tw = new TreeWalk(repository);
    try {
      int dirCacheIndex = tw.addTree(new DirCacheIterator(repository
          .readDirCache()));
      int fileTreeIndex = tw.addTree(new FileTreeIterator(repository));
      int repositoryTreeIndex = tw.addTree(rw.parseTree(repository
          .resolve(Constants.HEAD)));

      // skip ignored resources
      NotIgnoredFilter notIgnoredFilter = new NotIgnoredFilter(
          fileTreeIndex);
      // filter by selected resources
      if (filterPaths.size() > 1) {
        List<TreeFilter> suffixFilters = new ArrayList<TreeFilter>();
        for (String filterPath : filterPaths)
          suffixFilters.add(PathFilter.create(filterPath));
        TreeFilter otf = OrTreeFilter.create(suffixFilters);
        tw.setFilter(AndTreeFilter.create(otf, notIgnoredFilter));
      } else if (filterPaths.size() > 0) {
        String path = filterPaths.get(0);
        if (path.length() == 0)
          tw.setFilter(notIgnoredFilter);
        else
          tw.setFilter(AndTreeFilter.create(PathFilter.create(path),
              notIgnoredFilter));
      } else
        tw.setFilter(notIgnoredFilter);

      tw.setRecursive(true);

      while (tw.next()) {
        if (monitor.isCanceled())
          throw new InterruptedException();
        String gitPath = tw.getPathString();
        monitor.setTaskName(gitPath);

        FileTreeIterator fit = tw.getTree(fileTreeIndex,
            FileTreeIterator.class);
        if (fit == null)
          continue;

        DirCacheIterator dit = tw.getTree(dirCacheIndex,
            DirCacheIterator.class);

        final DirCacheEntry dirCacheEntry = dit == null ? null : dit
            .getDirCacheEntry();

        boolean conflicting = dirCacheEntry != null
            && dirCacheEntry.getStage() > 0;

        AbstractTreeIterator rt = tw.getTree(repositoryTreeIndex,
            AbstractTreeIterator.class);

        // compare local file against HEAD to see if it was modified
        boolean modified = rt != null
            && !fit.getEntryObjectId()
                .equals(rt.getEntryObjectId());

        // if this is neither conflicting nor changed, we skip it
        if (!conflicting && !modified)
          continue;

        ITypedElement right;
        if (conflicting) {
          GitFileRevision revision = GitFileRevision.inIndex(
              repository, gitPath, DirCacheEntry.STAGE_3);
          String encoding = CompareCoreUtils.getResourceEncoding(
              repository, gitPath);
          right = new FileRevisionTypedElement(revision, encoding);
        } else
          right = CompareUtils.getFileRevisionTypedElement(gitPath,
              headCommit, repository);

        // can this really happen?
        if (right instanceof EmptyTypedElement)
          continue;

        IFileRevision rev;
        // if the file is not conflicting (as it was auto-merged)
        // we will show the auto-merged (local) version

        Path repositoryPath = new Path(repository.getWorkTree()
            .getAbsolutePath());
        IPath location = repositoryPath
            .append(fit.getEntryPathString());
        IFile file = ResourceUtil.getFileForLocation(location);
        if (!conflicting || useWorkspace) {
          if (file != null)
            rev = new LocalFileRevision(file);
          else
            rev = new WorkingTreeFileRevision(location.toFile());
        } else {
          rev = GitFileRevision.inIndex(repository, gitPath,
              DirCacheEntry.STAGE_2);
        }

        IRunnableContext runnableContext = getContainer();
        if (runnableContext == null)
          runnableContext = PlatformUI.getWorkbench().getProgressService();

        EditableRevision leftEditable;
        if (file != null)
          leftEditable = new ResourceEditableRevision(rev, file,
              runnableContext);
        else
          leftEditable = new LocationEditableRevision(rev, location,
              runnableContext);
        // make sure we don't need a round trip later
        try {
          leftEditable.cacheContents(monitor);
        } catch (CoreException e) {
          throw new IOException(e.getMessage());
        }

        int kind = Differencer.NO_CHANGE;
        if (conflicting)
          kind = Differencer.CONFLICTING;
        else if (modified)
          kind = Differencer.PSEUDO_CONFLICT;

        IDiffContainer fileParent = getFileParent(result,
            repositoryPath, file, location);

        ITypedElement anc;
        if (ancestorCommit != null)
          anc = CompareUtils.getFileRevisionTypedElement(gitPath,
              ancestorCommit, repository);
        else
          anc = null;
        // we get an ugly black icon if we have an EmptyTypedElement
        // instead of null
        if (anc instanceof EmptyTypedElement)
          anc = null;
        // create the node as child
        new DiffNode(fileParent, kind, anc, leftEditable, right);
      }
      return result;
    } finally {
      tw.release();
    }
View Full Code Here

    for (IDiffElement child : parent.getChildren()) {
      if (child.getName().equals(name)) {
        return ((DiffNode) child);
      }
    }
    DiffNode child = new DiffNode(parent, Differencer.NO_CHANGE) {

      @Override
      public String getName() {
        return name;
      }
View Full Code Here

  }

  private DiffNode compare(ITypedElement actLeft, ITypedElement actRight, ITypedElement actAncestor) {
    if (actLeft.getType().equals(ITypedElement.FOLDER_TYPE)) {
      //      return new MyDiffContainer(null, left,right);
      DiffNode diffNode = new DiffNode(null, Differencer.CHANGE,
          actAncestor, actLeft, actRight);
      ITypedElement[] lc = (ITypedElement[])((IStructureComparator)actLeft).getChildren();
      ITypedElement[] rc = (ITypedElement[])((IStructureComparator)actRight).getChildren();
      ITypedElement[] ac = null;
      if (actAncestor != null)
        ac = (ITypedElement[]) ((IStructureComparator) actAncestor)
            .getChildren();
      int li=0;
      int ri=0;
      while (li<lc.length && ri<rc.length) {
        ITypedElement ln = lc[li];
        ITypedElement rn = rc[ri];
        ITypedElement an = null;
        if (ac != null)
          an = ac[ri];
        int compareTo = ln.getName().compareTo(rn.getName());
        // TODO: Git ordering!
        if (compareTo == 0) {
          if (!ln.equals(rn))
            diffNode.add(compare(ln,rn, an));
          ++li;
          ++ri;
        } else if (compareTo < 0) {
          DiffNode childDiffNode = new DiffNode(Differencer.ADDITION, an, ln, null);
          diffNode.add(childDiffNode);
          if (ln.getType().equals(ITypedElement.FOLDER_TYPE)) {
            ITypedElement[] children = (ITypedElement[])((IStructureComparator)ln).getChildren();
            if(children != null && children.length > 0) {
              for (ITypedElement child : children) {
                childDiffNode.add(addDirectoryFiles(child, Differencer.ADDITION));
              }
            }
          }
          ++li;
        } else {
          DiffNode childDiffNode = new DiffNode(Differencer.DELETION, an, null, rn);
          diffNode.add(childDiffNode);
          if (rn.getType().equals(ITypedElement.FOLDER_TYPE)) {
            ITypedElement[] children = (ITypedElement[])((IStructureComparator)rn).getChildren();
            if(children != null && children.length > 0) {
              for (ITypedElement child : children) {
                childDiffNode.add(addDirectoryFiles(child, Differencer.DELETION));
              }
            }
          }
          ++ri;
        }
      }
      while (li<lc.length) {
        ITypedElement ln = lc[li];
        ITypedElement an = null;
        if (ac != null)
          an= ac[li];
        DiffNode childDiffNode = new DiffNode(Differencer.ADDITION, an, ln, null);
        diffNode.add(childDiffNode);
        if (ln.getType().equals(ITypedElement.FOLDER_TYPE)) {
          ITypedElement[] children = (ITypedElement[])((IStructureComparator)ln).getChildren();
          if(children != null && children.length > 0) {
            for (ITypedElement child : children) {
              childDiffNode.add(addDirectoryFiles(child, Differencer.ADDITION));
            }
          }
        }
        ++li;
      }
      while (ri<rc.length) {
        ITypedElement rn = rc[ri];
        ITypedElement an = null;
        if (ac != null)
          an = ac[ri];
        DiffNode childDiffNode = new DiffNode(Differencer.DELETION, an, null, rn);
        diffNode.add(childDiffNode);
        if (rn.getType().equals(ITypedElement.FOLDER_TYPE)) {
          ITypedElement[] children = (ITypedElement[])((IStructureComparator)rn).getChildren();
          if(children != null && children.length > 0) {
            for (ITypedElement child : children) {
              childDiffNode.add(addDirectoryFiles(child, Differencer.DELETION));
            }
          }
        }
        ++ri;
      }
      return diffNode;
    } else {
      if (actAncestor != null)
        return new DiffNode(Differencer.CONFLICTING, actAncestor, actLeft, actRight);
      else
        return new DiffNode(actLeft, actRight);
    }
  }
View Full Code Here

    } else {
      l = elem;
    }

    if (elem.getType().equals(ITypedElement.FOLDER_TYPE)) {
      DiffNode diffNode = null;
      diffNode = new DiffNode(null,Differencer.CHANGE,null,l,r);
      ITypedElement[] children = (ITypedElement[])((IStructureComparator)elem).getChildren();
      for (ITypedElement child : children) {
        diffNode.add(addDirectoryFiles(child, diffType));
      }
      return diffNode;
    } else {
      return new DiffNode(diffType, null, l, r);
    }
  }
View Full Code Here

    initLabels(input);
    setTitle(NLS.bind(UIText.GitCompareFileRevisionEditorInput_CompareInputTitle, new String[] { input.getName() }));

    // The compare editor (Structure Compare) will show the diff filenames
    // with their project relative path. So, no need to also show directory entries.
    DiffNode flatDiffNode = new NotifiableDiffNode(null,
        ancestor != null ? Differencer.CONFLICTING : Differencer.CHANGE, ancestor, left, right);
    flatDiffView(flatDiffNode, (DiffNode) input);

    return flatDiffNode;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.compare.structuremergeviewer.DiffNode

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.