From 75a907eeabb2983bda2bd1081eacb8a7d94db63b Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 24 Nov 2014 09:34:46 -0500
Subject: [PATCH] Add .bat and .cmd to the pretty print extensions

---
 src/main/java/com/gitblit/wicket/pages/ComparePage.java |   70 +++++++++++++++++++++++-----------
 1 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.java b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
index a513f00..62ae7c2 100644
--- a/src/main/java/com/gitblit/wicket/pages/ComparePage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
@@ -37,23 +37,27 @@
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
 
+import com.gitblit.Keys;
 import com.gitblit.models.PathModel.PathChangeModel;
 import com.gitblit.models.RefModel;
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.SubmoduleModel;
+import com.gitblit.servlet.RawServlet;
 import com.gitblit.utils.DiffUtils;
+import com.gitblit.utils.DiffUtils.DiffOutput;
 import com.gitblit.utils.DiffUtils.DiffOutputType;
 import com.gitblit.utils.JGitUtils;
 import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.SessionlessForm;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.panels.CommitLegendPanel;
+import com.gitblit.wicket.panels.DiffStatPanel;
 import com.gitblit.wicket.panels.LinkPanel;
 import com.gitblit.wicket.panels.LogPanel;
 
 /**
  * The compare page allows you to compare two branches, tags, or hash ids.
- * 
+ *
  * @author James Moger
  *
  */
@@ -69,7 +73,7 @@
 		super(params);
 		Repository r = getRepository();
 		RepositoryModel repository = getRepositoryModel();
-		
+
 		if (StringUtils.isEmpty(objectId)) {
 			// seleciton form
 			add(new Label("comparison").setVisible(false));
@@ -77,30 +81,30 @@
 			// active comparison
 			Fragment comparison = new Fragment("comparison", "comparisonFragment", this);
 			add(comparison);
-			
+
 			RevCommit fromCommit;
 			RevCommit toCommit;
-			
+
 			String[] parts = objectId.split("\\.\\.");
 			if (parts[0].startsWith("refs/") && parts[1].startsWith("refs/")) {
 				// set the ref models
 				fromRefId.setObject(parts[0]);
 				toRefId.setObject(parts[1]);
-				
+
 				fromCommit = getCommit(r, fromRefId.getObject());
 				toCommit = getCommit(r, toRefId.getObject());
 			} else {
 				// set the id models
 				fromCommitId.setObject(parts[0]);
 				toCommitId.setObject(parts[1]);
-				
+
 				fromCommit = getCommit(r, fromCommitId.getObject());
 				toCommit = getCommit(r, toCommitId.getObject());
 			}
 
 			// prepare submodules
 			getSubmodules(toCommit);
-			
+
 			final String startId = fromCommit.getId().getName();
 			final String endId = toCommit.getId().getName();
 
@@ -108,7 +112,23 @@
 			fromCommitId.setObject(startId);
 			toCommitId.setObject(endId);
 
-			String diff = DiffUtils.getDiff(r, fromCommit, toCommit, DiffOutputType.HTML);
+			final List<String> imageExtensions = app().settings().getStrings(Keys.web.imageExtensions);
+			final ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,
+					fromCommit.getName(), toCommit.getName(), imageExtensions);
+
+			final DiffOutput diff = DiffUtils.getDiff(r, fromCommit, toCommit, DiffOutputType.HTML, handler);
+			if (handler.getImgDiffCount() > 0) {
+				addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs
+			}
+
+			// add compare diffstat
+			int insertions = 0;
+			int deletions = 0;
+			for (PathChangeModel pcm : diff.stat.paths) {
+				insertions += pcm.insertions;
+				deletions += pcm.deletions;
+			}
+			comparison.add(new DiffStatPanel("diffStat", insertions, deletions));
 
 			// compare page links
 //			comparison.add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
@@ -118,20 +138,20 @@
 			comparison.add(new LogPanel("commitList", repositoryName, objectId, r, 0, 0, repository.showRemoteBranches));
 
 			// changed paths list
