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

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

Introduction

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

Prototype

public Set<ObjectId> send(Collection<Ref> refs) throws IOException 

Source Link

Document

Format an advertisement for the supplied refs.

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.//from  w w w .  j  av  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());
}