1 /* 2 * Copyright (C) 2009-2010, Google Inc. and others 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the Eclipse Distribution License v. 1.0 which is available at 6 * https://www.eclipse.org/org/documents/edl-v10.php. 7 * 8 * SPDX-License-Identifier: BSD-3-Clause 9 */ 10 11 package org.eclipse.jgit.http.server; 12 13 import static org.eclipse.jgit.http.server.ServletUtils.getRepository; 14 import static org.eclipse.jgit.http.server.ServletUtils.sendPlainText; 15 16 import java.io.IOException; 17 18 import javax.servlet.http.HttpServlet; 19 import javax.servlet.http.HttpServletRequest; 20 import javax.servlet.http.HttpServletResponse; 21 22 import org.eclipse.jgit.internal.storage.file.ObjectDirectory; 23 import org.eclipse.jgit.internal.storage.file.Pack; 24 import org.eclipse.jgit.lib.ObjectDatabase; 25 26 /** Sends the current list of pack files, sorted most recent first. */ 27 class InfoPacksServlet extends HttpServlet { 28 private static final long serialVersionUID = 1L; 29 30 /** {@inheritDoc} */ 31 @Override doGet(final HttpServletRequest req, final HttpServletResponse rsp)32 public void doGet(final HttpServletRequest req, 33 final HttpServletResponse rsp) throws IOException { 34 sendPlainText(packList(req), req, rsp); 35 } 36 packList(HttpServletRequest req)37 private static String packList(HttpServletRequest req) { 38 final StringBuilder out = new StringBuilder(); 39 final ObjectDatabase db = getRepository(req).getObjectDatabase(); 40 if (db instanceof ObjectDirectory) { 41 for (Pack pack : ((ObjectDirectory) db).getPacks()) { 42 out.append("P "); 43 out.append(pack.getPackFile().getName()); 44 out.append('\n'); 45 } 46 } 47 out.append('\n'); 48 return out.toString(); 49 } 50 } 51