Paul Martin
2016-03-21 77c38a1865564a4ea4544bfb1f52bedf4326d481
Fix for #1018 and #1025 browser LFS links

+ View and Raw both download the actual file
+ Blame will show the metafile
4 files modified
291 ■■■■■ changed files
src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java 86 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/pages/CommitPage.java 100 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/pages/TreePage.java 83 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/LinkPanel.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
@@ -15,6 +15,7 @@
 */
package com.gitblit.wicket.pages;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -23,9 +24,13 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
import org.apache.wicket.util.resource.IResourceStream;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -35,6 +40,7 @@
import com.gitblit.models.GitNote;
import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.models.UserModel;
import com.gitblit.servlet.RawServlet;
import com.gitblit.utils.DiffUtils;
import com.gitblit.utils.DiffUtils.DiffComparator;
@@ -42,6 +48,7 @@
import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
@@ -135,7 +142,6 @@
            @Override
            public void populateItem(final Item<PathChangeModel> item) {
                final PathChangeModel entry = item.getModelObject();
                final String filestoreItemUrl = entry.isFilestoreItem() ? JGitUtils.getLfsRepositoryUrl(getContextUrl(), repositoryName, entry.getFilestoreOid()) : null;
                
                Label changeType = new Label("changeType", "");
                WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
@@ -162,7 +168,34 @@
                    item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#n" + entry.objectId));
                } else {
                    // add relative link
                    item.add(new LinkPanel("pathName", "list", entry.path, entry.isFilestoreItem() ? filestoreItemUrl : "#n" + entry.objectId));
                    if (entry.isFilestoreItem()) {
                        item.add(new LinkPanel("pathName", "list", entry.path, new Link<Object>("link", null) {
                            private static final long serialVersionUID = 1L;
                            @Override
                            public void onClick() {
                                IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                    private static final long serialVersionUID = 1L;
                                    @Override
                                    public void write(OutputStream output) {
                                        UserModel user =  GitBlitWebSession.get().getUser();
                                        user = user == null ? UserModel.ANONYMOUS : user;
                                        app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                    }
                                };
                                getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                            }}));
                    }
                    else
                    {
                        item.add(new LinkPanel("pathName", "list", entry.path, "#n" + entry.objectId));
                    }
                }
                // quick links
@@ -188,8 +221,53 @@
                    if (entry.isFilestoreItem()) {
                        item.add(new Label("filestore", getString("gb.filestore")).setVisible(true));
                        
                        item.add(new ExternalLink("view", filestoreItemUrl));
                        item.add(new ExternalLink("raw", filestoreItemUrl));
                        item.add(new Link<Object>("view", null) {
                            private static final long serialVersionUID = 1L;
                            @Override
                            public void onClick() {
                                 IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                    private static final long serialVersionUID = 1L;
                                    @Override
                                      public void write(OutputStream output) {
                                            UserModel user =  GitBlitWebSession.get().getUser();
                                         user = user == null ? UserModel.ANONYMOUS : user;
                                        app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                      }
                                  };
                                getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                            }});
                        item.add(new Link<Object>("raw", null) {
                            private static final long serialVersionUID = 1L;
                            @Override
                            public void onClick() {
                                 IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                    private static final long serialVersionUID = 1L;
                                    @Override
                                      public void write(OutputStream output) {
                                            UserModel user =  GitBlitWebSession.get().getUser();
                                         user = user == null ? UserModel.ANONYMOUS : user;
                                        app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                      }
                                  };
                                getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                            }});
                    } else {
                        
                        item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
src/main/java/com/gitblit/wicket/pages/CommitPage.java
@@ -15,29 +15,51 @@
 */
package com.gitblit.wicket.pages;
import java.io.OutputStream;
import java.sql.Blob;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.DownloadLink;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.link.ResourceLink;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
import org.apache.wicket.util.resource.AbstractResourceStream;
import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
import org.apache.wicket.util.resource.IResourceStream;
import org.bouncycastle.jcajce.provider.symmetric.Threefish;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.Constants;
import com.gitblit.GitBlit;
import com.gitblit.manager.FilestoreManager;
import com.gitblit.manager.GitblitManager;
import com.gitblit.models.FilestoreModel;
import com.gitblit.models.GitNote;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.models.UserModel;
import com.gitblit.servlet.RawServlet;
import com.gitblit.utils.JGitUtils;
import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
@@ -198,7 +220,31 @@
                    }
                    
                    if (entry.isFilestoreItem()) {
                        item.add(new LinkPanel("pathName", "list", entry.path, filestoreItemUrl));
                        item.add(new LinkPanel("pathName", "list", entry.path, new Link<Object>("link", null) {
                            private static final long serialVersionUID = 1L;
                            @Override
                            public void onClick() {
                                 IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                    private static final long serialVersionUID = 1L;
                                    @Override
                                      public void write(OutputStream output) {
                                            UserModel user =  GitBlitWebSession.get().getUser();
                                         user = user == null ? UserModel.ANONYMOUS : user;
                                        app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                      }
                                  };
                                getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                            }}));
                    } else {
                        item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
                            WicketUtils.newPathParameter(repositoryName, entry.commitId, path)));
