From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit,  gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command

---
 src/com/gitblit/utils/TicgitUtils.java |   98 +++++++++++++++++++++++++++----------------------
 1 files changed, 54 insertions(+), 44 deletions(-)

diff --git a/src/com/gitblit/utils/TicgitUtils.java b/src/com/gitblit/utils/TicgitUtils.java
index 914b813..aab5a3e 100644
--- a/src/com/gitblit/utils/TicgitUtils.java
+++ b/src/com/gitblit/utils/TicgitUtils.java
@@ -21,6 +21,7 @@
 import java.util.List;
 
 import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,45 +30,46 @@
 import com.gitblit.models.TicketModel;
 import com.gitblit.models.TicketModel.Comment;
 
+/**
+ * Utility class for reading Ticgit issues.
+ * 
+ * @author James Moger
+ * 
+ */
 public class TicgitUtils {
 
 	static final Logger LOGGER = LoggerFactory.getLogger(TicgitUtils.class);
 
-	public static RefModel getTicketsBranch(Repository r) {
-		RefModel ticgitBranch = null;
-		try {
-			// search for ticgit branch in local heads
-			for (RefModel ref : JGitUtils.getLocalBranches(r, -1)) {
-				if (ref.displayName.endsWith("ticgit")) {
-					ticgitBranch = ref;
-					break;
-				}
-			}
-
-			// search for ticgit branch in remote heads
-			if (ticgitBranch == null) {
-				for (RefModel ref : JGitUtils.getRemoteBranches(r, -1)) {
-					if (ref.displayName.endsWith("ticgit")) {
-						ticgitBranch = ref;
-						break;
-					}
-				}
-			}
-		} catch (Throwable t) {
-			LOGGER.error("Failed to find ticgit branch!", t);
-		}
-		return ticgitBranch;
+	/**
+	 * Returns a RefModel for the Ticgit branch in the repository. If the branch
+	 * can not be found, null is returned.
+	 * 
+	 * @param repository
+	 * @return a refmodel for the ticgit branch or null
+	 */
+	public static RefModel getTicketsBranch(Repository repository) {
+		return JGitUtils.getBranch(repository, "ticgit");
 	}
 
-	public static List<TicketModel> getTickets(Repository r) {
-		RefModel ticgitBranch = getTicketsBranch(r);
-		List<PathModel> paths = JGitUtils.getFilesInPath(r, null, ticgitBranch.commit);
+	/**
+	 * Returns a list of all tickets in the ticgit branch of the repository.
+	 * 
+	 * @param repository
+	 * @return list of tickets
+	 */
+	public static List<TicketModel> getTickets(Repository repository) {
+		RefModel ticgitBranch = getTicketsBranch(repository);
+		if (ticgitBranch == null) {
+			return null;
+		}
+		RevCommit commit = (RevCommit) ticgitBranch.referencedObject;
+		List<PathModel> paths = JGitUtils.getFilesInPath(repository, null, commit);
 		List<TicketModel> tickets = new ArrayList<TicketModel>();
 		for (PathModel ticketFolder : paths) {
 			if (ticketFolder.isTree()) {
 				try {
 					TicketModel t = new TicketModel(ticketFolder.name);
-					readTicketContents(r, ticgitBranch, t);
+					loadTicketContents(repository, ticgitBranch, t);
 					tickets.add(t);
 				} catch (Throwable t) {
 					LOGGER.error("Failed to get a ticket!", t);
@@ -79,12 +81,20 @@
 		return tickets;
 	}
 
-	public static TicketModel getTicket(Repository r, String ticketFolder) {
-		RefModel ticketsBranch = getTicketsBranch(r);
+	/**
+	 * Returns a TicketModel for the specified ticgit ticket. Returns null if
+	 * the ticket does not exist or some other error occurs.
+	 * 
+	 * @param repository
+	 * @param ticketFolder
+	 * @return a ticket
+	 */
+	public static TicketModel getTicket(Repository repository, String ticketFolder) {
+		RefModel ticketsBranch = getTicketsBranch(repository);
 		if (ticketsBranch != null) {
 			try {
 				TicketModel ticket = new TicketModel(ticketFolder);
-				readTicketContents(r, ticketsBranch, ticket);
+				loadTicketContents(repository, ticketsBranch, ticket);
 				return ticket;
 			} catch (Throwable t) {
 				LOGGER.error("Failed to get ticket " + ticketFolder, t);
@@ -93,11 +103,19 @@
 		return null;
 	}
 
-	private static void readTicketContents(Repository r, RefModel ticketsBranch, TicketModel ticket) {
-		List<PathModel> ticketFiles = JGitUtils
-				.getFilesInPath(r, ticket.name, ticketsBranch.commit);
+	/**
+	 * Loads the contents of the ticket.
+	 * 
+	 * @param repository
+	 * @param ticketsBranch
+	 * @param ticket
+	 */
+	private static void loadTicketContents(Repository repository, RefModel ticketsBranch,
+			TicketModel ticket) {
+		RevCommit commit = (RevCommit) ticketsBranch.referencedObject;
+		List<PathModel> ticketFiles = JGitUtils.getFilesInPath(repository, ticket.name, commit);
 		for (PathModel file : ticketFiles) {
-			String content = JGitUtils.getRawContentAsString(r, ticketsBranch.commit, file.path)
+			String content = JGitUtils.getStringContent(repository, commit.getTree(), file.path)
 					.trim();
 			if (file.name.equals("TICKET_ID")) {
 				ticket.id = content;
@@ -112,7 +130,7 @@
 						Comment c = new Comment(file.name, content);
 						ticket.comments.add(c);
 					} catch (ParseException e) {
-						e.printStackTrace();
+						LOGGER.error("Failed to parse ticket comment", e);
 					}
 				} else if (chunks[0].equals("TAG")) {
 					if (content.startsWith("TAG_")) {
@@ -126,13 +144,5 @@
 			}
 		}
 		Collections.sort(ticket.comments);
-	}
-
-	public static String getTicketContent(Repository r, String filePath) {
-		RefModel ticketsBranch = getTicketsBranch(r);
-		if (ticketsBranch != null) {
-			return JGitUtils.getRawContentAsString(r, ticketsBranch.commit, filePath);
-		}
-		return "";
 	}
 }

--
Gitblit v1.9.1