コード例 #1
0
  private void formatOldNewPaths(ByteArrayOutputStream o, DiffEntry ent) throws IOException {
    if (ent.oldId.equals(ent.newId)) return;

    final String oldp;
    final String newp;

    switch (ent.getChangeType()) {
      case ADD:
        oldp = DiffEntry.DEV_NULL;
        newp = quotePath(newPrefix + ent.getNewPath());
        break;

      case DELETE:
        oldp = quotePath(oldPrefix + ent.getOldPath());
        newp = DiffEntry.DEV_NULL;
        break;

      default:
        oldp = quotePath(oldPrefix + ent.getOldPath());
        newp = quotePath(newPrefix + ent.getNewPath());
        break;
    }

    o.write(encode("--- " + oldp + "\n")); // $NON-NLS-1$ //$NON-NLS-2$
    o.write(encode("+++ " + newp + "\n")); // $NON-NLS-1$ //$NON-NLS-2$
  }
コード例 #2
0
 private boolean isAdd(List<DiffEntry> files) {
   String oldPath = ((FollowFilter) pathFilter).getPath();
   for (DiffEntry ent : files) {
     if (ent.getChangeType() == ADD && ent.getNewPath().equals(oldPath)) return true;
   }
   return false;
 }
コード例 #3
0
 private List<DiffEntry> updateFollowFilter(List<DiffEntry> files) {
   String oldPath = ((FollowFilter) pathFilter).getPath();
   for (DiffEntry ent : files) {
     if (isRename(ent) && ent.getNewPath().equals(oldPath)) {
       pathFilter = FollowFilter.create(ent.getOldPath());
       return Collections.singletonList(ent);
     }
   }
   return Collections.emptyList();
 }
コード例 #4
0
  private void formatHeader(ByteArrayOutputStream o, DiffEntry ent) throws IOException {
    final ChangeType type = ent.getChangeType();
    final String oldp = ent.getOldPath();
    final String newp = ent.getNewPath();
    final FileMode oldMode = ent.getOldMode();
    final FileMode newMode = ent.getNewMode();

    formatGitDiffFirstHeaderLine(o, type, oldp, newp);

    switch (type) {
      case ADD:
        o.write(encodeASCII("new file mode ")); // $NON-NLS-1$
        newMode.copyTo(o);
        o.write('\n');
        break;

      case DELETE:
        o.write(encodeASCII("deleted file mode ")); // $NON-NLS-1$
        oldMode.copyTo(o);
        o.write('\n');
        break;

      case RENAME:
        o.write(
            encodeASCII("similarity index " + ent.getScore() + "%")); // $NON-NLS-1$ //$NON-NLS-2$
        o.write('\n');

        o.write(encode("rename from " + quotePath(oldp))); // $NON-NLS-1$
        o.write('\n');

        o.write(encode("rename to " + quotePath(newp))); // $NON-NLS-1$
        o.write('\n');
        break;

      case COPY:
        o.write(
            encodeASCII("similarity index " + ent.getScore() + "%")); // $NON-NLS-1$ //$NON-NLS-2$
        o.write('\n');

        o.write(encode("copy from " + quotePath(oldp))); // $NON-NLS-1$
        o.write('\n');

        o.write(encode("copy to " + quotePath(newp))); // $NON-NLS-1$
        o.write('\n');

        if (!oldMode.equals(newMode)) {
          o.write(encodeASCII("new file mode ")); // $NON-NLS-1$
          newMode.copyTo(o);
          o.write('\n');
        }
        break;

      case MODIFY:
        if (0 < ent.getScore()) {
          o.write(
              encodeASCII(
                  "dissimilarity index " //$NON-NLS-1$
                      + (100 - ent.getScore())
                      + "%")); //$NON-NLS-1$
          o.write('\n');
        }
        break;
    }

    if ((type == MODIFY || type == RENAME) && !oldMode.equals(newMode)) {
      o.write(encodeASCII("old mode ")); // $NON-NLS-1$
      oldMode.copyTo(o);
      o.write('\n');

      o.write(encodeASCII("new mode ")); // $NON-NLS-1$
      newMode.copyTo(o);
      o.write('\n');
    }

    if (!ent.getOldId().equals(ent.getNewId())) {
      formatIndexLine(o, ent);
    }
  }