From 27ae9095639bb228a1b7ff86a3ebe4264abf05be Mon Sep 17 00:00:00 2001
From: mschaefers <mschaefers@scoop-gmbh.de>
Date: Thu, 29 Nov 2012 12:33:09 -0500
Subject: [PATCH] feature: when using LdapUserService one can configure Gitblit to fetch all users from ldap that can possibly login. This allows to see newly generated LDAP users instantly in Gitblit. By now an LDAP user had to log in once to appear in GitBlit.

---
 src/com/gitblit/utils/PatchFormatter.java |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/com/gitblit/utils/PatchFormatter.java b/src/com/gitblit/utils/PatchFormatter.java
index ea13ff7..90b3fb1 100644
--- a/src/com/gitblit/utils/PatchFormatter.java
+++ b/src/com/gitblit/utils/PatchFormatter.java
@@ -30,13 +30,19 @@
 
 import com.gitblit.Constants;
 
+/**
+ * A diff formatter that outputs standard patch content.
+ * 
+ * @author James Moger
+ * 
+ */
 public class PatchFormatter extends DiffFormatter {
 
 	private final OutputStream os;
 
-	private PatchTouple currentTouple = null;
+	private Map<String, PatchTouple> changes = new HashMap<String, PatchTouple>();
 
-	Map<String, PatchTouple> changes = new HashMap<String, PatchTouple>();
+	private PatchTouple currentTouple;
 
 	public PatchFormatter(OutputStream os) {
 		super(os);
@@ -50,7 +56,8 @@
 	}
 
 	@Override
-	protected void writeLine(final char prefix, final RawText text, final int cur) throws IOException {
+	protected void writeLine(final char prefix, final RawText text, final int cur)
+			throws IOException {
 		switch (prefix) {
 		case '+':
 			currentTouple.insertions++;
@@ -68,9 +75,11 @@
 		// I have no idea why that is there. it seems to be a constant.
 		patch.append("From " + commit.getName() + " Mon Sep 17 00:00:00 2001" + "\n");
 		patch.append("From: " + JGitUtils.getDisplayName(commit.getAuthorIdent()) + "\n");
-		patch.append("Date: " + (new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z").format(new Date(commit.getCommitTime() * 1000l))) + "\n");
+		patch.append("Date: "
+				+ (new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z").format(new Date(commit
+						.getCommitTime() * 1000L))) + "\n");
 		patch.append("Subject: [PATCH] " + commit.getShortMessage() + "\n");
-		patch.append("\n");
+		patch.append('\n');
 		patch.append("---");
 		int maxPathLen = 0;
 		int files = 0;
@@ -93,26 +102,34 @@
 		}
 		for (String path : changes.keySet()) {
 			PatchTouple touple = changes.get(path);
-			patch.append("\n " + StringUtils.rightPad(path, maxPathLen, ' ') + " | " + StringUtils.leftPad("" + touple.total(), 4, ' ') + " " + touple.relativeScale(unit));
+			patch.append("\n " + StringUtils.rightPad(path, maxPathLen, ' ') + " | "
+					+ StringUtils.leftPad("" + touple.total(), 4, ' ') + " "
+					+ touple.relativeScale(unit));
 		}
-		patch.append(MessageFormat.format("\n {0} files changed, {1} insertions(+), {2} deletions(-)\n\n", files, insertions, deletions));
+		patch.append(MessageFormat.format(
+				"\n {0} files changed, {1} insertions(+), {2} deletions(-)\n\n", files, insertions,
+				deletions));
 		patch.append(os.toString());
 		patch.append("\n--\n");
-		patch.append(Constants.getRunningVersion());
+		patch.append(Constants.getGitBlitVersion());
 		return patch.toString();
 	}
 
-	private class PatchTouple {
-		int insertions = 0;
-		int deletions = 0;
+	/**
+	 * Class that represents the number of insertions and deletions from a
+	 * chunk.
+	 */
+	private static class PatchTouple {
+		int insertions;
+		int deletions;
 
 		int total() {
 			return insertions + deletions;
 		}
 
 		String relativeScale(int unit) {
-			int plus = (insertions / unit);
-			int minus = (deletions / unit);
+			int plus = insertions / unit;
+			int minus = deletions / unit;
 			StringBuilder sb = new StringBuilder();
 			for (int i = 0; i < plus; i++) {
 				sb.append('+');

--
Gitblit v1.9.1