Example usage for org.eclipse.jgit.transport RefAdvertiser init

List of usage examples for org.eclipse.jgit.transport RefAdvertiser init

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport RefAdvertiser init.

Prototype

public void init(Repository src) 

Source Link

Document

Initialize this advertiser with a repository for peeling tags.

Usage

From source file:org.webcat.core.git.http.InfoRefsRequestHandler.java

License:Open Source License

/**
 * Looks up the requested repository and appends its info/refs to the
 * response.//  ww w.j  a  v a2  s. co  m
 *
 * @param request the request
 * @param response the response
 * @throws Exception if an error occurs
 */
public void handleRequest(WORequest request, WOResponse response) throws Exception {
    response.setHeader("text/plain", "Content-Type");

    NSMutableDataOutputStream outputStream = new NSMutableDataOutputStream();

    Repository repo = RepositoryRequestUtils.repositoryFromRequest(request);
    //RevWalk walk = new RevWalk(repo);

    //try
    //{
    //final RevFlag ADVERTISED = walk.newFlag("ADVERTISED");

    final OutputStreamWriter out = new OutputStreamWriter(outputStream, Constants.CHARSET);

    final RefAdvertiser adv = new RefAdvertiser() {
        protected void writeOne(CharSequence line) throws IOException {
            out.append(line.toString().replace(' ', '\t'));
        }

        protected void end() {
            // Do nothing.
        }
    };

    adv.init(repo);
    //adv.init(walk, ADVERTISED);
    adv.setDerefTags(true);

    Map<String, Ref> refs = repo.getAllRefs();
    refs.remove(Constants.HEAD);
    adv.send(refs);
    //}
    //finally
    //{
    //walk.release();
    //}

    outputStream.close();
    response.appendContentData(outputStream.data());
}