The Unified and Autonomous Development Platform
Refine source commit page
steve16e53485fa5d
diff --git a/gitop.web/pom.xml b/gitop.web/pom.xmlindex 79e9edf088..30136e06f3 100644--- a/gitop.web/pom.xml+++ b/gitop.web/pom.xml@@ -35,6 +35,7 @@<artifactId>commons.wicket</artifactId><version>1.0.29</version></dependency>+<!-- JERSEY CLIENT --><dependency><groupId>com.sun.jersey</groupId>@@ -175,6 +176,12 @@<version>1.4.2</version></dependency>+ <dependency>+ <groupId>org.apache.commons</groupId>+ <artifactId>commons-exec</artifactId>+ <version>1.1</version>+ </dependency>+</dependencies><repositories>diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/base.css b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/base.cssindex b0f18e18ce..697c9f604e 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/base.css+++ b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/base.css@@ -484,5 +484,4 @@ fieldset[disabled] .btn-inverse.active {.faux-cell { display: table-cell; vertical-align: top; margin: 0; padding: 0; }.faux-cell.sidebar { width: 240px; position: relative; border-right: 1px solid #ddd; }.sidebar-inner { position: relative; width: 240px; }-.faux .content { }diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.cssindex 96a2a6f6d7..96b1666e4e 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css+++ b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css@@ -1,6 +1,8 @@/* MISC */.img-link:hover { text-decoration: none; }+pre, code { font-family: Consolas, 'Liberation Mono', Courier, monospace; }+/* MENU */.menu-ul { list-style: none; margin: 0; padding: 0; }.menu-item { display: block; padding: 5px 10px; color: #666; }@@ -370,9 +372,7 @@ ul.repo-actions { margin: 8px 4px 8px 0; padding: 0; list-style: none; }.source-tree td.message,.source-tree td.age { color: #999; }-.sha { font-family: Consolas, 'Liberation Mono', Courier, monospace; }--.commit-hash { font-family: monospace, serif; }+.commit-hash, .sha { font-family: Consolas, 'Liberation Mono', Courier, monospace; }.commit-hash > a { color: #999; }.commit-hash > a .sha { color: #555; }@@ -414,7 +414,6 @@ table.table-blob { width: 100%; }background: white; border-radius: 0; padding: 0; margin: 0; border: none;white-space: pre; word-break: normal; word-wrap: normal;font-size: 12px; line-height: 18px;- font-family: Consolas, 'Liberation Mono', Courier, monospace;}.code-highlight pre {@@ -476,40 +475,60 @@ table.table-blob { width: 100%; }#diff-toc.open .btn-hide,#diff-toc .btn-show { display: inline-block; }-.diffstat { white-space: nowrap; display: inline-block; font-size: 12px; float: right; color: #888; text-decoration: none;}-.diffstat .additions { color: #008F00; }-.diffstat .deletions { color: #8F0000; }-.diffstat > b { margin-left: 5px; }+.diffstat { white-space: nowrap; display: inline-block; font-size: 12px; line-height: 1; color: #888; text-decoration: none; vertical-align: middle; }+.diffstat .additions, .diffstat .deletions { width: 40px; display: inline-block; text-align: center; overflow: hidden; font-weight: normal; line-height: 1.5;}+.diffstat .additions { background: #35c335; color: #fff; border-radius: 4px 0 0 4px; }+.diffstat .deletions { background: #c33535; color: #fff; border-radius: 0 4px 4px 0; }+a.diffstat:hover { text-decoration: none; }-#files-stat li { padding: 5px 0; border-bottom: 1px solid #ddd; }-#diff-toc .description .icon { color: #999; }+#files-stat li { padding: 5px 0; border-top: 1px solid #ddd; }+#files-stat li:first-child { border-top: none; }+#files-stat .diffstat { float: right; }-#diff-toc .icon-diff-added { color: #6cc644; }-#diff-toc .icon-diff-removed { color: #bd2c00; }+#diff-toc .description .icon { color: #999; }+#diff-toc .icon-diff-added { color: #35c335; }+#diff-toc .icon-diff-removed { color: #c33535; }#diff-toc .icon-diff-renamed { color: #677a85; }-#diff-toc .icon-diff-modified { color: #d0b44c; }--.panel-body.panel-diff { padding: 0; }-.table-source, .table-diff { margin: 0; }-.table-source tbody > tr > td, .table-diff tbody > tr > td { border-top: none; padding: 3px 3px 3px 12px; }--.table-source tbody>tr>td.lineno,-.table-diff tbody>tr>td.lineno { border-right: 1px solid #ddd; width: 1%; color: #999; text-align: right; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: nowrap; padding-left: 6px; }-.table-source pre, .table-diff pre { margin: 0; padding: 0; background: transparent; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; }--.table-diff tr.old > td { background: #fdd; }-.table-diff tr.new > td { background: #dfd; }-.table-diff tbody>tr.old>td.lineno { color: #8f0000; }-.table-diff tbody>tr.new>td.lineno { color: #008f00; }--.table-diff tr.hunkhead > td { background: #eef; }-.table-diff tr.hunkhead td.expandable { border-right: 1px solid #ddd; text-align: center; padding: 0; }--.table-diff tr:hover > td { background: #fea; }--.table-diff td.expandable > a { display: block; color: #999; padding: 3px 0; }-.table-diff td.expandable > a:hover { color: #333; background: #ddf; text-decoration: none; }+#diff-toc .icon-diff-modified { color: #cfaf38; }++.panel-diff { position: relative; }+.panel-diff .panel-body { padding: 0; overflow: auto; overflow-x: auto; overflow-y: hidden; }+.panel-diff .empty-message { padding: 12px; }+.panel-diff .panel-heading .meta { line-height: 30px; height: 30px; font-size: 12px; }+.panel-diff .meta .diffstat { margin-right: 6px; }++.panel-diff .alert { margin: 0; border-width: 0; }+.panel-diff .alert > p { margin-bottom: 9px; }+.panel-diff .alert > pre { background: #fff; }++.diff-line { font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 20px; }+.diff-line:before, .diff-line:after { display: table; content: " "; }+.diff-line:after { clear: both; }+.diff-line .diff-line-nums { float:left; width: 110px; text-align: right; color: #999; overflow: hidden; border-right: 1px solid #ddd; }+.diff-line-nums > .oldnum, .diff-line-nums > .newnum { display: inline-block; padding-right: 4px; width: 50px; white-space: nowrap; }+.diff-line-nums > .oldnum { border-right: 1px solid #ddd;}+.diff-line-nums > .expander { text-align: center; }+.diff-line-nums > .expander a { color: #999; display: block; }+.diff-line-nums > .expander a:hover { color: #333; text-decoration: none; }+.diff-line-nums > .expander em .icon:before { content: ' '; } /* disabled expander */++.diff-line.hunk-head { background: #eef; }++.diff-line.old { background: #fdd; }+.diff-line.new { background: #cfc; }+.diff-line.old .diff-line-nums > .oldnum { color: #8f0000; }+.diff-line.new .diff-line-nums > .newnum { color: #008f00; }++.diff-line:hover, .diff-line.hunk-head:hover { background: #fea; }++.diff-line .diff-line-code { margin-left: 110px; padding: 0 12px; }+.diff-line .diff-line-code pre { background: transparent; margin: 0; padding: 0; word-break: normal; word-wrap: normal; border: none; font-size: 12px; line-height: 20px; white-space: pre; }+.hunk-head .diff-line-code pre { color: #999; }++.diff-line .add-comment { position: absolute; left: 0px; width: 20px; height: 16px; margin-left: -18px; visibility: hidden; }+.diff-line:hover .add-comment { visibility: visible; }+.diff-line .add-comment:hover { text-decoration: none; }/*** GATE KEEPER SETTING PAGEdiff --git a/gitop.web/src/main/java/com/pmease/gitop/web/common/soy/SoyPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/common/soy/SoyPanel.javaindex bc4da4b970..e7b9e60216 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/common/soy/SoyPanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/common/soy/SoyPanel.java@@ -34,10 +34,12 @@ public class SoyPanel extends Panel implements IMarkupResourceStreamProvider,@Overridepublic IResourceStream getMarkupResourceStream(MarkupContainer container,Class<?> containerClass) {+// Stopwatch watch = new Stopwatch().start();StringBuffer sb = new StringBuffer();sb.append("<wicket:panel>");sb.append(evaluateSoyTemplate());sb.append("</wicket:panel>");+// System.out.println("Duration " + watch.elapsedMillis());return new StringResourceStream(sb.toString());}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/common/wicket/bootstrap/Alert.java b/gitop.web/src/main/java/com/pmease/gitop/web/common/wicket/bootstrap/Alert.javaindex 0e5114d51e..8109c6ddd6 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/common/wicket/bootstrap/Alert.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/common/wicket/bootstrap/Alert.java@@ -196,6 +196,11 @@ public class Alert extends GenericPanel<String> {return this;}+ public Alert setMessageEscapeModelStrings(boolean b) {+ message.setEscapeModelStrings(b);+ return this;+ }+@Overrideprotected void onConfigure() {super.onConfigure();diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/util/GitUtils.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/GitUtils.javasimilarity index 98%rename from gitop.web/src/main/java/com/pmease/gitop/web/util/GitUtils.javarename to gitop.web/src/main/java/com/pmease/gitop/web/git/GitUtils.javaindex e2e72d44f5..e3f418e3d8 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/util/GitUtils.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/GitUtils.java@@ -1,4 +1,4 @@-package com.pmease.gitop.web.util;+package com.pmease.gitop.web.git;import java.util.List;import java.util.regex.Pattern;diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/jgit/RepoUtils.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/RepoUtils.javasimilarity index 99%rename from gitop.web/src/main/java/com/pmease/gitop/web/jgit/RepoUtils.javarename to gitop.web/src/main/java/com/pmease/gitop/web/git/RepoUtils.javaindex 08be74efda..eaa3b6b44e 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/jgit/RepoUtils.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/RepoUtils.java@@ -1,4 +1,4 @@-package com.pmease.gitop.web.jgit;+package com.pmease.gitop.web.git;import java.io.File;import java.io.IOException;diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/jgit/RepositoryException.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/RepositoryException.javasimilarity index 89%rename from gitop.web/src/main/java/com/pmease/gitop/web/jgit/RepositoryException.javarename to gitop.web/src/main/java/com/pmease/gitop/web/git/RepositoryException.javaindex 2687b4ac6a..e5c15f6186 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/jgit/RepositoryException.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/RepositoryException.java@@ -1,4 +1,4 @@-package com.pmease.gitop.web.jgit;+package com.pmease.gitop.web.git;public class RepositoryException extends RuntimeException {private static final long serialVersionUID = 1L;diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/AbstractDiffCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/AbstractDiffCommand.javanew file mode 100644index 0000000000..c777f8b2e5--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/AbstractDiffCommand.java@@ -0,0 +1,224 @@+package com.pmease.gitop.web.git.command;++import java.io.File;+import java.util.List;+import java.util.Set;++import com.google.common.base.Strings;+import com.google.common.collect.Sets;+import com.pmease.commons.git.command.GitCommand;+import com.pmease.commons.loader.AppLoader;+import com.pmease.commons.util.execution.Commandline;++public abstract class AbstractDiffCommand<T> extends GitCommand<T> {++ public static enum RenameType {+ NONE, FIND_RENAMES, FIND_COPIES, FIND_COPIES_HEADER+ }++ public static enum WhitespaceType {+ NONE,++ // Ignore changes in whitespace at EOL.+ IGNORE_SPACE_AT_EOL,++ // Ignore changes in amount of whitespace. This ignores whitespace at+ // line end, and considers all other sequences of one or more whitespace+ // characters to be equivalent.+ IGNORE_SPACE_CHANGE,++ // Ignore whitespace when comparing lines. This ignores differences even+ // if one line has whitespace where the other line has none.+ IGNORE_ALL_SPACE,++ // Ignore changes whose lines are all blank.+ IGNORE_BLANK_LINES+ }++ public static enum DiffAlgorithm {+ PATIENCE, MINIMAL, HISTOGRAM, MYERS+ }++ protected String rev;++ protected Set<String> paths = Sets.newLinkedHashSet();++ protected int contextLines;++ protected RenameType renameType = RenameType.FIND_RENAMES;++ protected int threshold = -1;++ protected WhitespaceType whitespaceType = WhitespaceType.NONE;++ protected DiffAlgorithm diffAlgorithm = DiffAlgorithm.MYERS; // git default+++ public AbstractDiffCommand(File repoDir) {+ super(repoDir);+ }++ public AbstractDiffCommand<T> revision(String rev) {+ this.rev = rev;+ return this;+ }++ public AbstractDiffCommand<T> path(String path) {+ this.paths.add(path);+ return this;+ }++ public AbstractDiffCommand<T> paths(List<String> paths) {+ this.paths.addAll(paths);+ return this;+ }++ public AbstractDiffCommand<T> contextLines(int contextLines) {+ this.contextLines = contextLines;+ return this;+ }++ public AbstractDiffCommand<T> findCopiesHarder(boolean b) {+ return renameType(b ? RenameType.FIND_COPIES_HEADER : RenameType.NONE);+ }++ public AbstractDiffCommand<T> findCopies(boolean b) {+ return findCopies(b, -1);+ }++ public AbstractDiffCommand<T> findCopies(boolean b, int threshold) {+ return renameType(b ? RenameType.FIND_COPIES : RenameType.NONE, threshold);+ }++ public AbstractDiffCommand<T> findRenames(boolean b) {+ return findRenames(b, -1);+ }++ public AbstractDiffCommand<T> findRenames(boolean b, int threshold) {+ return renameType(b ? RenameType.FIND_RENAMES : RenameType.NONE, threshold);+ }++ private AbstractDiffCommand<T> renameType(RenameType renameType) {+ return renameType(renameType, -1);+ }++ private AbstractDiffCommand<T> renameType(RenameType renameType, int threshold) {+ this.renameType = renameType;+ this.threshold = threshold;+ return this;+ }++ private AbstractDiffCommand<T> whitespaceType(WhitespaceType whitespaceType) {+ this.whitespaceType = whitespaceType;+ return this;+ }++ public AbstractDiffCommand<T> ignoreSpaceAtEol() {+ return whitespaceType(WhitespaceType.IGNORE_SPACE_AT_EOL);+ }++ public AbstractDiffCommand<T> ignoreAllSpace() {+ return whitespaceType(WhitespaceType.IGNORE_ALL_SPACE);+ }++ public AbstractDiffCommand<T> ignoreBlankLines() {+ return whitespaceType(WhitespaceType.IGNORE_BLANK_LINES);+ }++ public AbstractDiffCommand<T> ignoreSpaceChange() {+ return whitespaceType(WhitespaceType.IGNORE_SPACE_CHANGE);+ }++ public AbstractDiffCommand<T> diffAlgorithm(DiffAlgorithm algorithm) {+ this.diffAlgorithm = algorithm;+ return this;+ }++ @Override+ protected String getGitExe() {+ if (AppLoader.injector == null) {+ return "git";+ } else {+ return super.getGitExe();+ }+ }++ abstract protected String getSubCommand();++ protected Commandline newCommand() {+ Commandline cmd = cmd();+ cmd.addArgs(getSubCommand(), rev, "--full-index", "-p", "--no-color");+ return cmd;+ }++ protected Commandline buildCommand() {+ Commandline cmd = newCommand();++ applyContextLines(cmd);+ applyWhitespaceType(cmd);+ applyRenameType(cmd);+ applyDiffAlgorithm(cmd);++ applyPaths(cmd);++ return cmd;+ }++ protected void applyContextLines(Commandline cmd) {+ if (contextLines > 0) {+ cmd.addArgs("-U" + contextLines);+ }+ }++ protected void applyPaths(Commandline cmd) {+ if (paths.isEmpty())+ return;++ cmd.addArgs("--");+ for (String path : paths) {+ if (!Strings.isNullOrEmpty(path)) {+ cmd.addArgs(path);+ }+ }+ }++ protected void applyWhitespaceType(Commandline cmd) {+ switch (whitespaceType) {+ case IGNORE_SPACE_AT_EOL:+ cmd.addArgs("--ignore-space-at-eol");+ break;++ case IGNORE_SPACE_CHANGE:+ cmd.addArgs("--ignore-space-change");+ break;++ case IGNORE_ALL_SPACE:+ cmd.addArgs("--ignore-all-space");+ break;++ case IGNORE_BLANK_LINES:+ cmd.addArgs("--ignore-blank-lines");+ break;++ default:+ break;+ }+ }++ protected void applyRenameType(Commandline cmd) {+ if (renameType == RenameType.FIND_COPIES_HEADER) {+ cmd.addArgs("--find-copies-harder");+ } else if (renameType == RenameType.FIND_COPIES) {+ cmd.addArgs("-C" + (threshold > 0 ? threshold : ""));+ } else if (renameType == RenameType.FIND_RENAMES) {+ cmd.addArgs("-M" + (threshold > 0 ? threshold : ""));+ }+ }++ protected void applyDiffAlgorithm(Commandline cmd) {+ if (diffAlgorithm != DiffAlgorithm.MYERS) {+ cmd.addArgs("--" + diffAlgorithm.name().toLowerCase());+ }+ }++}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/CatFileCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/CatFileCommand.javanew file mode 100644index 0000000000..9bb583c233--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/CatFileCommand.java@@ -0,0 +1,155 @@+package com.pmease.gitop.web.git.command;++import java.io.ByteArrayOutputStream;+import java.io.File;+import java.io.IOException;+import java.io.InputStream;+import java.io.OutputStream;+import java.util.List;+import java.util.concurrent.Callable;++import org.apache.commons.exec.CommandLine;+import org.apache.commons.exec.DefaultExecutor;+import org.apache.commons.exec.ExecuteException;+import org.apache.commons.exec.LogOutputStream;+import org.apache.commons.exec.PumpStreamHandler;+import org.apache.commons.io.IOUtils;+import org.eclipse.jgit.util.RawParseUtils;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++import com.google.common.base.Joiner;+import com.google.common.base.Throwables;+import com.google.common.collect.Lists;+import com.pmease.commons.git.GitConfig;+import com.pmease.commons.loader.AppLoader;+import com.pmease.gitop.web.git.RepositoryException;+import com.pmease.gitop.web.util.UniversalEncodingDetector;++public class CatFileCommand implements Callable<String> {++ private final File workingDir;++ private String revision;+ private String path;+ private ShowType showType = ShowType.PRETTY;++ static enum ShowType {+ TYPE("-t"), SIZE("-s"), PRETTY("-p");++ final String arg;++ ShowType(String arg) {+ this.arg = arg;+ }+ }++ public CatFileCommand(File dir) {+ this.workingDir = dir;+ }++ public CatFileCommand revision(String revision) {+ this.revision = revision;+ return this;+ }++ public CatFileCommand path(String path) {+ this.path = path;+ return this;+ }++ public CatFileCommand showSize() {+ this.showType = ShowType.SIZE;+ return this;+ }++ public CatFileCommand showType() {+ this.showType = ShowType.TYPE;+ return this;+ }++ public CatFileCommand prettyPrint() {+ this.showType = ShowType.PRETTY;+ return this;+ }++ static class ErrorOutputStream extends LogOutputStream {+ final static Logger log = LoggerFactory.getLogger(ErrorOutputStream.class);++ @Override+ protected void processLine(String line, int level) {+ log.error(line);+ }+ }++ static class LineOutputStream extends LogOutputStream {+ List<String> lines = Lists.newArrayList();++ @Override+ protected void processLine(String line, int level) {+ lines.add(line);+ }++ public Iterable<String> getLines() {+ return lines;+ }++ public String getOutput() {+ return Joiner.on("\n").join(lines);+ }+ }++ @Override+ public String call() {+ CommandLine cmd = new CommandLine(getGitExe());+ cmd.addArguments(new String[] { "cat-file", showType.arg, revision+":"+path });++ DefaultExecutor executor = new DefaultExecutor();+ executor.setWorkingDirectory(workingDir);++ ByteArrayOutputStream out = (ByteArrayOutputStream) getOutputStream();+ OutputStream err = getErrorStream();+ InputStream in = getInputStream();++ PumpStreamHandler streamHandler = new PumpStreamHandler(out, err, in);+ executor.setStreamHandler(streamHandler);++ try {+ int retCode = executor.execute(cmd);+ if (executor.isFailure(retCode)) {+ throw new RepositoryException("Executing command {" + cmd + "} failed with return code " + retCode);+ }++ byte[] bytes = out.toByteArray();+ return RawParseUtils.decode(UniversalEncodingDetector.detect(bytes), bytes);+ } catch (ExecuteException e) {+ throw Throwables.propagate(e);+ } catch (IOException e) {+ throw Throwables.propagate(e);+ } finally {+ IOUtils.closeQuietly(out);+ IOUtils.closeQuietly(err);+ IOUtils.closeQuietly(in);+ }+ }++ protected OutputStream getOutputStream() {+ return new ByteArrayOutputStream(1024);+ }++ protected OutputStream getErrorStream() {+ return new ErrorOutputStream();+ }++ protected InputStream getInputStream() {+ return null;+ }++ protected String getGitExe() {+ if (AppLoader.injector == null) {+ return "/usr/local/bin/git";+ } else {+ return AppLoader.getInstance(GitConfig.class).getExecutable();+ }+ }+}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/DiffTreeCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/DiffTreeCommand.javanew file mode 100644index 0000000000..68f3df1260--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/DiffTreeCommand.java@@ -0,0 +1,78 @@+package com.pmease.gitop.web.git.command;++import java.io.ByteArrayInputStream;+import java.io.ByteArrayOutputStream;+import java.io.File;+import java.io.IOException;++import org.apache.commons.io.IOUtils;++import com.google.common.base.Strings;+import com.google.common.base.Throwables;+import com.google.common.io.ByteStreams;+import com.pmease.commons.util.execution.Commandline;+import com.pmease.gitop.web.page.project.source.commit.patch.Patch;++public class DiffTreeCommand extends AbstractDiffCommand<Patch> {++ boolean recurse;++ public DiffTreeCommand(File repoDir) {+ super(repoDir);+ }++ @Override+ protected Commandline newCommand() {+ Commandline cmd = super.newCommand();+ cmd.addArgs("--root");+ cmd.addArgs("--no-commit-id");++ if (recurse) {+ cmd.addArgs("-r");+ }++ return cmd;+ }++ @Override+ protected void applyPaths(Commandline cmd) {+ cmd.addArgs("--");+ for (String path : paths) {+ if (!Strings.isNullOrEmpty(path)) {+ cmd.addArgs(path);+ }+ }+ }++ public DiffTreeCommand recurse(boolean recurse) {+ this.recurse = recurse;+ return this;+ }++ @Override+ public Patch call() {+ Commandline cmd = buildCommand();++ final Patch patch = new Patch();++ ByteArrayOutputStream out = new ByteArrayOutputStream(2048);+ ByteArrayInputStream in = null;++ try {+ cmd.execute(out, errorLogger);+ in = ByteStreams.newInputStreamSupplier(out.toByteArray()).getInput();+ patch.parse(in);+ return patch;+ } catch (IOException e) {+ throw Throwables.propagate(e);+ } finally {+ IOUtils.closeQuietly(out);+ IOUtils.closeQuietly(in);+ }+ }++ @Override+ protected String getSubCommand() {+ return "diff-tree";+ }+}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/ProjectOptionsPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/ProjectOptionsPage.javaindex 85a062f586..db354cfe1e 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/ProjectOptionsPage.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/settings/ProjectOptionsPage.java@@ -34,9 +34,9 @@ import com.pmease.gitop.web.common.wicket.form.BaseForm;import com.pmease.gitop.web.common.wicket.form.checkbox.CheckBoxElement;import com.pmease.gitop.web.common.wicket.form.select.DropDownChoiceElement;import com.pmease.gitop.web.common.wicket.form.textfield.TextFieldElement;+import com.pmease.gitop.web.git.GitUtils;import com.pmease.gitop.web.page.PageSpec;import com.pmease.gitop.web.page.account.home.AccountHomePage;-import com.pmease.gitop.web.util.GitUtils;@SuppressWarnings("serial")public class ProjectOptionsPage extends AbstractProjectSettingPage {diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/ProjectHomePage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/ProjectHomePage.javaindex c09ae697bb..016736c5cf 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/ProjectHomePage.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/ProjectHomePage.java@@ -5,8 +5,8 @@ import java.util.List;import org.apache.wicket.request.mapper.parameter.PageParameters;+import com.pmease.gitop.web.git.GitUtils;import com.pmease.gitop.web.page.project.source.tree.SourceTreePage;-import com.pmease.gitop.web.util.GitUtils;@SuppressWarnings("serial")public class ProjectHomePage extends SourceTreePage {diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/ContributorsPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/ContributorsPanel.javaindex d5bb9d2a5d..bcc56ad0a8 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/ContributorsPanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/ContributorsPanel.java@@ -89,7 +89,7 @@ public class ContributorsPanel extends Panel {@Overrideprotected void populateItem(ListItem<GitPerson> item) {- item.add(new GitPersonLink("committer", item.getModel(), Mode.AVATAR_ONLY));+ item.add(new GitPersonLink("committer", item.getModel(), Mode.FULL));}});diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.htmlindex cf2f0f7f85..c609855dc4 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.html+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.html@@ -1,25 +1,33 @@<html xmlns:wicket><wicket:panel>- <div class="panel panel-default">- <div class="panel-heading">- <span wicket:id="path"></span>- <a class="btn btn-default"><i class="icon icon-file"></i></a>+ <div class="panel-heading clearfix">+ <div class="pull-left meta">+ <span class="diffstat inline" data-toggle="tooltip" data-placement="right" wicket:id="statspan">+ <b class="additions" wicket:id="additions"></b><b class="deletions" wicket:id="deletions"></b>+ </span>++ <wicket:enclosure>+ <span wicket:id="oldpath"></span> ➞+ </wicket:enclosure>++ <span wicket:id="newpath"></span>+ </div>+ <div class="actions pull-right">+ <a class="btn btn-default btn-sm" wicket:id="bloblink">View file @ <b class="sha" wicket:id="sha"></b></a>+ </div></div>- <div class="panel-body panel-diff">- <table class="table table-diff">- <wicket:container wicket:id="hunk">- <tr class="hunkhead">- <td colspan="2" class="expandable"><a data-toggle="tooltip" title="expand"><i class="icon icon-expand"></i></a></td>- <td><pre wicket:id="head"></pre></td>- </tr>- <tr wicket:id="lines">- <td class="lineno"><span wicket:id="oldLineNo"></span></td>- <td class="lineno"><span wicket:id="newLineNo"></span></td>- <td class="linecode"><pre wicket:id="code"></pre></td>- </tr>- </wicket:container>- </table>+ <div class="panel-body">+ <div wicket:id="diffcontent"></div></div>- </div>++ <wicket:fragment wicket:id="frag">+ <wicket:container wicket:id="loop">+ <wicket:container wicket:id="hunk"></wicket:container>+ </wicket:container>+ </wicket:fragment>++ <wicket:fragment wicket:id="messagefrag">+ <div class="empty-message" wicket:id="message"></div>+ </wicket:fragment></wicket:panel></html>\ No newline at end of filediff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.javaindex 6077cdfdef..975a4bf4cf 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/BlobDiffPanel.java@@ -2,97 +2,229 @@ package com.pmease.gitop.web.page.project.source.commit;import java.util.List;+import org.apache.wicket.AttributeModifier;import org.apache.wicket.Component;-import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;-import org.apache.wicket.markup.html.list.ListItem;-import org.apache.wicket.markup.html.list.ListView;+import org.apache.wicket.markup.html.link.AbstractLink;+import org.apache.wicket.markup.html.link.BookmarkablePageLink;+import org.apache.wicket.markup.html.list.Loop;+import org.apache.wicket.markup.html.list.LoopItem;+import org.apache.wicket.markup.html.panel.Fragment;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;+import org.apache.wicket.model.Model;+import org.eclipse.jgit.diff.DiffEntry.ChangeType;import org.eclipse.jgit.diff.DiffEntry.Side;+import com.google.common.base.Splitter;+import com.google.common.collect.Lists;+import com.pmease.commons.git.Commit;+import com.pmease.commons.util.StringUtils;+import com.pmease.gitop.core.Gitop;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.web.common.wicket.bootstrap.Alert;+import com.pmease.gitop.web.common.wicket.bootstrap.Alert.Type;+import com.pmease.gitop.web.git.GitUtils;+import com.pmease.gitop.web.page.project.source.blob.SourceBlobPage;import com.pmease.gitop.web.page.project.source.commit.patch.FileHeader;+import com.pmease.gitop.web.page.project.source.commit.patch.FileHeader.PatchType;import com.pmease.gitop.web.page.project.source.commit.patch.HunkHeader;-import com.pmease.gitop.web.page.project.source.commit.patch.HunkHeader.AnnotatedLine;-import com.pmease.gitop.web.page.project.source.commit.patch.HunkHeader.LineType;+import com.pmease.gitop.web.service.FileBlob;+import com.pmease.gitop.web.service.FileBlobService;@SuppressWarnings("serial")public class BlobDiffPanel extends Panel {- public BlobDiffPanel(String id, IModel<FileHeader> model) {- super(id, model);+ private final IModel<Commit> commitModel;+ private final IModel<Project> projectModel;+ private final IModel<FileBlob> blobModel;++ public BlobDiffPanel(String id,+ IModel<Project> projectModel,+ IModel<FileHeader> fileModel,+ IModel<Commit> commitModel) {+ super(id, fileModel);++ this.projectModel = projectModel;+ this.commitModel = commitModel;+ this.blobModel = new LoadableDetachableModel<FileBlob>() {++ @Override+ protected FileBlob load() {+ return Gitop.getInstance(FileBlobService.class).get(+ getProject(),+ getCommit().getHash(),+ getFile().getNewPath());+ }+ };}@Overrideprotected void onInitialize() {super.onInitialize();- add(new ListView<HunkHeader>("hunk", new LoadableDetachableModel<List<? extends HunkHeader>>() {+ WebMarkupContainer statspan = new WebMarkupContainer("statspan");+ add(statspan);+ statspan.add(AttributeModifier.replace("title", new AbstractReadOnlyModel<String>() {@Override- protected List<? extends HunkHeader> load() {- return getFile().getHunks();+ public String getObject() {+ return getFile().getDiffStat().toString();}- }) {+ }));++ statspan.add(new Label("additions", new AbstractReadOnlyModel<String>() {+ @Override+ public String getObject() {+ int additions = getFile().getDiffStat().getAdditions();+ return additions > 0 ? "+" + additions : "-";+ }+ }));+ statspan.add(new Label("deletions", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ int deletions = getFile().getDiffStat().getDeletions();+ return deletions > 0 ? "-" + deletions : "-";+ }+ }));++ add(new Label("oldpath", new AbstractReadOnlyModel<String>() {@Override- protected void populateItem(ListItem<HunkHeader> item) {- HunkHeader hunk = item.getModelObject();- item.add(new Label("head",- "@@ -" + hunk.getOldImage().getStartLine()- + "," + hunk.getOldImage().getLineCount()- + " +" + hunk.getNewStartLine()- + ", " + hunk.getNewLineCount() + " @@"));+ public String getObject() {+ return getFile().getPath(Side.OLD);+ }+ }) {+ @Override+ protected void onConfigure() {+ super.onConfigure();- item.add(createLines("lines", item.getModel()));+ this.setVisibilityAllowed(getFile().getChangeType() == ChangeType.RENAME);}});- add(new Label("path", new AbstractReadOnlyModel<String>() {+ add(new Label("newpath", new AbstractReadOnlyModel<String>() {@Overridepublic String getObject() {- return getFile().getPath(Side.NEW);+ if (getFile().getChangeType() == ChangeType.DELETE) {+ return getFile().getPath(Side.OLD);+ } else {+ return getFile().getPath(Side.NEW);+ }}}));- }-- private Component createLines(String id, final IModel<HunkHeader> hunkModel) {- return new ListView<AnnotatedLine>(id, new LoadableDetachableModel<List<AnnotatedLine>>() {+ String path = getFile().getNewPath();+ List<String> paths = Lists.newArrayList(Splitter.on("/").split(path));+ Commit commit = commitModel.getObject();+ AbstractLink blobLink = new BookmarkablePageLink<Void>("bloblink",+ SourceBlobPage.class,+ SourceBlobPage.newParams(projectModel.getObject(),+ commit.getHash(),+ paths));+ blobLink.setVisibilityAllowed(getFile().getChangeType() != ChangeType.DELETE);+ add(blobLink);+ blobLink.add(new Label("sha", Model.of(GitUtils.abbreviateSHA(commit.getHash(), 6))));++ add(createContent("diffcontent"));+ }- @Override- protected List<AnnotatedLine> load() {- return hunkModel.getObject().getAnnotatedLines();- }+ static final int MAX_DIFF_LINES = 10000;+ private Component createContent(String id) {+ List<? extends HunkHeader> hunks = getFile().getHunks();+ if (hunks.isEmpty()+ || getFile().getDiffStat().getTotalChanges() > MAX_DIFF_LINES) {+ return (createMessageLabel("diffcontent"));- }) {+ } else {++ return (createHunks("diffcontent"));+ }+ }++ private Component createMessageLabel(String id) {+ return new Alert(id, new AbstractReadOnlyModel<String>() {@Override- protected void populateItem(ListItem<AnnotatedLine> item) {- AnnotatedLine line = item.getModelObject();- String oldLineNo, newLineNo;- oldLineNo = line.getOldLineNo() > 0 ? "" + line.getOldLineNo() : "";- newLineNo = line.getNewLineNo() > 0 ? "" + line.getNewLineNo() : "";+ public String getObject() {+ FileHeader file = getFile();+ if (file.getChangeType() == ChangeType.RENAME) {+ return "File renamed without changes";+ }- if (line.getLineType() == LineType.OLD) {- oldLineNo = "- " + oldLineNo;- } else if (line.getLineType() == LineType.NEW) {- newLineNo = "+ " + newLineNo;+ if (file.getPatchType() == PatchType.BINARY) {+ return "File is a binary file";}- item.add(new Label("oldLineNo", oldLineNo));- item.add(new Label("newLineNo", newLineNo));- item.add(new Label("code", line.getText()));- item.add(AttributeAppender.append("class", line.getLineType().name().toLowerCase()));+ if (file.getDiffStat().getTotalChanges() > MAX_DIFF_LINES) {+ Commit commit = commitModel.getObject();+ return "<p>"+ + "The diff for this file is too large to render. "+ + "You can run below command to get the diff manually:"+ + "</p> "+ + "<pre><code>"+ + "git diff -C -M " + commit.getHash() + "^.." + commit.getHash() + " -- "+ + StringUtils.quoteArgument(getFile().getNewPath())+ + "</code></pre>";+ }++ return "File is empty";+ }+ }).type(Type.Warning).setCloseButtonVisible(false);+ }++ private Component createHunks(String id) {+ Fragment frag = new Fragment(id, "frag", this);+ frag.setOutputMarkupId(true);+ Loop loop = new Loop("loop", getFile().getHunks().size()) {++ @SuppressWarnings("unchecked")+ @Override+ protected void populateItem(LoopItem item) {+ item.add(new HunkPanel("hunk",+ (IModel<FileHeader>) BlobDiffPanel.this.getDefaultModel(),+ blobModel,+ item.getIndex()));+ item.setRenderBodyOnly(true);}};++ frag.add(loop);+ return frag;}private FileHeader getFile() {- return (FileHeader) getDefaultModelObject();+ return (FileHeader) getDefaultModelObject();+ }++ private Project getProject() {+ return projectModel.getObject();+ }++ private Commit getCommit() {+ return commitModel.getObject();+ }++ @Override+ public void onDetach() {+ if (projectModel != null) {+ projectModel.detach();+ }++ if (commitModel != null) {+ commitModel.detach();+ }++ if (blobModel != null) {+ blobModel.detach();+ }++ super.onDetach();}}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/DiffCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/DiffCommand.javadeleted file mode 100644index cfceb4e3fb..0000000000--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/DiffCommand.java+++ /dev/null@@ -1,88 +0,0 @@-package com.pmease.gitop.web.page.project.source.commit;--import java.io.ByteArrayInputStream;-import java.io.ByteArrayOutputStream;-import java.io.File;-import java.io.IOException;--import org.apache.commons.io.IOUtils;--import com.google.common.base.Throwables;-import com.google.common.io.ByteStreams;-import com.pmease.commons.git.command.GitCommand;-import com.pmease.commons.loader.AppLoader;-import com.pmease.commons.util.execution.Commandline;-import com.pmease.gitop.web.page.project.source.commit.patch.Patch;--public class DiffCommand extends GitCommand<Patch> {-- private String fromRev;-- private String toRev;-- private String path;-- private int contextLines;-- public DiffCommand(File repoDir) {- super(repoDir);- }-- public DiffCommand fromRev(String fromRev) {- this.fromRev = fromRev;- return this;- }-- public DiffCommand toRev(String toRev) {- this.toRev = toRev;- return this;- }-- public DiffCommand path(String path) {- this.path = path;- return this;- }-- public DiffCommand contextLines(int contextLines) {- this.contextLines = contextLines;- return this;- }-- @Override- protected String getGitExe() {- if (AppLoader.injector == null) {- return "/usr/local/bin/git";- } else {- return super.getGitExe();- }- }-- @Override- public Patch call() {- Commandline cmd = cmd();-- cmd.addArgs("diff", fromRev + ".." + toRev, "--full-index", "-p", "--no-color", "--find-renames");-- if (contextLines != 0)- cmd.addArgs("--unified=" + contextLines);- if (path != null)- cmd.addArgs("--", path);-- final Patch patch = new Patch();-- ByteArrayOutputStream out = new ByteArrayOutputStream(2048);- ByteArrayInputStream in = null;-- try {- cmd.execute(out, errorLogger);- in = ByteStreams.newInputStreamSupplier(out.toByteArray()).getInput();- patch.parse(in);- return patch;- } catch (IOException e) {- throw Throwables.propagate(e);- } finally {- IOUtils.closeQuietly(out);- IOUtils.closeQuietly(in);- }- }-}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/HunkPanel.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/HunkPanel.htmlnew file mode 100644index 0000000000..28087922db--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/HunkPanel.html@@ -0,0 +1,37 @@+<html xmlns:wicket>+<wicket:panel>+ <div class="diff-hunk">+ <div class="diff-line hunk-head" wicket:id="hunkhead">+ <div class="diff-line-nums">+ <div class="expander">+ <a wicket:id="expandlink" title="show more lines"><i class="icon icon-expand"></i></a>+ </div>+ </div>+ <div class="diff-line-code">+ <pre wicket:id="head"></pre>+ </div>+ </div>+ <div wicket:id="previouslines"></div>+ <div wicket:id="hunklines"></div>+ </div>++ <wicket:fragment wicket:id="linefrag">+ <div class="diff-line" wicket:id="lines">+ <div class="diff-line-nums">+ <div class="oldnum">+ <span wicket:id="oldlineno"></span>+ </div>+ <div class="newnum">+ <span wicket:id="newlineno"></span>+ </div>+ </div>+ <div class="diff-line-code">+ <a class="add-comment"><i class="icon icon-comment-add"></i></a>+ <pre wicket:id="code"></pre>+ </div>+ </div>+ </wicket:fragment>+++</wicket:panel>+</html>\ No newline at end of filediff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/HunkPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/HunkPanel.javanew file mode 100644index 0000000000..4007995eb5--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/HunkPanel.java@@ -0,0 +1,239 @@+package com.pmease.gitop.web.page.project.source.commit;++import java.util.Collections;+import java.util.List;++import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.markup.html.list.ListItem;+import org.apache.wicket.markup.html.list.ListView;+import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.AbstractReadOnlyModel;+import org.apache.wicket.model.IModel;+import org.apache.wicket.model.LoadableDetachableModel;++import com.google.common.collect.Lists;+import com.pmease.gitop.web.page.project.source.commit.patch.FileHeader;+import com.pmease.gitop.web.page.project.source.commit.patch.HunkHeader;+import com.pmease.gitop.web.page.project.source.commit.patch.HunkLine;+import com.pmease.gitop.web.page.project.source.commit.patch.HunkLine.LineType;+import com.pmease.gitop.web.service.FileBlob;++@SuppressWarnings("serial")+public class HunkPanel extends Panel {++ private final IModel<FileBlob> blobModel;++ private final int hunkIndex;++ private int expandedLines = 0;++ public HunkPanel(String id,+ IModel<FileHeader> model,+ IModel<FileBlob> blobModel,+ final int hunkIndex) {++ super(id, model);++ this.blobModel = blobModel;+ this.hunkIndex = hunkIndex;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ add(createHunkHead());+ add(createPreviousLines());+ add(createHunkLines());+ }++ private Component createPreviousLines() {+ return createHunkLines("previouslines", new LoadableDetachableModel<List<HunkLine>>() {++ @Override+ protected List<HunkLine> load() {+ if (expandedLines > 0) {+ List<HunkLine> lines = Lists.newArrayList();++ // need more context lines+ // line start from 1, not 0+ //+ int oldStart = getActualOldStartLine();+ int newStart = getActualNewStartLine();++ List<String> blobLines = getBlob().getLines();+ for (int i = 0; i < expandedLines; i++) {+ HunkLine line = new HunkLine(+ blobLines.get(newStart + i - 1),+ LineType.CONTEXT,+ oldStart + i,+ newStart + i);+ lines.add(line);+ }+ return lines;+ } else {+ return Collections.emptyList();+ }+ }+ });+ }++ private Component createHunkLines() {+ return createHunkLines("hunklines", new LoadableDetachableModel<List<HunkLine>>() {++ @Override+ protected List<HunkLine> load() {+ return getCurrentHunk().getLines();+ }++ });+ }++ private Component createHunkHead() {+ WebMarkupContainer header = new WebMarkupContainer("hunkhead");+ header.setOutputMarkupId(true);+ header.add(new AjaxLink<Void>("expandlink") {+ @Override+ public void onClick(AjaxRequestTarget target) {+ expandLines();+ onExpand(target);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ int newStartLine = getActualNewStartLine();+ HunkHeader previousHunk = getPreviousHunk();+ int previousStartLine = previousHunk == null ? 1 : previousHunk.getNewStartLine() + previousHunk.getNewLineCount();+ setEnabled(newStartLine > 1 && newStartLine > previousStartLine);+ }+ });++ header.add(new Label("head", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ HunkHeader hunk = getCurrentHunk();+ StringBuffer sb = new StringBuffer();+ sb.append("@@ ");+ int oldStart = getActualOldStartLine();+ int newStart = getActualNewStartLine();+ int oldOffset = expandedLines > 0 ? expandedLines : hunk.getOldImage().getLineCount();+ int newOffset = expandedLines > 0 ? expandedLines : hunk.getNewLineCount();++ sb.append("-").append(oldStart).append(",").append(oldOffset);+ sb.append(" +").append(newStart).append(",").append(newOffset);+ sb.append(" @@");+ return sb.toString();+ }+ }));++ return header;+ }++ private void expandLines() {+ expandedLines += 20;++ int startLine = getCurrentHunk().getNewStartLine();+ startLine -= expandedLines;+ startLine = Math.max(1, startLine);+ HunkHeader previous = getPreviousHunk();+ if (previous != null) {+ startLine = Math.max(previous.getNewStartLine() + previous.getNewLineCount(), startLine);+ }++ expandedLines = getCurrentHunk().getNewStartLine() - startLine;+ }++ Component createHunkLines(String id, IModel<List<HunkLine>> linesModel) {+ Fragment frag = new Fragment(id, "linefrag", this);+ frag.setOutputMarkupId(true);+ frag.add(new ListView<HunkLine>("lines", linesModel) {++ @Override+ protected void populateItem(ListItem<HunkLine> item) {+ HunkLine line = item.getModelObject();+ item.add(AttributeAppender.append("class", line.getLineType().name().toLowerCase()));++ String oldLineNo, newLineNo;+ if (line.getLineType() == LineType.CONTEXT) {+ oldLineNo = String.valueOf(line.getOldLineNo());+ newLineNo = String.valueOf(line.getNewLineNo());+ } else if (line.getLineType() == LineType.OLD) {+ oldLineNo = "- " + line.getOldLineNo();+ newLineNo = " ";+ } else {+ oldLineNo = " ";+ newLineNo = "+ " + line.getNewLineNo();+ }++ item.add(new Label("oldlineno", oldLineNo).setEscapeModelStrings(false));+ item.add(new Label("newlineno", newLineNo).setEscapeModelStrings(false));+ item.add(new Label("code", line.getText()));+ }++ });++ return frag;+ }++ private int getActualOldStartLine() {+ HunkHeader currentHunk = getCurrentHunk();+ return currentHunk.getOldImage().getStartLine() - expandedLines;+ }++ private int getActualNewStartLine() {+ return getCurrentHunk().getNewStartLine() - expandedLines;+ }++ private HunkHeader getCurrentHunk() {+ return getHunk(hunkIndex);+ }++ private HunkHeader getPreviousHunk() {+ if (hunkIndex > 0) {+ return getHunk(hunkIndex - 1);+ } else {+ return null;+ }+ }++ private HunkHeader getHunk(int index) {+ FileHeader file = getFile();+ return file.getHunks().get(index);+ }++ private FileHeader getFile() {+ return (FileHeader) getDefaultModelObject();+ }++ private FileBlob getBlob() {+ return blobModel.getObject();+ }++ private void onExpand(AjaxRequestTarget target) {+ Component head = createHunkHead();+ addOrReplace(head);+ target.add(head);++ Component previousLines = createPreviousLines();+ addOrReplace(previousLines);+ target.add(previousLines);+ }++ @Override+ public void onDetach() {+ if (blobModel != null) {+ blobModel.detach();+ }++ super.onDetach();+ }+}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.htmlindex 128ec95876..18131d5922 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.html+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.html@@ -32,11 +32,11 @@</div><div id="diff-toc">- <p class="description clearfix">- <i class="icon icon-diff"></i>- Showing <strong><span wicket:id="changes"></span> changed files</strong>- with <strong><span wicket:id="additions">1</span> additions</strong>- and <strong><span wicket:id="deletions">1</span> deletions</strong>+ <p class="diff-summary clearfix">+ <i class="icon icon-diff text-muted"></i>+ <b wicket:id="changes"></b> files changed /+ <b class="additions"><span wicket:id="additions">1</span></b> additions /+ <b class="deletions"><span wicket:id="deletions">1</span></b> deletions<a class="btn btn-sm btn-gray btn-show" data-toggle="collapse" data-target="#files-stat">Show Diff Stats</a><a class="btn btn-sm btn-gray btn-hide" data-toggle="collapse" data-target="#files-stat">Hide Diff Stats</a>@@ -46,16 +46,23 @@<ul class="list-unstyled"><li wicket:id="files"><i class="" wicket:id="icon"></i>- <a wicket:id="file"><span wicket:id="path"></span></a>- <a class="diffstat"><b class="additions" wicket:id="additions"></b> <b class="deletions" wicket:id="deletions"></b></a>+ <a wicket:id="link">+ <wicket:enclosure>+ <span wicket:id="oldpath"></span> ➞+ </wicket:enclosure>+ <span wicket:id="path"></span>+ </a>+ <a class="diffstat" wicket:id="statlink" data-toggle="tooltip" data-placement="left">+ <b class="additions" wicket:id="additions"></b><b class="deletions" wicket:id="deletions"></b>+ </a></li></ul></div></div>- <wicket:container wicket:id="filelist">- <div wicket:id="file"></div>- </wicket:container>+ <div class="panel panel-default panel-diff" wicket:id="filelist">+ <wicket:container wicket:id="file"></wicket:container>+ </div></div></wicket:extend></html>\ No newline at end of filediff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.javaindex df28361b1c..273410056c 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/SourceCommitPage.java@@ -21,7 +21,6 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;import org.eclipse.jgit.diff.DiffEntry.ChangeType;import com.google.common.base.Objects;-import com.google.common.base.Splitter;import com.google.common.collect.Lists;import com.pmease.commons.git.Commit;import com.pmease.gitop.model.Project;@@ -30,13 +29,13 @@ import com.pmease.gitop.web.component.avatar.GitPersonAvatar;import com.pmease.gitop.web.component.label.AgeLabel;import com.pmease.gitop.web.component.link.GitPersonLink;import com.pmease.gitop.web.component.link.GitPersonLink.Mode;+import com.pmease.gitop.web.git.GitUtils;+import com.pmease.gitop.web.git.command.DiffTreeCommand;import com.pmease.gitop.web.page.PageSpec;import com.pmease.gitop.web.page.project.ProjectCategoryPage;import com.pmease.gitop.web.page.project.api.GitPerson;-import com.pmease.gitop.web.page.project.source.blob.SourceBlobPage;import com.pmease.gitop.web.page.project.source.commit.patch.FileHeader;import com.pmease.gitop.web.page.project.source.commit.patch.Patch;-import com.pmease.gitop.web.util.GitUtils;@SuppressWarnings("serial")public class SourceCommitPage extends ProjectCategoryPage {@@ -68,12 +67,20 @@ public class SourceCommitPage extends ProjectCategoryPage {@Overrideprotected Patch load() {- String toRev = getRevision();- String fromRev = toRev + "^";- Patch patch = new DiffCommand(getProject().code().repoDir())- .fromRev(fromRev)- .toRev(toRev)+ Commit commit = commitModel.getObject();++ String rev;+ if (commit.getParentHashes().isEmpty()) {+ // no parent, initial commit+ rev = getRevision();+ } else {+ rev = getRevision() + "^.." + getRevision();+ }++ Patch patch = new DiffTreeCommand(getProject().code().repoDir())+ .revision(rev).contextLines(DEFAULT_CONTEXT_LINES)+ .findRenames(true).call();return patch;}@@ -169,18 +176,26 @@ public class SourceCommitPage extends ProjectCategoryPage {createDiffToc();- add(new ListView<FileHeader>("filelist", new LoadableDetachableModel<List<? extends FileHeader>>() {+ IModel<List<? extends FileHeader>> model = new LoadableDetachableModel<List<? extends FileHeader>>() {@Overrideprotected List<? extends FileHeader> load() {- return getDiffPatch().getFiles();+ List<? extends FileHeader> total = getDiffPatch().getFiles();+ if (total.size() > 300) {+ return Lists.newArrayList(total.subList(0, 300));+ } else {+ return total;+ }}- }) {+ };++ add(new ListView<FileHeader>("filelist", model) {@Overrideprotected void populateItem(ListItem<FileHeader> item) {- item.add(new BlobDiffPanel("file", item.getModel()));+ item.setMarkupId("diff-" + item.getIndex());+ item.add(new BlobDiffPanel("file", projectModel, item.getModel(), commitModel));}});@@ -229,24 +244,21 @@ public class SourceCommitPage extends ProjectCategoryPage {FileHeader file = item.getModelObject();ChangeType changeType = file.getChangeType();item.add(new Icon("icon", getChangeIcon(changeType)).add(AttributeModifier.replace("title", changeType.name())));- String path;- if (changeType == ChangeType.DELETE) {- path = file.getOldPath();- } else {- path = file.getNewPath();- }+ WebMarkupContainer link = new WebMarkupContainer("link");+ link.add(AttributeModifier.replace("href", "#diff-" + item.getIndex()));+ item.add(link);+ link.add(new Label("oldpath", Model.of(file.getOldPath())).setVisibilityAllowed(file.getChangeType() == ChangeType.RENAME));+ link.add(new Label("path", Model.of(file.getNewPath())));- List<String> paths = Lists.newArrayList(Splitter.on("/").split(path));- BookmarkablePageLink<?> link = new BookmarkablePageLink<Void>("file",- SourceBlobPage.class,- SourceBlobPage.newParams(getProject(), getRevision(), paths));+ WebMarkupContainer statlink = new WebMarkupContainer("statlink");+ statlink.add(AttributeModifier.replace("href", "#diff-" + item.getIndex()));+ statlink.add(AttributeModifier.replace("title", file.getDiffStat().toString()));- link.add(new Label("path", path));- item.add(link);- item.add(new Label("additions", Model.of(+ item.add(statlink);+ statlink.add(new Label("additions", Model.of(file.getDiffStat().getAdditions() > 0 ?"+" + file.getDiffStat().getAdditions() : "-")));- item.add(new Label("deletions", Model.of(+ statlink.add(new Label("deletions", Model.of(file.getDiffStat().getDeletions() > 0 ?"-" + file.getDiffStat().getDeletions() : "-")));}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/blob.diff.soy b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/blob.diff.soynew file mode 100644index 0000000000..eaa99fd4ae--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/blob.diff.soy@@ -0,0 +1,27 @@+{namespace gitop.component.commit}++/**+ * @param file+ */+{template .filediff}+ <div class="annotated">+ {foreach $hunk in $file.hunks}+ {call .hunk data="all"}+ {param hunk: $hunk /}+ {/call}+ {ifempty}+ <div class="empty-message">No diff</div>+ {/foreach}+ </div>+{/template}++/**+ * @param hunk+ */+{template .hunk}+ {foreach $line in $hunk.annotatedLines}+ <div class="lineno old">{$line.oldLineNo > 0 ? $line.oldLineNo : ''}</div>+ <div class="lineno new">{$line.newLineNo > 0 ? $line.newLineNo : ''}</div>+ <div class="linecode"><pre>{$line.text}{if $line.noNewLine} no new line{/if}</pre></div>+ {/foreach}+{/template}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/DiffStat.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/DiffStat.javaindex 3ddffd40b0..d4e3715986 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/DiffStat.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/DiffStat.java@@ -8,15 +8,16 @@ public class DiffStat {return additions;}- public void setAdditions(int additions) {- this.additions = additions;- }-public int getDeletions() {return deletions;}- public void setDeletions(int deletions) {- this.deletions = deletions;+ public int getTotalChanges() {+ return additions + deletions;+ }++ @Override+ public String toString() {+ return additions + " additions & " + deletions + " deletions";}}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/HunkHeader.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/HunkHeader.javaindex 2d0f1940aa..d509563af3 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/HunkHeader.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/HunkHeader.java@@ -4,11 +4,14 @@ import static org.eclipse.jgit.util.RawParseUtils.match;import static org.eclipse.jgit.util.RawParseUtils.nextLF;import static org.eclipse.jgit.util.RawParseUtils.parseBase10;+import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.OutputStream;+import java.nio.charset.Charset;import java.text.MessageFormat;import java.util.List;+import org.apache.commons.io.IOUtils;import org.eclipse.jgit.diff.Edit;import org.eclipse.jgit.diff.EditList;import org.eclipse.jgit.internal.JGitText;@@ -16,7 +19,11 @@ import org.eclipse.jgit.lib.AbbreviatedObjectId;import org.eclipse.jgit.util.MutableInteger;import org.eclipse.jgit.util.RawParseUtils;+import com.google.common.base.Throwables;import com.google.common.collect.Lists;+import com.google.common.io.ByteStreams;+import com.pmease.gitop.web.page.project.source.commit.patch.HunkLine.LineType;+import com.pmease.gitop.web.util.UniversalEncodingDetector;/** Hunk header describing the layout of a single block of lines */public class HunkHeader {@@ -197,6 +204,8 @@ public class HunkHeader {return editList;}+ String hunkFunction;+void parseHeader() {// Parse "@@ -236,9 +236,9 @@ protected boolean"//@@ -214,67 +223,42 @@ public class HunkHeader {newLineCount = parseBase10(buf, ptr.value + 1, ptr);elsenewLineCount = 1;- }-- public static enum LineType {- CONTEXT, OLD, NEW, NO_NEWLINE- }-- public static class AnnotatedLine {- final String text;- final LineType lineType;- final int oldLineNo;- final int newLineNo;-- AnnotatedLine(String text, LineType lineType, int oldLineNo, int newLineNo) {- this.text = text;- this.lineType = lineType;- this.oldLineNo = oldLineNo;- this.newLineNo = newLineNo;- }-- public String getText() {- return text;- }--- public LineType getLineType() {- return lineType;- }-- public int getOldLineNo() {- return oldLineNo;- }- public int getNewLineNo() {- return newLineNo;+ // decode from " @@ protected boolean"+ //+ this.hunkFunction = RawParseUtils.decode(buf, ptr.value + 4, nextLF(buf, ptr.value));+ if (this.hunkFunction.endsWith("\n")) {+ this.hunkFunction = this.hunkFunction.substring(0, hunkFunction.length() - 1);}+ }- @Override- public String toString() {- switch (lineType) {- case CONTEXT:- return " " + text;- case OLD:- return "-" + text;- case NEW:- return "+" + text;- case NO_NEWLINE:- return "\\ No newline at the end of file";- default:- throw new IllegalArgumentException();- }- }+ public String getHunkFunction() {+ return hunkFunction;}- List<AnnotatedLine> lines = Lists.newArrayList();+ List<HunkLine> lines = Lists.newArrayList();- public List<AnnotatedLine> getAnnotatedLines() {+ public List<HunkLine> getLines() {return lines;}+ public Charset getCharset() {+ ByteArrayInputStream bas = null;+ try {+ bas = ByteStreams.newInputStreamSupplier(file.buf).getInput();+ return UniversalEncodingDetector.detect(bas);+ } catch (IOException e) {+ throw Throwables.propagate(e);+ } finally {+ IOUtils.closeQuietly(bas);+ }+ }+int parseBody(final Patch script, final int end) {final byte[] buf = file.buf;++ Charset charset = getCharset();+int c = nextLF(buf, startOffset), last = c;old.nDeleted = 0;@@ -283,6 +267,7 @@ public class HunkHeader {int oldLineNo = old.startLine;int newLineNo = newStartLine;+ HunkLine al = null;SCAN: for (; c < end; last = c, c = nextLF(buf, c)) {String line;int eol;@@ -291,8 +276,9 @@ public class HunkHeader {case '\n':nContext++;eol = nextLF(buf, c);- line = RawParseUtils.decode(buf, c + 1, eol - 1);- lines.add(new AnnotatedLine(line, LineType.CONTEXT, oldLineNo, newLineNo));+ line = RawParseUtils.decode(charset, buf, c + 1, eol - 1);+ al = new HunkLine(line, LineType.CONTEXT, oldLineNo, newLineNo);+ lines.add(al);oldLineNo++;newLineNo++;continue;@@ -300,8 +286,9 @@ public class HunkHeader {case '-':old.nDeleted++;eol = nextLF(buf, c);- line = RawParseUtils.decode(buf, c + 1, eol - 1);- lines.add(new AnnotatedLine(line, LineType.OLD, oldLineNo, -1));+ line = RawParseUtils.decode(charset, buf, c + 1, eol - 1);+ al = new HunkLine(line, LineType.OLD, oldLineNo, -1);+ lines.add(al);file.diffStat.deletions++;script.diffStat.deletions++;oldLineNo++;@@ -310,19 +297,20 @@ public class HunkHeader {case '+':old.nAdded++;eol = nextLF(buf, c);- line = RawParseUtils.decode(buf, c + 1, eol - 1);- lines.add(new AnnotatedLine(line, LineType.NEW, -1, newLineNo));+ line = RawParseUtils.decode(charset, buf, c + 1, eol - 1);+ al = new HunkLine(line, LineType.NEW, -1, newLineNo);+ lines.add(al);file.diffStat.additions++;script.diffStat.additions++;newLineNo++;continue;case '\\': // Matches "\ No newline at end of file"- // TODO: no newline can occurred on either side, old line or new line+ // no newline can occurred on either side, old line or new line//- lines.add(new AnnotatedLine("", LineType.NO_NEWLINE, oldLineNo, newLineNo));- oldLineNo++;- newLineNo++;+ if (al != null) {+ al.noNewLine = true;+ }continue;default:diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/HunkLine.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/HunkLine.javanew file mode 100644index 0000000000..e2e5f7b97a--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/patch/HunkLine.java@@ -0,0 +1,69 @@+package com.pmease.gitop.web.page.project.source.commit.patch;++import java.io.Serializable;++@SuppressWarnings("serial")+public class HunkLine implements Serializable {++ public static enum LineType {+ CONTEXT,+ OLD,+ NEW+ }++ final String text;+ final LineType lineType;+ final int oldLineNo;+ final int newLineNo;++ boolean noNewLine = false;++ public HunkLine(String text, LineType lineType, int oldLineNo, int newLineNo) {+ this.text = text;+ this.lineType = lineType;+ this.oldLineNo = oldLineNo;+ this.newLineNo = newLineNo;+ }++ public boolean isNoNewLine() {+ return noNewLine;+ }++ public void setNoNewLine(boolean noNewLine) {+ this.noNewLine = noNewLine;+ }++ public String getText() {+ return text;+ }++ public LineType getLineType() {+ return lineType;+ }++ public int getOldLineNo() {+ return oldLineNo;+ }++ public int getNewLineNo() {+ return newLineNo;+ }++ @Override+ public String toString() {+ switch (lineType) {++ case CONTEXT:+ return " " + text;++ case OLD:+ return "-" + text;++ case NEW:+ return "+" + text;++ default:+ throw new IllegalArgumentException();+ }+ }+}\ No newline at end of filediff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commits/CommitsPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commits/CommitsPanel.javaindex f61524bf92..ded54a7b56 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commits/CommitsPanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commits/CommitsPanel.java@@ -26,10 +26,10 @@ import com.pmease.gitop.web.common.datatype.DataTypes;import com.pmease.gitop.web.component.label.AgeLabel;import com.pmease.gitop.web.component.link.GitPersonLink;import com.pmease.gitop.web.component.link.GitPersonLink.Mode;+import com.pmease.gitop.web.git.GitUtils;import com.pmease.gitop.web.page.project.api.GitPerson;import com.pmease.gitop.web.page.project.source.commit.SourceCommitPage;import com.pmease.gitop.web.page.project.source.tree.SourceTreePage;-import com.pmease.gitop.web.util.GitUtils;@SuppressWarnings("serial")public class CommitsPanel extends Panel {diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/component/RevisionSelector.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/component/RevisionSelector.javaindex 230bb24f84..78a8137208 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/component/RevisionSelector.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/component/RevisionSelector.java@@ -34,10 +34,10 @@ import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;import com.pmease.gitop.model.Project;import com.pmease.gitop.web.common.wicket.bootstrap.Icon;import com.pmease.gitop.web.common.wicket.component.tab.BootstrapTabbedPanel;+import com.pmease.gitop.web.git.GitUtils;import com.pmease.gitop.web.page.PageSpec;import com.pmease.gitop.web.page.project.source.ProjectHomePage;import com.pmease.gitop.web.page.project.source.tree.SourceTreePage;-import com.pmease.gitop.web.util.GitUtils;@SuppressWarnings("serial")public class RevisionSelector extends AbstractSourcePagePanel {diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.javaindex e5b0d8257c..e7b9855517 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.java@@ -31,12 +31,12 @@ import com.pmease.gitop.web.common.wicket.bootstrap.Icon;import com.pmease.gitop.web.component.label.AgeLabel;import com.pmease.gitop.web.component.link.GitPersonLink;import com.pmease.gitop.web.component.link.GitPersonLink.Mode;+import com.pmease.gitop.web.git.GitUtils;import com.pmease.gitop.web.page.PageSpec;import com.pmease.gitop.web.page.project.api.GitPerson;import com.pmease.gitop.web.page.project.source.blob.SourceBlobPage;import com.pmease.gitop.web.page.project.source.commit.SourceCommitPage;import com.pmease.gitop.web.page.project.source.component.AbstractSourcePagePanel;-import com.pmease.gitop.web.util.GitUtils;@SuppressWarnings("serial")public class SourceTreePanel extends AbstractSourcePagePanel {diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.java b/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.javaindex 479f440c0c..14af8bf65c 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.java@@ -11,6 +11,7 @@ import javax.annotation.Nullable;import org.apache.commons.io.FilenameUtils;import org.apache.tika.mime.MediaType;import org.eclipse.jgit.lib.FileMode;+import org.eclipse.jgit.util.RawParseUtils;import com.google.common.base.Objects;import com.google.common.base.Preconditions;@@ -90,11 +91,7 @@ public class FileBlob implements Serializable {return null;}- if (charset != null) {- return new String(data, charset);- } else {- return new String(data);- }+ return RawParseUtils.decode(charset, data);}public List<String> getLines() {diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/DefaultFileBlobService.java b/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/DefaultFileBlobService.javaindex d2fe0ccd98..e4eeeebc71 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/DefaultFileBlobService.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/DefaultFileBlobService.java@@ -22,8 +22,8 @@ import org.gitective.core.CommitUtils;import com.google.common.base.Objects;import com.google.common.io.ByteStreams;import com.pmease.gitop.model.Project;-import com.pmease.gitop.web.jgit.RepoUtils;-import com.pmease.gitop.web.jgit.RepositoryException;+import com.pmease.gitop.web.git.RepoUtils;+import com.pmease.gitop.web.git.RepositoryException;import com.pmease.gitop.web.service.FileBlob;import com.pmease.gitop.web.service.FileBlobService;import com.pmease.gitop.web.service.FileTypes;diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.java b/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.javaindex f61d02f3ca..c35c71d3ac 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.java@@ -1,5 +1,6 @@package com.pmease.gitop.web.util;+import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import java.nio.charset.Charset;@@ -7,6 +8,8 @@ import java.nio.charset.Charset;import org.apache.tika.metadata.Metadata;import org.mozilla.universalchardet.UniversalDetector;+import com.google.common.io.Closeables;+/*** Copied from tika UniversalEncodingDetector*@@ -46,6 +49,15 @@ public class UniversalEncodingDetector {}}+ public static Charset detect(byte[] buffer) throws IOException {+ ByteArrayInputStream in = new ByteArrayInputStream(buffer); //ByteStreams.newInputStreamSupplier(buffer).getInput();+ try {+ return detect(in);+ } finally {+ Closeables.close(in, false);+ }+ }+public static boolean isBinary(InputStream in) throws IOException {byte[] buf = new byte[4];in.mark(5);diff --git a/gitop.web/src/test/java/com/pmease/gitop/web/util/CommitTest.java b/gitop.web/src/test/java/com/pmease/gitop/web/util/CommitTest.javadeleted file mode 100644index 5504e2e242..0000000000--- a/gitop.web/src/test/java/com/pmease/gitop/web/util/CommitTest.java+++ /dev/null@@ -1,26 +0,0 @@-package com.pmease.gitop.web.util;--import java.io.File;-import java.io.IOException;--import org.eclipse.jgit.api.Git;-import org.eclipse.jgit.api.errors.GitAPIException;-import org.eclipse.jgit.api.errors.NoHeadException;-import org.eclipse.jgit.revwalk.RevCommit;-import org.gitective.core.CommitUtils;-import org.junit.Test;--public class CommitTest {-- static File gitDir = new File("/Users/zhenyu/data/gitop/projects/3/code");-- @Test public void testLog() throws IOException, NoHeadException, GitAPIException {- Git git = Git.open(gitDir);- Iterable<RevCommit> it = git.log().setMaxCount(25).add(CommitUtils.getCommit(git.getRepository(), "v3.9-rc6"))- .call();-- for (RevCommit each : it) {- System.out.println(each.getCommitterIdent().getWhen() + "\t" + each.getShortMessage());- }- }-}diff --git a/gitop.web/src/test/java/com/pmease/gitop/web/util/PatchTest.java b/gitop.web/src/test/java/com/pmease/gitop/web/util/PatchTest.javadeleted file mode 100644index 7d17cf9326..0000000000--- a/gitop.web/src/test/java/com/pmease/gitop/web/util/PatchTest.java+++ /dev/null@@ -1,38 +0,0 @@-package com.pmease.gitop.web.util;--import java.io.File;-import java.util.List;--import org.apache.commons.lang3.StringUtils;-import org.junit.Test;--import com.pmease.gitop.web.page.project.source.commit.DiffCommand;-import com.pmease.gitop.web.page.project.source.commit.patch.FileHeader;-import com.pmease.gitop.web.page.project.source.commit.patch.HunkHeader;-import com.pmease.gitop.web.page.project.source.commit.patch.HunkHeader.AnnotatedLine;-import com.pmease.gitop.web.page.project.source.commit.patch.Patch;--public class PatchTest {-- @Test public void testPatch() {- DiffCommand cmd = new DiffCommand(new File("/Users/zhenyu/temp/aaa"));- cmd.fromRev("9477cf0^").toRev("9477cf0");- Patch patch = cmd.call();-- List<? extends FileHeader> files = patch.getFiles();- for (FileHeader each : files) {- List<? extends HunkHeader> hunks = each.getHunks();- for (HunkHeader hunk : hunks) {- List<AnnotatedLine> lines = hunk.getAnnotatedLines();- for (AnnotatedLine line : lines) {- System.out.println(line);- }- System.out.println(StringUtils.repeat('=', 72));- }-- System.out.println(StringUtils.repeat('*', 72));- System.out.println();- System.out.println();- }- }-}