From 5cc4f299b2a1138687cbaea73257abab08e245a4 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 4 Jun 2011 14:23:55 -0400 Subject: Fixed refs linking problem. Author metrics are lowercase. --- distrib/users.properties | 2 +- src/com/gitblit/utils/JGitUtils.java | 28 +++++++----- src/com/gitblit/utils/MetricUtils.java | 10 ++--- src/com/gitblit/utils/TicgitUtils.java | 4 +- src/com/gitblit/wicket/pages/TagPage.java | 2 +- src/com/gitblit/wicket/panels/BranchesPanel.java | 4 +- src/com/gitblit/wicket/panels/RefsPanel.java | 56 +++++++++++++++--------- src/com/gitblit/wicket/panels/TagsPanel.java | 2 +- tests/com/gitblit/tests/JGitUtilsTest.java | 10 ++--- 9 files changed, 68 insertions(+), 50 deletions(-) diff --git a/distrib/users.properties b/distrib/users.properties index a7ebc678..f3e50752 100644 --- a/distrib/users.properties +++ b/distrib/users.properties @@ -1,3 +1,3 @@ ## Git:Blit realm file format: username=password,\#permission,repository1,repository2... -#Thu Jun 02 22:11:15 EDT 2011 +#Sat Jun 04 14:21:04 EDT 2011 admin=admin,\#admin diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index 2590a300..6e02b9c4 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -211,7 +211,7 @@ public class JGitUtils { } public static Map> getAllRefs(Repository r) { - List list = getRefs(r, org.eclipse.jgit.lib.RefDatabase.ALL, -1); + List list = getRefs(r, org.eclipse.jgit.lib.RefDatabase.ALL, true, -1); Map> refs = new HashMap>(); for (RefModel ref : list) { ObjectId objectid = ref.getReferencedObjectId(); @@ -613,23 +613,23 @@ public class JGitUtils { return list; } - public static List getTags(Repository r, int maxCount) { - return getRefs(r, Constants.R_TAGS, maxCount); + public static List getTags(Repository r, boolean fullName, int maxCount) { + return getRefs(r, Constants.R_TAGS, fullName, maxCount); } - public static List getLocalBranches(Repository r, int maxCount) { - return getRefs(r, Constants.R_HEADS, maxCount); + public static List getLocalBranches(Repository r, boolean fullName, int maxCount) { + return getRefs(r, Constants.R_HEADS, fullName, maxCount); } - public static List getRemoteBranches(Repository r, int maxCount) { - return getRefs(r, Constants.R_REMOTES, maxCount); + public static List getRemoteBranches(Repository r, boolean fullName, int maxCount) { + return getRefs(r, Constants.R_REMOTES, fullName, maxCount); } - public static List getNotesRefs(Repository r, int maxCount) { - return getRefs(r, Constants.R_NOTES, maxCount); + public static List getNotesRefs(Repository r, boolean fullName, int maxCount) { + return getRefs(r, Constants.R_NOTES, fullName, maxCount); } - private static List getRefs(Repository r, String refs, int maxCount) { + private static List getRefs(Repository r, String refs, boolean fullName, int maxCount) { List list = new ArrayList(); try { Map map = r.getRefDatabase().getRefs(refs); @@ -637,7 +637,11 @@ public class JGitUtils { for (Entry entry : map.entrySet()) { Ref ref = entry.getValue(); RevObject object = rw.parseAny(ref.getObjectId()); - list.add(new RefModel(entry.getKey(), ref, object)); + String name = entry.getKey(); + if (fullName && !StringUtils.isEmpty(refs)) { + name = refs + name; + } + list.add(new RefModel(name, ref, object)); } rw.dispose(); Collections.sort(list); @@ -653,7 +657,7 @@ public class JGitUtils { public static List getNotesOnCommit(Repository repository, RevCommit commit) { List list = new ArrayList(); - List notesRefs = getNotesRefs(repository, -1); + List notesRefs = getNotesRefs(repository, true, -1); for (RefModel notesRef : notesRefs) { RevTree notesTree = JGitUtils.getCommit(repository, notesRef.getName()).getTree(); StringBuilder sb = new StringBuilder(commit.getName()); diff --git a/src/com/gitblit/utils/MetricUtils.java b/src/com/gitblit/utils/MetricUtils.java index d963bf58..d8286e29 100644 --- a/src/com/gitblit/utils/MetricUtils.java +++ b/src/com/gitblit/utils/MetricUtils.java @@ -44,7 +44,7 @@ public class MetricUtils { final Map metricMap = new HashMap(); if (JGitUtils.hasCommits(r)) { - final List tags = JGitUtils.getTags(r, -1); + final List tags = JGitUtils.getTags(r, true, -1); final Map tagMap = new HashMap(); for (RefModel tag : tags) { tagMap.put(tag.getReferencedObjectId(), tag); @@ -122,14 +122,14 @@ public class MetricUtils { for (RevCommit rev : revlog) { String p; if (byEmail) { - p = rev.getAuthorIdent().getEmailAddress(); + p = rev.getAuthorIdent().getEmailAddress().toLowerCase(); if (StringUtils.isEmpty(p)) { - p = rev.getAuthorIdent().getName(); + p = rev.getAuthorIdent().getName().toLowerCase(); } } else { - p = rev.getAuthorIdent().getName(); + p = rev.getAuthorIdent().getName().toLowerCase(); if (StringUtils.isEmpty(p)) { - p = rev.getAuthorIdent().getEmailAddress(); + p = rev.getAuthorIdent().getEmailAddress().toLowerCase(); } } if (!metricMap.containsKey(p)) { diff --git a/src/com/gitblit/utils/TicgitUtils.java b/src/com/gitblit/utils/TicgitUtils.java index 8224d1cb..48e8558c 100644 --- a/src/com/gitblit/utils/TicgitUtils.java +++ b/src/com/gitblit/utils/TicgitUtils.java @@ -38,7 +38,7 @@ public class TicgitUtils { RefModel ticgitBranch = null; try { // search for ticgit branch in local heads - for (RefModel ref : JGitUtils.getLocalBranches(r, -1)) { + for (RefModel ref : JGitUtils.getLocalBranches(r, false, -1)) { if (ref.displayName.endsWith("ticgit")) { ticgitBranch = ref; break; @@ -47,7 +47,7 @@ public class TicgitUtils { // search for ticgit branch in remote heads if (ticgitBranch == null) { - for (RefModel ref : JGitUtils.getRemoteBranches(r, -1)) { + for (RefModel ref : JGitUtils.getRemoteBranches(r, false, -1)) { if (ref.displayName.endsWith("ticgit")) { ticgitBranch = ref; break; diff --git a/src/com/gitblit/wicket/pages/TagPage.java b/src/com/gitblit/wicket/pages/TagPage.java index 71a86452..c1efb898 100644 --- a/src/com/gitblit/wicket/pages/TagPage.java +++ b/src/com/gitblit/wicket/pages/TagPage.java @@ -39,7 +39,7 @@ public class TagPage extends RepositoryPage { Repository r = getRepository(); // Find tag in repository - List tags = JGitUtils.getTags(r, -1); + List tags = JGitUtils.getTags(r, true, -1); RefModel tagRef = null; for (RefModel tag : tags) { if (tag.getName().equals(objectId) || tag.getObjectId().getName().equals(objectId)) { diff --git a/src/com/gitblit/wicket/panels/BranchesPanel.java b/src/com/gitblit/wicket/panels/BranchesPanel.java index d50db883..82f8a045 100644 --- a/src/com/gitblit/wicket/panels/BranchesPanel.java +++ b/src/com/gitblit/wicket/panels/BranchesPanel.java @@ -48,9 +48,9 @@ public class BranchesPanel extends BasePanel { // branches List branches = new ArrayList(); - branches.addAll(JGitUtils.getLocalBranches(r, maxCount)); + branches.addAll(JGitUtils.getLocalBranches(r, false, maxCount)); if (model.showRemoteBranches) { - branches.addAll(JGitUtils.getRemoteBranches(r, maxCount)); + branches.addAll(JGitUtils.getRemoteBranches(r, false, maxCount)); } Collections.sort(branches); Collections.reverse(branches); diff --git a/src/com/gitblit/wicket/panels/RefsPanel.java b/src/com/gitblit/wicket/panels/RefsPanel.java index 266a49b7..8cf137b1 100644 --- a/src/com/gitblit/wicket/panels/RefsPanel.java +++ b/src/com/gitblit/wicket/panels/RefsPanel.java @@ -17,6 +17,7 @@ package com.gitblit.wicket.panels; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -33,6 +34,7 @@ import com.gitblit.models.RefModel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.CommitPage; import com.gitblit.wicket.pages.LogPage; +import com.gitblit.wicket.pages.RepositoryPage; import com.gitblit.wicket.pages.TagPage; public class RefsPanel extends Panel { @@ -49,8 +51,12 @@ public class RefsPanel extends Panel { if (refs == null) { refs = new ArrayList(); } - Collections.sort(refs); - // refNames.remove(Constants.HEAD); + Collections.sort(refs, new Comparator() { + @Override + public int compare(RefModel o1, RefModel o2) { + return o1.displayName.compareTo(o2.displayName); + } + }); ListDataProvider refsDp = new ListDataProvider(refs); DataView refsView = new DataView("ref", refsDp) { @@ -60,34 +66,42 @@ public class RefsPanel extends Panel { RefModel entry = item.getModelObject(); String name = entry.displayName; String objectid = entry.getReferencedObjectId().getName(); - Component c = null; + + Class linkClass = CommitPage.class; + String cssClass = ""; if (name.startsWith(Constants.R_HEADS)) { // local head - c = new LinkPanel("refName", null, name.substring(Constants.R_HEADS.length()), - LogPage.class, WicketUtils.newObjectParameter(repositoryName, objectid)); - WicketUtils.setCssClass(c, "headRef"); + linkClass = LogPage.class; + name = name.substring(Constants.R_HEADS.length()); + cssClass = "headRef"; } else if (name.equals(Constants.HEAD)) { // local head - c = new LinkPanel("refName", null, name, LogPage.class, - WicketUtils.newObjectParameter(repositoryName, objectid)); - WicketUtils.setCssClass(c, "headRef"); + linkClass = LogPage.class; + cssClass = "headRef"; } else if (name.startsWith(Constants.R_REMOTES)) { // remote head - c = new LinkPanel("refName", null, - name.substring(Constants.R_REMOTES.length()), LogPage.class, - WicketUtils.newObjectParameter(repositoryName, objectid)); - WicketUtils.setCssClass(c, "remoteRef"); + linkClass = LogPage.class; + name = name.substring(Constants.R_REMOTES.length()); + cssClass = "remoteRef"; } else if (name.startsWith(Constants.R_TAGS)) { // tag - c = new LinkPanel("refName", null, name.substring(Constants.R_TAGS.length()), - TagPage.class, WicketUtils.newObjectParameter(repositoryName, objectid)); - WicketUtils.setCssClass(c, "tagRef"); - } else { - // other - c = new LinkPanel("refName", null, name, CommitPage.class, - WicketUtils.newObjectParameter(repositoryName, objectid)); - WicketUtils.setCssClass(c, "otherRef"); + if (entry.isAnnotatedTag()) { + linkClass = TagPage.class; + objectid = entry.getObjectId().getName(); + } else { + linkClass = CommitPage.class; + objectid = entry.getReferencedObjectId().getName(); + } + name = name.substring(Constants.R_TAGS.length()); + cssClass = "tagRef"; + } else if (name.startsWith(Constants.R_NOTES)) { + linkClass = CommitPage.class; + cssClass = "otherRef"; } + + Component c = new LinkPanel("refName", null, name, linkClass, + WicketUtils.newObjectParameter(repositoryName, objectid)); + WicketUtils.setCssClass(c, cssClass); WicketUtils.setHtmlTooltip(c, name); item.add(c); } diff --git a/src/com/gitblit/wicket/panels/TagsPanel.java b/src/com/gitblit/wicket/panels/TagsPanel.java index 259af312..f6dd762b 100644 --- a/src/com/gitblit/wicket/panels/TagsPanel.java +++ b/src/com/gitblit/wicket/panels/TagsPanel.java @@ -49,7 +49,7 @@ public class TagsPanel extends BasePanel { super(wicketId); // header - List tags = JGitUtils.getTags(r, maxCount); + List tags = JGitUtils.getTags(r, false, maxCount); if (maxCount > 0) { // summary page // show tags page link diff --git a/tests/com/gitblit/tests/JGitUtilsTest.java b/tests/com/gitblit/tests/JGitUtilsTest.java index 7196afdf..6646bf80 100644 --- a/tests/com/gitblit/tests/JGitUtilsTest.java +++ b/tests/com/gitblit/tests/JGitUtilsTest.java @@ -139,7 +139,7 @@ public class JGitUtilsTest extends TestCase { public void testBranches() throws Exception { Repository repository = GitBlitSuite.getTicgitRepository(); - for (RefModel model : JGitUtils.getLocalBranches(repository, -1)) { + for (RefModel model : JGitUtils.getLocalBranches(repository, true, -1)) { assertTrue(model.getName().startsWith(Constants.R_HEADS)); assertTrue(model.equals(model)); assertFalse(model.equals("")); @@ -147,7 +147,7 @@ public class JGitUtilsTest extends TestCase { + model.getName().hashCode()); assertTrue(model.getShortMessage().equals(model.getShortMessage())); } - for (RefModel model : JGitUtils.getRemoteBranches(repository, -1)) { + for (RefModel model : JGitUtils.getRemoteBranches(repository, true, -1)) { assertTrue(model.getName().startsWith(Constants.R_REMOTES)); assertTrue(model.equals(model)); assertFalse(model.equals("")); @@ -155,13 +155,13 @@ public class JGitUtilsTest extends TestCase { + model.getName().hashCode()); assertTrue(model.getShortMessage().equals(model.getShortMessage())); } - assertTrue(JGitUtils.getRemoteBranches(repository, 10).size() == 10); + assertTrue(JGitUtils.getRemoteBranches(repository, true, 10).size() == 10); repository.close(); } public void testTags() throws Exception { Repository repository = GitBlitSuite.getTicgitRepository(); - for (RefModel model : JGitUtils.getTags(repository, -1)) { + for (RefModel model : JGitUtils.getTags(repository, true, -1)) { if (model.getObjectId().getName().equals("283035e4848054ff1803cb0e690270787dc92399")) { assertTrue("Not an annotated tag!", model.isAnnotatedTag()); } @@ -174,7 +174,7 @@ public class JGitUtilsTest extends TestCase { repository.close(); repository = GitBlitSuite.getBluezGnomeRepository(); - for (RefModel model : JGitUtils.getTags(repository, -1)) { + for (RefModel model : JGitUtils.getTags(repository, true, -1)) { if (model.getObjectId().getName().equals("728643ec0c438c77e182898c2f2967dbfdc231c8")) { assertFalse(model.isAnnotatedTag()); assertTrue(model.getAuthorIdent().getEmailAddress().equals("marcel@holtmann.org")); -- cgit v1.2.3