From d00a0ca46fcde3e3e580afea6a548b9c12aeac25 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 11 Jul 2012 17:18:02 -0400
Subject: [PATCH] Update to slf4j 1.6.6 and log4j 1.2.17
---
src/com/gitblit/utils/TicgitUtils.java | 82 ++++++++++++++++++++++++-----------------
1 files changed, 48 insertions(+), 34 deletions(-)
diff --git a/src/com/gitblit/utils/TicgitUtils.java b/src/com/gitblit/utils/TicgitUtils.java
index 8224d1c..aab5a3e 100644
--- a/src/com/gitblit/utils/TicgitUtils.java
+++ b/src/com/gitblit/utils/TicgitUtils.java
@@ -30,49 +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);
+ /**
+ * 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(r, null, commit);
+ 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);
@@ -84,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);
@@ -98,11 +103,20 @@
return null;
}
- private static void readTicketContents(Repository r, RefModel ticketsBranch, TicketModel ticket) {
+ /**
+ * 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(r, ticket.name, commit);
+ List<PathModel> ticketFiles = JGitUtils.getFilesInPath(repository, ticket.name, commit);
for (PathModel file : ticketFiles) {
- String content = JGitUtils.getStringContent(r, commit.getTree(), file.path).trim();
+ String content = JGitUtils.getStringContent(repository, commit.getTree(), file.path)
+ .trim();
if (file.name.equals("TICKET_ID")) {
ticket.id = content;
} else if (file.name.equals("TITLE")) {
--
Gitblit v1.9.1