1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.http.server;
12
13 import static java.nio.charset.StandardCharsets.UTF_8;
14 import static org.eclipse.jgit.http.server.ServletUtils.getRepository;
15
16 import java.io.IOException;
17 import java.io.OutputStreamWriter;
18
19 import javax.servlet.http.HttpServlet;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.eclipse.jgit.lib.Constants;
24 import org.eclipse.jgit.lib.Repository;
25 import org.eclipse.jgit.transport.RefAdvertiser;
26 import org.eclipse.jgit.util.HttpSupport;
27
28
29 class InfoRefsServlet extends HttpServlet {
30 private static final long serialVersionUID = 1L;
31
32
33 @Override
34 public void doGet(final HttpServletRequest req,
35 final HttpServletResponse rsp) throws IOException {
36
37
38 rsp.setContentType(HttpSupport.TEXT_PLAIN);
39 rsp.setCharacterEncoding(UTF_8.name());
40
41 final Repository db = getRepository(req);
42 try (OutputStreamWriter out = new OutputStreamWriter(
43 new SmartOutputStream(req, rsp, true),
44 UTF_8)) {
45 final RefAdvertiser adv = new RefAdvertiser() {
46 @Override
47 protected void writeOne(CharSequence line)
48 throws IOException {
49
50
51
52 out.append(line.toString().replace(' ', '\t'));
53 }
54
55 @Override
56 protected void end() {
57
58 }
59 };
60 adv.init(db);
61 adv.setDerefTags(true);
62 adv.send(db.getRefDatabase().getRefsByPrefix(Constants.R_REFS));
63 }
64 }
65 }