private void getChangedLines(Subscriber s, PatchFile p, IProgressMonitor monitor) {
    try {
      // For an outgoing changed resource, find out which lines
      // differ from the local file and its previous local version
      // (i.e. we don't want to force a diff with the repository).
      IDiff d = s.getDiff(p.getResource());
      if (d instanceof IThreeWayDiff
          && ((IThreeWayDiff) d).getDirection() == IThreeWayDiff.OUTGOING) {
        IThreeWayDiff diff = (IThreeWayDiff) d;
        monitor.beginTask(null, 100);
        IResourceDiff localDiff = (IResourceDiff) diff.getLocalChange();
        IResource resource = localDiff.getResource();
        if (resource instanceof IFile) {
          IFile file = (IFile) resource;
          monitor.subTask(Messages.getString("ChangeLog.MergingDiffs")); // $NON-NLS-1$
          String osEncoding = file.getCharset();
          IFileRevision ancestorState = localDiff.getBeforeState();
          IStorage ancestorStorage;
          if (ancestorState != null) {
            ancestorStorage = ancestorState.getStorage(monitor);
            p.setStorage(ancestorStorage);
          } else ancestorStorage = null;

          try {
            // We compare using a standard differencer to get ranges
            // of changes.  We modify them to be document-based (i.e.
            // first line is line 1) and store them for later parsing.
            LineComparator left = new LineComparator(ancestorStorage.getContents(), osEncoding);
            LineComparator right = new LineComparator(file.getContents(), osEncoding);
            for (RangeDifference tmp : RangeDifferencer.findDifferences(left, right)) {
              if (tmp.kind() == RangeDifference.CHANGE) {
                // Right side of diff are all changes found in local file.
                int rightLength = tmp.rightLength() > 0 ? tmp.rightLength() : tmp.rightLength() + 1;
                // We also want to store left side of the diff which are changes to the ancestor as
                // it may contain
                // functions/methods that have been removed.
                int leftLength = tmp.leftLength() > 0 ? tmp.leftLength() : tmp.leftLength() + 1;
                // Only store left side changes if the storage exists and we add one to the start
                // line number
                if (p.getStorage() != null)
                  p.addLineRange(tmp.leftStart(), tmp.leftStart() + leftLength, false);
                p.addLineRange(tmp.rightStart(), tmp.rightStart() + rightLength, true);
              }
            }
          } catch (UnsupportedEncodingException e) {
            // do nothing for now
          }
        }
        monitor.done();
      }
    } catch (CoreException e) {
      // Do nothing if error occurs
    }
  }
示例#2
0
  public AncestorComparatorResult getResult(AncestorComparator other, Locale locale) {

    AncestorComparatorResult result = new AncestorComparatorResult();

    RangeDifference[] differences = RangeDifferencer.findDifferences(other, this);

    if (differences.length == 0) return result;

    //        ChangeTextGenerator changeTxt = new ChangeTextGenerator(this, other,
    //                locale);

    result.setChanged(true);
    result.setChanges("" /*changeTxt.getChanged(differences).toString()*/);

    return result;
  }