@@ -232,8 +278,56 @@
                    if (entry.isFilestoreItem()) {
                        item.add(new Label("filestore", getString("gb.filestore")).setVisible(true));
                        
                        item.add(new ExternalLink("view", filestoreItemUrl));
                        item.add(new ExternalLink("raw", filestoreItemUrl));
                        item.add(new Link<Object>("view", null) {
                            private static final long serialVersionUID = 1L;
                            @Override
                            public void onClick() {
                                 IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                    private static final long serialVersionUID = 1L;
                                    @Override
                                      public void write(OutputStream output) {
                                            UserModel user =  GitBlitWebSession.get().getUser();
                                         user = user == null ? UserModel.ANONYMOUS : user;
                                        app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                      }
                                  };
                                getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                            }});
                        item.add(new Link<Object>("raw", null) {
                            private static final long serialVersionUID = 1L;
                            @Override
                            public void onClick() {
                                 IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                    private static final long serialVersionUID = 1L;
                                    @Override
                                      public void write(OutputStream output) {
                                            UserModel user =  GitBlitWebSession.get().getUser();
                                         user = user == null ? UserModel.ANONYMOUS : user;
                                        app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                      }
                                  };
                                getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                            }});
                    } else {
                        item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
                        
src/main/java/com/gitblit/wicket/pages/TreePage.java
@@ -15,26 +15,33 @@
 */
package com.gitblit.wicket.pages;
import java.io.OutputStream;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
import org.apache.wicket.util.resource.IResourceStream;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.models.PathModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.models.UserModel;
import com.gitblit.servlet.RawServlet;
import com.gitblit.utils.ByteFormat;
import com.gitblit.utils.JGitUtils;
import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
@@ -88,7 +95,7 @@
            @Override
            public void populateItem(final Item<PathModel> item) {
                PathModel entry = item.getModelObject();
                final PathModel entry = item.getModelObject();
                
                item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
                
@@ -170,11 +177,77 @@
                        if (entry.isFilestoreItem()) {
                            item.add(new Label("filestore", getString("gb.filestore")).setVisible(true));
                            
                            final String filestoreItemUrl = JGitUtils.getLfsRepositoryUrl(getContextUrl(), repositoryName, entry.getFilestoreOid());
                            item.add(new LinkPanel("pathName", "list", displayPath, new Link<Object>("link", null) {
                                private static final long serialVersionUID = 1L;
                                @Override
                                public void onClick() {
                                     IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                        private static final long serialVersionUID = 1L;
                                        @Override
                                          public void write(OutputStream output) {
                                                UserModel user =  GitBlitWebSession.get().getUser();
                                             user = user == null ? UserModel.ANONYMOUS : user;
                                            app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                          }
                                      };
                                    getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                                }}));
                            
                            item.add(new LinkPanel("pathName", "list", displayPath, filestoreItemUrl));
                            links.add(new ExternalLink("view", filestoreItemUrl));
                            links.add(new ExternalLink("raw", filestoreItemUrl));
                            links.add(new Link<Object>("view", null) {
                                private static final long serialVersionUID = 1L;
                                @Override
                                public void onClick() {
                                     IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                        private static final long serialVersionUID = 1L;
                                        @Override
                                          public void write(OutputStream output) {
                                                UserModel user =  GitBlitWebSession.get().getUser();
                                             user = user == null ? UserModel.ANONYMOUS : user;
                                            app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                          }
                                      };
                                    getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                                }});
                            links.add(new Link<Object>("raw", null) {
                                private static final long serialVersionUID = 1L;
                                @Override
                                public void onClick() {
                                     IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                                        private static final long serialVersionUID = 1L;
                                        @Override
                                          public void write(OutputStream output) {
                                                UserModel user =  GitBlitWebSession.get().getUser();
                                             user = user == null ? UserModel.ANONYMOUS : user;
                                            app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
                                          }
                                      };
                                    getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
                                }});
                            
                        } else {
                            item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
src/main/java/com/gitblit/wicket/panels/LinkPanel.java
@@ -15,6 +15,9 @@
 */
package com.gitblit.wicket.panels;
import java.io.OutputStream;
import java.util.concurrent.Callable;
import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.SimpleAttributeModifier;
@@ -26,8 +29,13 @@
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
import org.apache.wicket.util.resource.IResourceStream;
import com.gitblit.models.UserModel;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
public class LinkPanel extends Panel {
@@ -108,6 +116,20 @@
        add(link);
    }
    public LinkPanel(String wicketId, String linkCssClass, String label, Link<?> link) {
        super(wicketId);
        this.labelModel = new Model<String>(label);
        if (linkCssClass != null) {
            link.add(new SimpleAttributeModifier("class", linkCssClass));
        }
        link.add(new Label("icon").setVisible(false));
        link.add(new Label("label", labelModel));
        add(link);
    }
    public void setNoFollow() {
        Component c = get("link");
        c.add(new SimpleAttributeModifier("rel", "nofollow"));