| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Enumeration for the diff comparator types.
|
| | | */
|
| | | public static enum DiffComparator {
|
| | | SHOW_WHITESPACE(RawTextComparator.DEFAULT),
|
| | | IGNORE_WHITESPACE(RawTextComparator.WS_IGNORE_ALL),
|
| | | IGNORE_LEADING(RawTextComparator.WS_IGNORE_LEADING),
|
| | | IGNORE_TRAILING(RawTextComparator.WS_IGNORE_TRAILING),
|
| | | IGNORE_CHANGES(RawTextComparator.WS_IGNORE_CHANGE);
|
| | |
|
| | | public final RawTextComparator textComparator;
|
| | |
|
| | | DiffComparator(RawTextComparator textComparator) {
|
| | | this.textComparator = textComparator;
|
| | | }
|
| | |
|
| | | public DiffComparator getOpposite() {
|
| | | return this == SHOW_WHITESPACE ? IGNORE_WHITESPACE : SHOW_WHITESPACE;
|
| | | }
|
| | |
|
| | | public String getTranslationKey() {
|
| | | return "gb." + name().toLowerCase();
|
| | | }
|
| | |
|
| | | public static DiffComparator forName(String name) {
|
| | | for (DiffComparator type : values()) {
|
| | | if (type.name().equalsIgnoreCase(name)) {
|
| | | return type;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Encapsulates the output of a diff.
|
| | | */
|
| | | public static class DiffOutput implements Serializable {
|
| | |
| | | public final List<PathChangeModel> paths = new ArrayList<PathChangeModel>();
|
| | |
|
| | | private final String commitId;
|
| | | |
| | | private final Repository repository;
|
| | |
|
| | | public DiffStat(String commitId) {
|
| | | public DiffStat(String commitId, Repository repository) {
|
| | | this.commitId = commitId;
|
| | | this.repository = repository;
|
| | | }
|
| | |
|
| | | public PathChangeModel addPath(DiffEntry entry) {
|
| | | PathChangeModel pcm = PathChangeModel.from(entry, commitId);
|
| | | PathChangeModel pcm = PathChangeModel.from(entry, commitId, repository);
|
| | | paths.add(pcm);
|
| | | return pcm;
|
| | | }
|
| | |
| | | *
|
| | | * @param repository
|
| | | * @param commit
|
| | | * @param comparator
|
| | | * @param outputType
|
| | | * @param tabLength
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getCommitDiff(Repository repository, RevCommit commit,
|
| | | DiffOutputType outputType) {
|
| | | return getDiff(repository, null, commit, null, outputType);
|
| | | DiffComparator comparator, DiffOutputType outputType, int tabLength) {
|
| | | return getDiff(repository, null, commit, null, comparator, outputType, tabLength);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | *
|
| | | * @param repository
|
| | | * @param commit
|
| | | * @param comparator
|
| | | * @param outputType
|
| | | * @param handler
|
| | | * to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.
|
| | | * May be {@code null}, resulting in the default behavior.
|
| | | * @param tabLength
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getCommitDiff(Repository repository, RevCommit commit,
|
| | | DiffOutputType outputType, BinaryDiffHandler handler) {
|
| | | return getDiff(repository, null, commit, null, outputType, handler);
|
| | | DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler, int tabLength) {
|
| | | return getDiff(repository, null, commit, null, comparator, outputType, handler, tabLength);
|
| | | }
|
| | |
|
| | |
|
| | |
| | | * @param repository
|
| | | * @param commit
|
| | | * @param path
|
| | | * @param comparator
|
| | | * @param outputType
|
| | | * @param tabLength
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getDiff(Repository repository, RevCommit commit, String path,
|
| | | DiffOutputType outputType) {
|
| | | return getDiff(repository, null, commit, path, outputType);
|
| | | DiffComparator comparator, DiffOutputType outputType, int tabLength) {
|
| | | return getDiff(repository, null, commit, path, comparator, outputType, tabLength);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param repository
|
| | | * @param commit
|
| | | * @param path
|
| | | * @param comparator
|
| | | * @param outputType
|
| | | * @param handler
|
| | | * to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.
|
| | | * May be {@code null}, resulting in the default behavior.
|
| | | * @param tabLength
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getDiff(Repository repository, RevCommit commit, String path,
|
| | | DiffOutputType outputType, BinaryDiffHandler handler) {
|
| | | return getDiff(repository, null, commit, path, outputType, handler);
|
| | | DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler, int tabLength) {
|
| | | return getDiff(repository, null, commit, path, comparator, outputType, handler, tabLength);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param repository
|
| | | * @param baseCommit
|
| | | * @param commit
|
| | | * @param comparator
|
| | | * @param outputType
|
| | | * @param tabLength
|
| | | *
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,
|
| | | DiffOutputType outputType) {
|
| | | return getDiff(repository, baseCommit, commit, null, outputType);
|
| | | DiffComparator comparator, DiffOutputType outputType, int tabLength) {
|
| | | return getDiff(repository, baseCommit, commit, null, comparator, outputType, tabLength);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param repository
|
| | | * @param baseCommit
|
| | | * @param commit
|
| | | * @param comparator
|
| | | * @param outputType
|
| | | * @param handler
|
| | | * to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.
|
| | | * May be {@code null}, resulting in the default behavior.
|
| | | * @param tabLength
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,
|
| | | DiffOutputType outputType, BinaryDiffHandler handler) {
|
| | | return getDiff(repository, baseCommit, commit, null, outputType, handler);
|
| | | DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler, int tabLength) {
|
| | | return getDiff(repository, baseCommit, commit, null, comparator, outputType, handler, tabLength);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * if the path is specified, the diff is restricted to that file
|
| | | * or folder. if unspecified, the diff is for the entire commit.
|
| | | * @param outputType
|
| | | * @param diffComparator
|
| | | * @param tabLength
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,
|
| | | String path, DiffOutputType outputType) {
|
| | | return getDiff(repository, baseCommit, commit, path, outputType, null);
|
| | | String path, DiffComparator diffComparator, DiffOutputType outputType, int tabLength) {
|
| | | return getDiff(repository, baseCommit, commit, path, diffComparator, outputType, null, tabLength);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param path
|
| | | * if the path is specified, the diff is restricted to that file
|
| | | * or folder. if unspecified, the diff is for the entire commit.
|
| | | * @param comparator
|
| | | * @param outputType
|
| | | * @param handler
|
| | | * to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.
|
| | | * May be {@code null}, resulting in the default behavior.
|
| | | * @param tabLength
|
| | | * @return the diff
|
| | | */
|
| | | public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit, String path, DiffOutputType outputType,
|
| | | final BinaryDiffHandler handler) {
|
| | | public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit, String path,
|
| | | DiffComparator comparator, DiffOutputType outputType, final BinaryDiffHandler handler, int tabLength) {
|
| | | DiffStat stat = null;
|
| | | String diff = null;
|
| | | try {
|
| | | ByteArrayOutputStream os = null;
|
| | | RawTextComparator cmp = RawTextComparator.DEFAULT;
|
| | |
|
| | | DiffFormatter df;
|
| | | switch (outputType) {
|
| | | case HTML:
|
| | | df = new GitBlitDiffFormatter(commit.getName(), path, handler);
|
| | | df = new GitBlitDiffFormatter(commit.getName(), repository, path, handler, tabLength);
|
| | | break;
|
| | | case PLAIN:
|
| | | default:
|
| | |
| | | break;
|
| | | }
|
| | | df.setRepository(repository);
|
| | | df.setDiffComparator(cmp);
|
| | | df.setDiffComparator((comparator == null ? DiffComparator.SHOW_WHITESPACE : comparator).textComparator);
|
| | | df.setDetectRenames(true);
|
| | |
|
| | | RevTree commitTree = commit.getTree();
|
| | |
| | | DiffStat stat = null;
|
| | | try {
|
| | | RawTextComparator cmp = RawTextComparator.DEFAULT;
|
| | | DiffStatFormatter df = new DiffStatFormatter(commit.getName());
|
| | | DiffStatFormatter df = new DiffStatFormatter(commit.getName(), repository);
|
| | | df.setRepository(repository);
|
| | | df.setDiffComparator(cmp);
|
| | | df.setDetectRenames(true);
|