Example usage for org.eclipse.jgit.submodule SubmoduleWalk forPath

List of usage examples for org.eclipse.jgit.submodule SubmoduleWalk forPath

Introduction

In this page you can find the example usage for org.eclipse.jgit.submodule SubmoduleWalk forPath.

Prototype

public static SubmoduleWalk forPath(Repository repository, AbstractTreeIterator iterator, String path)
        throws IOException 

Source Link

Document

Create a generator and advance it to the submodule entry at the given path

Usage

From source file:com.google.gitiles.PathServlet.java

License:Open Source License

private void showGitlink(HttpServletRequest req, HttpServletResponse res, RevWalk rw, TreeWalk tw, RevTree root)
        throws IOException {
    GitilesView view = ViewFilter.getView(req);
    SubmoduleWalk sw = SubmoduleWalk.forPath(ServletUtils.getRepository(req), root, view.getTreePath());

    String remoteUrl;//from  w  ww .j  a v  a  2s  .  c  om
    try {
        remoteUrl = sw.getRemoteUrl();
    } catch (ConfigInvalidException e) {
        throw new IOException(e);
    } finally {
        sw.release();
    }

    Map<String, Object> data = Maps.newHashMap();
    data.put("sha", ObjectId.toString(tw.getObjectId(0)));
    data.put("remoteUrl", remoteUrl);

    // TODO(dborowitz): Guess when we can put commit SHAs in the URL.
    String httpUrl = resolveHttpUrl(remoteUrl);
    if (httpUrl != null) {
        data.put("httpUrl", httpUrl);
    }

    // TODO(sop): Allow caching links by SHA-1 when no S cookie is sent.
    render(req, res, "gitiles.pathDetail",
            ImmutableMap.of("title", view.getTreePath(), "type", FileType.GITLINK.toString(), "data", data));
}