15e33a1deSShawn O. Pearce /* 25c5f7c6bSMatthias Sohn * Copyright (C) 2009-2010, Google Inc. and others 35e33a1deSShawn O. Pearce * 45c5f7c6bSMatthias Sohn * This program and the accompanying materials are made available under the 55c5f7c6bSMatthias Sohn * terms of the Eclipse Distribution License v. 1.0 which is available at 65c5f7c6bSMatthias Sohn * https://www.eclipse.org/org/documents/edl-v10.php. 75e33a1deSShawn O. Pearce * 85c5f7c6bSMatthias Sohn * SPDX-License-Identifier: BSD-3-Clause 95e33a1deSShawn O. Pearce */ 105e33a1deSShawn O. Pearce 115e33a1deSShawn O. Pearce package org.eclipse.jgit.http.server; 125e33a1deSShawn O. Pearce 135e33a1deSShawn O. Pearce import static org.eclipse.jgit.http.server.ServletUtils.getRepository; 145e33a1deSShawn O. Pearce import static org.eclipse.jgit.http.server.ServletUtils.sendPlainText; 155e33a1deSShawn O. Pearce 165e33a1deSShawn O. Pearce import java.io.IOException; 175e33a1deSShawn O. Pearce 185e33a1deSShawn O. Pearce import javax.servlet.http.HttpServlet; 195e33a1deSShawn O. Pearce import javax.servlet.http.HttpServletRequest; 205e33a1deSShawn O. Pearce import javax.servlet.http.HttpServletResponse; 215e33a1deSShawn O. Pearce 22f32b8612SShawn Pearce import org.eclipse.jgit.internal.storage.file.ObjectDirectory; 23*efb154fcSNasser Grainawi import org.eclipse.jgit.internal.storage.file.Pack; 245e33a1deSShawn O. Pearce import org.eclipse.jgit.lib.ObjectDatabase; 255e33a1deSShawn O. Pearce 265e33a1deSShawn O. Pearce /** Sends the current list of pack files, sorted most recent first. */ 275e33a1deSShawn O. Pearce class InfoPacksServlet extends HttpServlet { 285e33a1deSShawn O. Pearce private static final long serialVersionUID = 1L; 295e33a1deSShawn O. Pearce 303b00041cSMatthias Sohn /** {@inheritDoc} */ 317ac182f4SDavid Pursehouse @Override doGet(final HttpServletRequest req, final HttpServletResponse rsp)325e33a1deSShawn O. Pearce public void doGet(final HttpServletRequest req, 335e33a1deSShawn O. Pearce final HttpServletResponse rsp) throws IOException { 345e33a1deSShawn O. Pearce sendPlainText(packList(req), req, rsp); 355e33a1deSShawn O. Pearce } 365e33a1deSShawn O. Pearce packList(HttpServletRequest req)376d370d83SHan-Wen Nienhuys private static String packList(HttpServletRequest req) { 385e33a1deSShawn O. Pearce final StringBuilder out = new StringBuilder(); 395e33a1deSShawn O. Pearce final ObjectDatabase db = getRepository(req).getObjectDatabase(); 405e33a1deSShawn O. Pearce if (db instanceof ObjectDirectory) { 41*efb154fcSNasser Grainawi for (Pack pack : ((ObjectDirectory) db).getPacks()) { 425e33a1deSShawn O. Pearce out.append("P "); 435e33a1deSShawn O. Pearce out.append(pack.getPackFile().getName()); 445e33a1deSShawn O. Pearce out.append('\n'); 455e33a1deSShawn O. Pearce } 465e33a1deSShawn O. Pearce } 475e33a1deSShawn O. Pearce out.append('\n'); 485e33a1deSShawn O. Pearce return out.toString(); 495e33a1deSShawn O. Pearce } 505e33a1deSShawn O. Pearce } 51