From cc1cd7800940f98efe206fe50a4375a3fb9dc621 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 9 Jan 2012 21:10:27 -0500 Subject: [PATCH] Refactored named branch retrieval function --- src/com/gitblit/utils/JGitUtils.java | 31 +++++++++++++++++--------- src/com/gitblit/utils/TicgitUtils.java | 24 +------------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index ae53c942..2a99c973 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -1291,29 +1291,40 @@ public class JGitUtils { * @return a refmodel for the gh-pages branch or null */ public static RefModel getPagesBranch(Repository repository) { - RefModel ghPages = null; + return getBranch(repository, "gh-pages"); + } + + /** + * Returns a RefModel for a specific branch name in the repository. If the + * branch can not be found, null is returned. + * + * @param repository + * @return a refmodel for the branch or null + */ + public static RefModel getBranch(Repository repository, String name) { + RefModel branch = null; try { - // search for gh-pages branch in local heads + // search for the branch in local heads for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) { - if (ref.displayName.endsWith("gh-pages")) { - ghPages = ref; + if (ref.displayName.endsWith(name)) { + branch = ref; break; } } - // search for gh-pages branch in remote heads - if (ghPages == null) { + // search for the branch in remote heads + if (branch == null) { for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) { - if (ref.displayName.endsWith("gh-pages")) { - ghPages = ref; + if (ref.displayName.endsWith(name)) { + branch = ref; break; } } } } catch (Throwable t) { - LOGGER.error("Failed to find gh-pages branch!", t); + LOGGER.error(MessageFormat.format("Failed to find {0} branch!", name), t); } - return ghPages; + return branch; } /** diff --git a/src/com/gitblit/utils/TicgitUtils.java b/src/com/gitblit/utils/TicgitUtils.java index 87a2b3ae..aab5a3e1 100644 --- a/src/com/gitblit/utils/TicgitUtils.java +++ b/src/com/gitblit/utils/TicgitUtils.java @@ -48,29 +48,7 @@ public class TicgitUtils { * @return a refmodel for the ticgit branch or null */ public static RefModel getTicketsBranch(Repository repository) { - RefModel ticgitBranch = null; - try { - // search for ticgit branch in local heads - for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) { - if (ref.displayName.endsWith("ticgit")) { - ticgitBranch = ref; - break; - } - } - - // search for ticgit branch in remote heads - if (ticgitBranch == null) { - for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) { - if (ref.displayName.endsWith("ticgit")) { - ticgitBranch = ref; - break; - } - } - } - } catch (Throwable t) { - LOGGER.error("Failed to find ticgit branch!", t); - } - return ticgitBranch; + return JGitUtils.getBranch(repository, "ticgit"); } /** -- 2.39.5