-			List<PathChangeModel> paths = JGitUtils.getFilesInRange(r, fromCommit, toCommit);
-
-			comparison.add(new CommitLegendPanel("commitLegend", paths));
-			ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
+			comparison.add(new CommitLegendPanel("commitLegend", diff.stat.paths));
+			ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(diff.stat.paths);
 			DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
 				private static final long serialVersionUID = 1L;
 				int counter;
 
+				@Override
 				public void populateItem(final Item<PathChangeModel> item) {
 					final PathChangeModel entry = item.getModelObject();
 					Label changeType = new Label("changeType", "");
 					WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
 					setChangeTypeTooltip(changeType, entry.changeType);
 					item.add(changeType);
+					item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
 
 					boolean hasSubmodule = false;
 					String submodulePath = null;
@@ -148,10 +168,10 @@
 						hasSubmodule = submodule.hasSubmodule;
 
 						// add relative link
-						item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#" + entry.path));
+						item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#n" + entry.objectId));
 					} else {
 						// add relative link
-						item.add(new LinkPanel("pathName", "list", entry.path, "#" + entry.path));
+						item.add(new LinkPanel("pathName", "list", entry.path, "#n" + entry.objectId));
 					}
 
 					// quick links
@@ -160,6 +180,7 @@
 						item.add(new ExternalLink("patch", "").setEnabled(false));
 						item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
 								.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
+						item.add(new ExternalLink("raw", "").setEnabled(false));
 						item.add(new ExternalLink("blame", "").setEnabled(false));
 						item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
 								.newPathParameter(repositoryName, endId, entry.path))
@@ -171,6 +192,9 @@
 								.setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
 						item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
 								.newPathParameter(repositoryName, endId, entry.path))
+								.setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
+						String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, endId, entry.path);
+						item.add(new ExternalLink("raw", rawUrl)
 								.setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
 						item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
 								.newPathParameter(repositoryName, endId, entry.path))
@@ -185,7 +209,7 @@
 				}
 			};
 			comparison.add(pathsView);
-			comparison.add(new Label("diffText", diff).setEscapeModelStrings(false));
+			comparison.add(new Label("diffText", diff.content).setEscapeModelStrings(false));
 		}
 
 		//
@@ -199,14 +223,14 @@
 			public void onSubmit() {
 				String from = ComparePage.this.fromRefId.getObject();
 				String to = ComparePage.this.toRefId.getObject();
-				
+
 				PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to);
 				String relativeUrl = urlFor(ComparePage.class, params).toString();
 				String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
 				getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
 			}
 		};
-		
+
 		List<String> refs = new ArrayList<String>();
 		for (RefModel ref : JGitUtils.getLocalBranches(r, true, -1)) {
 			refs.add(ref.getName());
@@ -222,7 +246,7 @@
 		refsForm.add(new DropDownChoice<String>("fromRef", fromRefId, refs).setEnabled(refs.size() > 0));
 		refsForm.add(new DropDownChoice<String>("toRef", toRefId, refs).setEnabled(refs.size() > 0));
 		add(refsForm);
-		
+
 		//
 		// manual ids form
 		//
@@ -234,23 +258,23 @@
 			public void onSubmit() {
 				String from = ComparePage.this.fromCommitId.getObject();
 				String to = ComparePage.this.toCommitId.getObject();
-				
+
 				PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to);
 				String relativeUrl = urlFor(ComparePage.class, params).toString();
 				String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
 				getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
 			}
 		};
-		
+
 		TextField<String> fromIdField = new TextField<String>("fromId", fromCommitId);
 		WicketUtils.setInputPlaceholder(fromIdField, getString("gb.from") + "...");
 		idsForm.add(fromIdField);
-		
+
 		TextField<String> toIdField = new TextField<String>("toId", toCommitId);
 		WicketUtils.setInputPlaceholder(toIdField, getString("gb.to") + "...");
 		idsForm.add(toIdField);
 		add(idsForm);
-		
+
 		r.close();
 	}
 
@@ -258,7 +282,7 @@
 	protected String getPageName() {
 		return getString("gb.compare");
 	}
-	
+
 	@Override
 	protected Class<? extends BasePage> getRepoNavPageClass() {
 		return ComparePage.class;

--
Gitblit v1.9.1