예제 #1
0
 /**
  * @param o the stream the formatter will write line data to
  * @param ent the DiffEntry to create the FileHeader for
  * @throws IOException writing to the supplied stream failed.
  */
 protected void formatIndexLine(OutputStream o, DiffEntry ent) throws IOException {
   o.write(
       encodeASCII(
           "index " // //$NON-NLS-1$
               + format(ent.getOldId()) //
               + ".." // //$NON-NLS-1$
               + format(ent.getNewId())));
   if (ent.getOldMode().equals(ent.getNewMode())) {
     o.write(' ');
     ent.getNewMode().copyTo(o);
   }
   o.write('\n');
 }
예제 #2
0
 private void writeGitLinkDiffText(OutputStream o, DiffEntry ent) throws IOException {
   if (ent.getOldMode() == GITLINK) {
     o.write(
         encodeASCII(
             "-Subproject commit "
                 + ent.getOldId().name() // $NON-NLS-1$
                 + "\n")); //$NON-NLS-1$
   }
   if (ent.getNewMode() == GITLINK) {
     o.write(
         encodeASCII(
             "+Subproject commit "
                 + ent.getNewId().name() // $NON-NLS-1$
                 + "\n")); //$NON-NLS-1$
   }
 }
예제 #3
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);
    }
  }