James Moger
2013-05-25 5c1588395c1ae15d770fc4ee4092a055abd6038b
Enhance push log utils api with functional date filtering
2 files modified
111 ■■■■ changed files
src/main/java/com/gitblit/utils/PushLogUtils.java 38 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/PushesPanel.java 73 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/utils/PushLogUtils.java
@@ -438,4 +438,42 @@
        
        return refPushLog;
    }
    /**
     * Returns the list of pushes separated by ref (e.g. each ref has it's own
     * PushLogEntry object).
     *
     * @param repositoryName
     * @param repository
     * @param minimumDate
     * @return a list of push log entries separated by ref
     */
    public static List<PushLogEntry> getPushLogByRef(String repositoryName, Repository repository,  Date minimumDate) {
        // break the push log into ref push logs and then merge them back into a list
        Map<String, List<PushLogEntry>> refMap = new HashMap<String, List<PushLogEntry>>();
        for (PushLogEntry push : getPushLog(repositoryName, repository, minimumDate)) {
            for (String ref : push.getChangedRefs()) {
                if (!refMap.containsKey(ref)) {
                    refMap.put(ref, new ArrayList<PushLogEntry>());
                }
                // construct new ref-specific push log entry
                PushLogEntry refPush = new PushLogEntry(push.repository, push.date, push.user);
                refPush.updateRef(ref, push.getChangeType(ref), push.getOldId(ref), push.getNewId(ref));
                refPush.addCommits(push.getCommits(ref));
                refMap.get(ref).add(refPush);
            }
        }
        // merge individual ref pushes into master list
        List<PushLogEntry> refPushLog = new ArrayList<PushLogEntry>();
        for (List<PushLogEntry> refPush : refMap.values()) {
            refPushLog.addAll(refPush);
        }
        // sort ref push log
        Collections.sort(refPushLog);
        return refPushLog;
    }
}
src/main/java/com/gitblit/wicket/panels/PushesPanel.java
@@ -59,19 +59,52 @@
            pushesPerPage = 10;
        }
        final int hashLen = GitBlit.getInteger(Keys.web.shortCommitIdLength, 6);
        List<PushLogEntry> pushes;
        if (pageResults) {
            pushes = PushLogUtils.getPushLogByRef(model.name, r, pageOffset * pushesPerPage, pushesPerPage);
        } else {
            pushes = PushLogUtils.getPushLogByRef(model.name, r, limit);
        }
        // inaccurate way to determine if there are more commits.
        // works unless commits.size() represents the exact end.
        hasMore = pushes.size() >= pushesPerPage;
        hasPushes = pushes.size() > 0;
        setup(pushes);
        // determine to show pager, more, or neither
        if (limit <= 0) {
            // no display limit
            add(new Label("morePushes").setVisible(false));
        } else {
            if (pageResults) {
                // paging
                add(new Label("morePushes").setVisible(false));
            } else {
                // more
                if (pushes.size() == limit) {
                    // show more
                    add(new LinkPanel("morePushes", "link", new StringResourceModel("gb.morePushes",
                            this, null), PushesPage.class,
                            WicketUtils.newRepositoryParameter(model.name)));
                } else {
                    // no more
                    add(new Label("morePushes").setVisible(false));
                }
            }
        }
    }
    public PushesPanel(String wicketId, List<PushLogEntry> pushes) {
        super(wicketId);
        hasPushes = pushes.size() > 0;
        setup(pushes);
        add(new Label("morePushes").setVisible(false));
    }
    protected void setup(List<PushLogEntry> pushes) {
        final int hashLen = GitBlit.getInteger(Keys.web.shortCommitIdLength, 6);
        ListDataProvider<PushLogEntry> dp = new ListDataProvider<PushLogEntry>(pushes);
        DataView<PushLogEntry> pushView = new DataView<PushLogEntry>("push", dp) {
@@ -144,19 +177,19 @@
                } else if (isTag) {
                    // link to tag
                    pushItem.add(new LinkPanel("refPushed", null, shortRefName,
                            TagPage.class, WicketUtils.newObjectParameter(model.name, fullRefName)));
                            TagPage.class, WicketUtils.newObjectParameter(push.repository, fullRefName)));
                } else {
                    // link to tree
                    pushItem.add(new LinkPanel("refPushed", null, shortRefName,
                        TreePage.class, WicketUtils.newObjectParameter(model.name, fullRefName)));
                        TreePage.class, WicketUtils.newObjectParameter(push.repository, fullRefName)));
                }
                
                // to/from/etc
                pushItem.add(new Label("repoPreposition", getString(preposition)));
                
                String repoName = StringUtils.stripDotGit(model.name);
                String repoName = StringUtils.stripDotGit(push.repository);
                pushItem.add(new LinkPanel("repoPushed", null, repoName,
                        SummaryPage.class, WicketUtils.newRepositoryParameter(model.name)));
                        SummaryPage.class, WicketUtils.newRepositoryParameter(push.repository)));
                int maxCommitCount = 5;
                List<RepositoryCommit> commits = push.getCommits();
@@ -208,7 +241,7 @@
                        }
                        LinkPanel shortlog = new LinkPanel("commitShortMessage", "list",
                                trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
                                        model.name, commit.getName()));
                                        push.repository, commit.getName()));
                        if (!shortMessage.equals(trimmedMessage)) {
                            WicketUtils.setHtmlTooltip(shortlog, shortMessage);
                        }
@@ -217,7 +250,7 @@
                        // commit hash link
                        LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
                                CommitPage.class, WicketUtils.newObjectParameter(
                                        model.name, commit.getName()));
                                        push.repository, commit.getName()));
                        WicketUtils.setCssClass(commitHash, "shortsha1");
                        WicketUtils.setHtmlTooltip(commitHash, commit.getName());
                        commitItem.add(commitHash);
@@ -229,27 +262,7 @@
        };
        add(pushView);
        // determine to show pager, more, or neither
        if (limit <= 0) {
            // no display limit
            add(new Label("morePushes").setVisible(false));
        } else {
            if (pageResults) {
                // paging
                add(new Label("morePushes").setVisible(false));
            } else {
                // more
                if (pushes.size() == limit) {
                    // show more
                    add(new LinkPanel("morePushes", "link", new StringResourceModel("gb.morePushes",
                            this, null), PushesPage.class,
                            WicketUtils.newRepositoryParameter(model.name)));
                } else {
                    // no more
                    add(new Label("morePushes").setVisible(false));
                }
            }
        }
    }
    public boolean hasMore() {