]> source.dussan.org Git - gitblit.git/commitdiff
Refactored named branch retrieval function
authorJames Moger <james.moger@gitblit.com>
Tue, 10 Jan 2012 02:10:27 +0000 (21:10 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 10 Jan 2012 02:10:27 +0000 (21:10 -0500)
src/com/gitblit/utils/JGitUtils.java
src/com/gitblit/utils/TicgitUtils.java

index ae53c942e0c71ae2388574cb7dbb0362fde77e78..2a99c97368c17b4d86219a3e40046f28f4be83db 100644 (file)
@@ -1291,29 +1291,40 @@ public class JGitUtils {
         * @return a refmodel for the gh-pages branch or null\r
         */\r
        public static RefModel getPagesBranch(Repository repository) {\r
-               RefModel ghPages = null;\r
+               return getBranch(repository, "gh-pages");\r
+       }\r
+\r
+       /**\r
+        * Returns a RefModel for a specific branch name in the repository. If the\r
+        * branch can not be found, null is returned.\r
+        * \r
+        * @param repository\r
+        * @return a refmodel for the branch or null\r
+        */\r
+       public static RefModel getBranch(Repository repository, String name) {\r
+               RefModel branch = null;\r
                try {\r
-                       // search for gh-pages branch in local heads\r
+                       // search for the branch in local heads\r
                        for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) {\r
-                               if (ref.displayName.endsWith("gh-pages")) {\r
-                                       ghPages = ref;\r
+                               if (ref.displayName.endsWith(name)) {\r
+                                       branch = ref;\r
                                        break;\r
                                }\r
                        }\r
 \r
-                       // search for gh-pages branch in remote heads\r
-                       if (ghPages == null) {\r
+                       // search for the branch in remote heads\r
+                       if (branch == null) {\r
                                for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) {\r
-                                       if (ref.displayName.endsWith("gh-pages")) {\r
-                                               ghPages = ref;\r
+                                       if (ref.displayName.endsWith(name)) {\r
+                                               branch = ref;\r
                                                break;\r
                                        }\r
                                }\r
                        }\r
                } catch (Throwable t) {\r
-                       LOGGER.error("Failed to find gh-pages branch!", t);\r
+                       LOGGER.error(MessageFormat.format("Failed to find {0} branch!", name), t);\r
                }\r
-               return ghPages;\r
+               return branch;\r
        }\r
 \r
        /**\r
index 87a2b3aeaa62d42c825f15919788b75347d05808..aab5a3e14030ec987cf70facb33e64767bc22d94 100644 (file)
@@ -48,29 +48,7 @@ public class TicgitUtils {
         * @return a refmodel for the ticgit branch or null\r
         */\r
        public static RefModel getTicketsBranch(Repository repository) {\r
-               RefModel ticgitBranch = null;\r
-               try {\r
-                       // search for ticgit branch in local heads\r
-                       for (RefModel ref : JGitUtils.getLocalBranches(repository, false, -1)) {\r
-                               if (ref.displayName.endsWith("ticgit")) {\r
-                                       ticgitBranch = ref;\r
-                                       break;\r
-                               }\r
-                       }\r
-\r
-                       // search for ticgit branch in remote heads\r
-                       if (ticgitBranch == null) {\r
-                               for (RefModel ref : JGitUtils.getRemoteBranches(repository, false, -1)) {\r
-                                       if (ref.displayName.endsWith("ticgit")) {\r
-                                               ticgitBranch = ref;\r
-                                               break;\r
-                                       }\r
-                               }\r
-                       }\r
-               } catch (Throwable t) {\r
-                       LOGGER.error("Failed to find ticgit branch!", t);\r
-               }\r
-               return ticgitBranch;\r
+               return JGitUtils.getBranch(repository, "ticgit");\r
        }\r
 \r
        /**\r