James Moger
2011-06-04 5cc4f299b2a1138687cbaea73257abab08e245a4
Fixed refs linking problem. Author metrics are lowercase.
9 files modified
118 ■■■■■ changed files
distrib/users.properties 2 ●●● patch | view | raw | blame | history
src/com/gitblit/utils/JGitUtils.java 28 ●●●●● patch | view | raw | blame | history
src/com/gitblit/utils/MetricUtils.java 10 ●●●● patch | view | raw | blame | history
src/com/gitblit/utils/TicgitUtils.java 4 ●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/pages/TagPage.java 2 ●●● patch | view | raw | blame | history
src/com/gitblit/wicket/panels/BranchesPanel.java 4 ●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/panels/RefsPanel.java 56 ●●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/panels/TagsPanel.java 2 ●●● patch | view | raw | blame | history
tests/com/gitblit/tests/JGitUtilsTest.java 10 ●●●● patch | view | raw | blame | history
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
src/com/gitblit/utils/JGitUtils.java
@@ -211,7 +211,7 @@
    }
    public static Map<ObjectId, List<RefModel>> getAllRefs(Repository r) {
        List<RefModel> list = getRefs(r, org.eclipse.jgit.lib.RefDatabase.ALL, -1);
        List<RefModel> list = getRefs(r, org.eclipse.jgit.lib.RefDatabase.ALL, true, -1);
        Map<ObjectId, List<RefModel>> refs = new HashMap<ObjectId, List<RefModel>>();
        for (RefModel ref : list) {
            ObjectId objectid = ref.getReferencedObjectId();
@@ -613,23 +613,23 @@
        return list;
    }
    public static List<RefModel> getTags(Repository r, int maxCount) {
        return getRefs(r, Constants.R_TAGS, maxCount);
    public static List<RefModel> getTags(Repository r, boolean fullName, int maxCount) {
        return getRefs(r, Constants.R_TAGS, fullName, maxCount);
    }
    public static List<RefModel> getLocalBranches(Repository r, int maxCount) {
        return getRefs(r, Constants.R_HEADS, maxCount);
    public static List<RefModel> getLocalBranches(Repository r, boolean fullName, int maxCount) {
        return getRefs(r, Constants.R_HEADS, fullName, maxCount);
    }
    public static List<RefModel> getRemoteBranches(Repository r, int maxCount) {
        return getRefs(r, Constants.R_REMOTES, maxCount);
    public static List<RefModel> getRemoteBranches(Repository r, boolean fullName, int maxCount) {
        return getRefs(r, Constants.R_REMOTES, fullName, maxCount);
    }
    public static List<RefModel> getNotesRefs(Repository r, int maxCount) {
        return getRefs(r, Constants.R_NOTES, maxCount);
    public static List<RefModel> getNotesRefs(Repository r, boolean fullName, int maxCount) {
        return getRefs(r, Constants.R_NOTES, fullName, maxCount);
    }
    private static List<RefModel> getRefs(Repository r, String refs, int maxCount) {
    private static List<RefModel> getRefs(Repository r, String refs, boolean fullName, int maxCount) {
        List<RefModel> list = new ArrayList<RefModel>();
        try {
            Map<String, Ref> map = r.getRefDatabase().getRefs(refs);
@@ -637,7 +637,11 @@
            for (Entry<String, Ref> 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 static List<GitNote> getNotesOnCommit(Repository repository, RevCommit commit) {
        List<GitNote> list = new ArrayList<GitNote>();
        List<RefModel> notesRefs = getNotesRefs(repository, -1);
        List<RefModel> notesRefs = getNotesRefs(repository, true, -1);
        for (RefModel notesRef : notesRefs) {
            RevTree notesTree = JGitUtils.getCommit(repository, notesRef.getName()).getTree();
            StringBuilder sb = new StringBuilder(commit.getName());
src/com/gitblit/utils/MetricUtils.java
@@ -44,7 +44,7 @@
        final Map<String, Metric> metricMap = new HashMap<String, Metric>();
        if (JGitUtils.hasCommits(r)) {
            final List<RefModel> tags = JGitUtils.getTags(r, -1);
            final List<RefModel> tags = JGitUtils.getTags(r, true, -1);
            final Map<ObjectId, RefModel> tagMap = new HashMap<ObjectId, RefModel>();
            for (RefModel tag : tags) {
                tagMap.put(tag.getReferencedObjectId(), tag);
@@ -122,14 +122,14 @@
                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)) {
src/com/gitblit/utils/TicgitUtils.java
@@ -38,7 +38,7 @@
        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 @@
            // 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;
src/com/gitblit/wicket/pages/TagPage.java
@@ -39,7 +39,7 @@
        Repository r = getRepository();
        // Find tag in repository
        List<RefModel> tags = JGitUtils.getTags(r, -1);
        List<RefModel> tags = JGitUtils.getTags(r, true, -1);
        RefModel tagRef = null;
        for (RefModel tag : tags) {
            if (tag.getName().equals(objectId) || tag.getObjectId().getName().equals(objectId)) {
src/com/gitblit/wicket/panels/BranchesPanel.java
@@ -48,9 +48,9 @@
        // branches
        List<RefModel> branches = new ArrayList<RefModel>();
        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);
src/com/gitblit/wicket/panels/RefsPanel.java
@@ -17,6 +17,7 @@
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.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 @@
        if (refs == null) {
            refs = new ArrayList<RefModel>();
        }
        Collections.sort(refs);
        // refNames.remove(Constants.HEAD);
        Collections.sort(refs, new Comparator<RefModel>() {
            @Override
            public int compare(RefModel o1, RefModel o2) {
                return o1.displayName.compareTo(o2.displayName);
            }
        });
        ListDataProvider<RefModel> refsDp = new ListDataProvider<RefModel>(refs);
        DataView<RefModel> refsView = new DataView<RefModel>("ref", refsDp) {
@@ -60,34 +66,42 @@
                RefModel entry = item.getModelObject();
                String name = entry.displayName;
                String objectid = entry.getReferencedObjectId().getName();
                Component c = null;
                Class<? extends RepositoryPage> 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);
            }
src/com/gitblit/wicket/panels/TagsPanel.java
@@ -49,7 +49,7 @@
        super(wicketId);
        // header
        List<RefModel> tags = JGitUtils.getTags(r, maxCount);
        List<RefModel> tags = JGitUtils.getTags(r, false, maxCount);
        if (maxCount > 0) {
            // summary page
            // show tags page link
tests/com/gitblit/tests/JGitUtilsTest.java
@@ -139,7 +139,7 @@
    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 @@
                    + 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 @@
                    + 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 @@
        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"));