View Javadoc
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  
11  package org.eclipse.jgit.transport;
12  
13  import java.util.Collection;
14  
15  import org.eclipse.jgit.lib.ObjectId;
16  
17  /**
18   * Hook invoked by {@link org.eclipse.jgit.transport.UploadPack} before during
19   * critical phases.
20   * <p>
21   * If any hook function throws
22   * {@link org.eclipse.jgit.transport.ServiceMayNotContinueException} then
23   * processing stops immediately and the exception is thrown up the call stack.
24   * Most phases of UploadPack will try to report the exception's message text to
25   * the end-user over the client's protocol connection.
26   */
27  public interface PreUploadHook {
28  	/** A simple no-op hook. */
29  	PreUploadHook NULL = new PreUploadHook() {
30  		@Override
31  		public void onBeginNegotiateRound(UploadPack up,
32  				Collection<? extends ObjectId> wants, int cntOffered)
33  				throws ServiceMayNotContinueException {
34  			// Do nothing.
35  		}
36  
37  		@Override
38  		public void onEndNegotiateRound(UploadPack up,
39  				Collection<? extends ObjectId> wants, int cntCommon,
40  				int cntNotFound, boolean ready)
41  				throws ServiceMayNotContinueException {
42  			// Do nothing.
43  		}
44  
45  		@Override
46  		public void onSendPack(UploadPack up,
47  				Collection<? extends ObjectId> wants,
48  				Collection<? extends ObjectId> haves)
49  				throws ServiceMayNotContinueException {
50  			// Do nothing.
51  		}
52  	};
53  
54  	/**
55  	 * Invoked before negotiation round is started.
56  	 *
57  	 * @param up
58  	 *            the upload pack instance handling the connection.
59  	 * @param wants
60  	 *            the list of wanted objects.
61  	 * @param cntOffered
62  	 *            number of objects the client has offered.
63  	 * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
64  	 *             abort; the message will be sent to the user.
65  	 */
66  	void onBeginNegotiateRound(UploadPack up,
67  			Collection<? extends ObjectId> wants, int cntOffered)
68  			throws ServiceMayNotContinueException;
69  
70  	/**
71  	 * Invoked after a negotiation round is completed.
72  	 *
73  	 * @param up
74  	 *            the upload pack instance handling the connection.
75  	 * @param wants
76  	 *            the list of wanted objects.
77  	 * @param cntCommon
78  	 *            number of objects this round found to be common. In a smart
79  	 *            HTTP transaction this includes the objects that were
80  	 *            previously found to be common.
81  	 * @param cntNotFound
82  	 *            number of objects in this round the local repository does not
83  	 *            have, but that were offered as potential common bases.
84  	 * @param ready
85  	 *            true if a pack is ready to be sent (the commit graph was
86  	 *            successfully cut).
87  	 * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
88  	 *             abort; the message will be sent to the user.
89  	 */
90  	void onEndNegotiateRound(UploadPack up,
91  			Collection<? extends ObjectId> wants, int cntCommon,
92  			int cntNotFound, boolean ready)
93  			throws ServiceMayNotContinueException;
94  
95  	/**
96  	 * Invoked just before a pack will be sent to the client.
97  	 *
98  	 * @param up
99  	 *            the upload pack instance handling the connection.
100 	 * @param wants
101 	 *            the list of wanted objects. These may be RevObject or
102 	 *            RevCommit if the processed parsed them. Implementors should
103 	 *            not rely on the values being parsed.
104 	 * @param haves
105 	 *            the list of common objects. Empty on an initial clone request.
106 	 *            These may be RevObject or RevCommit if the processed parsed
107 	 *            them. Implementors should not rely on the values being parsed.
108 	 * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
109 	 *             abort; the message will be sent to the user.
110 	 */
111 	void onSendPack(UploadPack up, Collection<? extends ObjectId> wants,
112 			Collection<? extends ObjectId> haves)
113 			throws ServiceMayNotContinueException;
114 }