You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DiffStatFormatter.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2013 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.utils;
  17. import java.io.IOException;
  18. import org.eclipse.jgit.diff.DiffEntry;
  19. import org.eclipse.jgit.diff.DiffFormatter;
  20. import org.eclipse.jgit.diff.RawText;
  21. import org.eclipse.jgit.util.io.NullOutputStream;
  22. import com.gitblit.models.PathModel.PathChangeModel;
  23. import com.gitblit.utils.DiffUtils.DiffStat;
  24. /**
  25. * Calculates a DiffStat.
  26. *
  27. * @author James Moger
  28. *
  29. */
  30. public class DiffStatFormatter extends DiffFormatter {
  31. private final DiffStat diffStat;
  32. private PathChangeModel path;
  33. public DiffStatFormatter(String commitId) {
  34. super(NullOutputStream.INSTANCE);
  35. diffStat = new DiffStat(commitId);
  36. }
  37. @Override
  38. public void format(DiffEntry entry) throws IOException {
  39. path = diffStat.addPath(entry);
  40. super.format(entry);
  41. }
  42. @Override
  43. protected void writeLine(final char prefix, final RawText text, final int cur)
  44. throws IOException {
  45. path.update(prefix);
  46. }
  47. public DiffStat getDiffStat() {
  48. return diffStat;
  49. }
  50. }