PreUploadHook.java

  1. /*
  2.  * Copyright (C) 2011, 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. package org.eclipse.jgit.transport;

  11. import java.util.Collection;

  12. import org.eclipse.jgit.lib.ObjectId;

  13. /**
  14.  * Hook invoked by {@link org.eclipse.jgit.transport.UploadPack} before during
  15.  * critical phases.
  16.  * <p>
  17.  * If any hook function throws
  18.  * {@link org.eclipse.jgit.transport.ServiceMayNotContinueException} then
  19.  * processing stops immediately and the exception is thrown up the call stack.
  20.  * Most phases of UploadPack will try to report the exception's message text to
  21.  * the end-user over the client's protocol connection.
  22.  */
  23. public interface PreUploadHook {
  24.     /** A simple no-op hook. */
  25.     PreUploadHook NULL = new PreUploadHook() {
  26.         @Override
  27.         public void onBeginNegotiateRound(UploadPack up,
  28.                 Collection<? extends ObjectId> wants, int cntOffered)
  29.                 throws ServiceMayNotContinueException {
  30.             // Do nothing.
  31.         }

  32.         @Override
  33.         public void onEndNegotiateRound(UploadPack up,
  34.                 Collection<? extends ObjectId> wants, int cntCommon,
  35.                 int cntNotFound, boolean ready)
  36.                 throws ServiceMayNotContinueException {
  37.             // Do nothing.
  38.         }

  39.         @Override
  40.         public void onSendPack(UploadPack up,
  41.                 Collection<? extends ObjectId> wants,
  42.                 Collection<? extends ObjectId> haves)
  43.                 throws ServiceMayNotContinueException {
  44.             // Do nothing.
  45.         }
  46.     };

  47.     /**
  48.      * Invoked before negotiation round is started.
  49.      *
  50.      * @param up
  51.      *            the upload pack instance handling the connection.
  52.      * @param wants
  53.      *            the list of wanted objects.
  54.      * @param cntOffered
  55.      *            number of objects the client has offered.
  56.      * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
  57.      *             abort; the message will be sent to the user.
  58.      */
  59.     void onBeginNegotiateRound(UploadPack up,
  60.             Collection<? extends ObjectId> wants, int cntOffered)
  61.             throws ServiceMayNotContinueException;

  62.     /**
  63.      * Invoked after a negotiation round is completed.
  64.      *
  65.      * @param up
  66.      *            the upload pack instance handling the connection.
  67.      * @param wants
  68.      *            the list of wanted objects.
  69.      * @param cntCommon
  70.      *            number of objects this round found to be common. In a smart
  71.      *            HTTP transaction this includes the objects that were
  72.      *            previously found to be common.
  73.      * @param cntNotFound
  74.      *            number of objects in this round the local repository does not
  75.      *            have, but that were offered as potential common bases.
  76.      * @param ready
  77.      *            true if a pack is ready to be sent (the commit graph was
  78.      *            successfully cut).
  79.      * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
  80.      *             abort; the message will be sent to the user.
  81.      */
  82.     void onEndNegotiateRound(UploadPack up,
  83.             Collection<? extends ObjectId> wants, int cntCommon,
  84.             int cntNotFound, boolean ready)
  85.             throws ServiceMayNotContinueException;

  86.     /**
  87.      * Invoked just before a pack will be sent to the client.
  88.      *
  89.      * @param up
  90.      *            the upload pack instance handling the connection.
  91.      * @param wants
  92.      *            the list of wanted objects. These may be RevObject or
  93.      *            RevCommit if the processed parsed them. Implementors should
  94.      *            not rely on the values being parsed.
  95.      * @param haves
  96.      *            the list of common objects. Empty on an initial clone request.
  97.      *            These may be RevObject or RevCommit if the processed parsed
  98.      *            them. Implementors should not rely on the values being parsed.
  99.      * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
  100.      *             abort; the message will be sent to the user.
  101.      */
  102.     void onSendPack(UploadPack up, Collection<? extends ObjectId> wants,
  103.             Collection<? extends ObjectId> haves)
  104.             throws ServiceMayNotContinueException;
  105. }