private void serializeFileDiffList(INodeFile file, OutputStream out) throws IOException {
   FileWithSnapshotFeature sf = file.getFileWithSnapshotFeature();
   if (sf != null) {
     List<FileDiff> diffList = sf.getDiffs().asList();
     SnapshotDiffSection.DiffEntry entry =
         SnapshotDiffSection.DiffEntry.newBuilder()
             .setInodeId(file.getId())
             .setType(Type.FILEDIFF)
             .setNumOfDiff(diffList.size())
             .build();
     entry.writeDelimitedTo(out);
     for (int i = diffList.size() - 1; i >= 0; i--) {
       FileDiff diff = diffList.get(i);
       SnapshotDiffSection.FileDiff.Builder fb =
           SnapshotDiffSection.FileDiff.newBuilder()
               .setSnapshotId(diff.getSnapshotId())
               .setFileSize(diff.getFileSize());
       INodeFileAttributes copy = diff.snapshotINode;
       if (copy != null) {
         fb.setName(ByteString.copyFrom(copy.getLocalNameBytes()))
             .setSnapshotCopy(buildINodeFile(copy, parent.getSaverContext()));
       }
       fb.build().writeDelimitedTo(out);
     }
   }
 }
示例#2
0
 // TODO use jgit API methods as soon as they are available
 private void writePatch(StringBuilder sb, DiffFormatter diffFmt) throws IOException {
   FileDiff[] diffs = FileDiff.compute(walker, commit);
   for (FileDiff diff : diffs) {
     String projectRelativePath = getProjectRelaticePath(diff);
     sb.append("diff --git ")
         .append(projectRelativePath)
         .append(" ") // $NON-NLS-1$ //$NON-NLS-2$
         .append(projectRelativePath)
         .append("\n"); // $NON-NLS-1$
     diff.outputDiff(sb, db, diffFmt, true, true);
   }
 }
示例#3
0
  // TODO use jgit API methods as soon as they are available
  private void writeGitPatch(StringBuilder sb, DiffFormatter diffFmt) throws IOException {

    final SimpleDateFormat dtfmt;
    dtfmt = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US); // $NON-NLS-1$
    dtfmt.setTimeZone(commit.getAuthorIdent().getTimeZone());
    sb.append(UIText.GitHistoryPage_From)
        .append(" ") // $NON-NLS-1$
        .append(commit.getId().getName())
        .append(" ") // $NON-NLS-1$
        .append(dtfmt.format(Long.valueOf(System.currentTimeMillis())))
        .append("\n"); // $NON-NLS-1$
    sb.append(UIText.GitHistoryPage_From)
        .append(": ") // $NON-NLS-1$
        .append(commit.getAuthorIdent().getName())
        .append(" <")
        .append(commit.getAuthorIdent().getEmailAddress()) // $NON-NLS-1$
        .append(">\n"); // $NON-NLS-1$
    sb.append(UIText.GitHistoryPage_Date)
        .append(": ") // $NON-NLS-1$
        .append(dtfmt.format(commit.getAuthorIdent().getWhen()))
        .append("\n"); // $NON-NLS-1$
    sb.append(UIText.GitHistoryPage_Subject)
        .append(": [PATCH] ") // $NON-NLS-1$
        .append(commit.getShortMessage());

    String message = commit.getFullMessage().substring(commit.getShortMessage().length());
    sb.append(message).append("\n\n"); // $NON-NLS-1$

    FileDiff[] diffs = FileDiff.compute(walker, commit);
    for (FileDiff diff : diffs) {
      sb.append("diff --git a")
          .append(IPath.SEPARATOR) // $NON-NLS-1$
          .append(diff.path)
          .append(" b")
          .append(IPath.SEPARATOR) // $NON-NLS-1$
          .append(diff.path)
          .append("\n"); // $NON-NLS-1$
      diff.outputDiff(sb, db, diffFmt, false, false);
    }
    sb.append("\n--\n"); // $NON-NLS-1$
    Bundle bundle = Activator.getDefault().getBundle();
    String name = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
    String version = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
    sb.append(name).append(" ").append(version); // $NON-NLS-1$
  }
  /**
   * If some blocks at the end of the block list no longer belongs to any inode, collect them and
   * update the block list.
   */
  private void collectBlocksAndClear(
      final INodeFile file, final BlocksMapUpdateInfo info, final List<INode> removedINodes) {
    // check if everything is deleted.
    if (isCurrentFileDeleted() && getDiffs().asList().isEmpty()) {
      file.destroyAndCollectBlocks(info, removedINodes);
      return;
    }
    // find max file size.
    final long max;
    if (isCurrentFileDeleted()) {
      final FileDiff last = getDiffs().getLast();
      max = last == null ? 0 : last.getFileSize();
    } else {
      max = file.computeFileSize();
    }

    collectBlocksBeyondMax(file, max, info);
  }