aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivedPackStatistics.java
blob: d7bc40006bf45785d0e0fc15937760127c535127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * Copyright (C) 2016, Google Inc. and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.transport;

import org.eclipse.jgit.lib.Constants;

/**
 * Statistics about {@link org.eclipse.jgit.transport.PackParser}.
 *
 * @since 4.6
 */
public class ReceivedPackStatistics {
	private long numBytesRead;
	private long numBytesDuplicated;

	private long numWholeCommit;
	private long numWholeTree;
	private long numWholeBlob;
	private long numWholeTag;
	private long numOfsDelta;
	private long numRefDelta;
	private long numObjectsDuplicated;

	private long numDeltaCommit;
	private long numDeltaTree;
	private long numDeltaBlob;
	private long numDeltaTag;

	/**
	 * Get number of bytes read from the input stream
	 *
	 * @return number of bytes read from the input stream
	 */
	public long getNumBytesRead() {
		return numBytesRead;
	}

	/**
	 * Get number of bytes of objects already in the local database
	 *
	 * @return number of bytes of objects appeared in both the pack sent by the
	 *         client and the local database
	 * @since 5.10
	 */
	public long getNumBytesDuplicated() {
		return numBytesDuplicated;
	}

	/**
	 * Get number of whole commit objects in the pack
	 *
	 * @return number of whole commit objects in the pack
	 */
	public long getNumWholeCommit() {
		return numWholeCommit;
	}

	/**
	 * Get number of whole tree objects in the pack
	 *
	 * @return number of whole tree objects in the pack
	 */
	public long getNumWholeTree() {
		return numWholeTree;
	}

	/**
	 * Get number of whole blob objects in the pack
	 *
	 * @return number of whole blob objects in the pack
	 */
	public long getNumWholeBlob() {
		return numWholeBlob;
	}

	/**
	 * Get number of whole tag objects in the pack
	 *
	 * @return number of whole tag objects in the pack
	 */
	public long getNumWholeTag() {
		return numWholeTag;
	}

	/**
	 * Get number of offset delta objects in the pack
	 *
	 * @return number of offset delta objects in the pack
	 */
	public long getNumOfsDelta() {
		return numOfsDelta;
	}

	/**
	 * Get number of ref delta objects in the pack
	 *
	 * @return number of ref delta objects in the pack
	 */
	public long getNumRefDelta() {
		return numRefDelta;
	}

	/**
	 * Get number of objects already in the local database
	 *
	 * @return number of objects appeared in both the pack sent by the client
	 *         and the local database
	 * @since 5.10
	 */
	public long getNumObjectsDuplicated() {
		return numObjectsDuplicated;
	}

	/**
	 * Get number of delta commit objects in the pack
	 *
	 * @return number of delta commit objects in the pack
	 */
	public long getNumDeltaCommit() {
		return numDeltaCommit;
	}

	/**
	 * Get number of delta tree objects in the pack
	 *
	 * @return number of delta tree objects in the pack
	 */
	public long getNumDeltaTree() {
		return numDeltaTree;
	}

	/**
	 * Get number of delta blob objects in the pack
	 *
	 * @return number of delta blob objects in the pack
	 */
	public long getNumDeltaBlob() {
		return numDeltaBlob;
	}

	/**
	 * Get number of delta tag objects in the pack
	 *
	 * @return number of delta tag objects in the pack
	 */
	public long getNumDeltaTag() {
		return numDeltaTag;
	}

	/** A builder for {@link ReceivedPackStatistics}. */
	public static class Builder {
		private long numBytesRead;
		private long numBytesDuplicated;

		private long numWholeCommit;
		private long numWholeTree;
		private long numWholeBlob;
		private long numWholeTag;
		private long numOfsDelta;
		private long numRefDelta;
		private long numObjectsDuplicated;

		private long numDeltaCommit;
		private long numDeltaTree;
		private long numDeltaBlob;
		private long numDeltaTag;

		/**
		 * @param numBytesRead number of bytes read from the input stream
		 * @return this
		 */
		public Builder setNumBytesRead(long numBytesRead) {
			this.numBytesRead = numBytesRead;
			return this;
		}

		/**
		 * @param size
		 *            additional bytes already in the local database
		 * @return this
		 * @since 5.10
		 */
		Builder incrementNumBytesDuplicated(long size) {
			numBytesDuplicated += size;
			return this;
		}

		/**
		 * Increment a whole object count.
		 *
		 * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
		 * @return this
		 */
		public Builder addWholeObject(int type) {
			switch (type) {
				case Constants.OBJ_COMMIT:
					numWholeCommit++;
					break;
				case Constants.OBJ_TREE:
					numWholeTree++;
					break;
				case Constants.OBJ_BLOB:
					numWholeBlob++;
					break;
				case Constants.OBJ_TAG:
					numWholeTag++;
					break;
				default:
					throw new IllegalArgumentException(
							type + " cannot be a whole object"); //$NON-NLS-1$
			}
			return this;
		}

		/** @return this */
		public Builder addOffsetDelta() {
			numOfsDelta++;
			return this;
		}

		/** @return this */
		public Builder addRefDelta() {
			numRefDelta++;
			return this;
		}

		/**
		 * Increment the duplicated object count.
		 *
		 * @return this
		 * @since 5.10
		 */
		Builder incrementObjectsDuplicated() {
			numObjectsDuplicated++;
			return this;
		}

		/**
		 * Increment a delta object count.
		 *
		 * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
		 * @return this
		 */
		public Builder addDeltaObject(int type) {
			switch (type) {
				case Constants.OBJ_COMMIT:
					numDeltaCommit++;
					break;
				case Constants.OBJ_TREE:
					numDeltaTree++;
					break;
				case Constants.OBJ_BLOB:
					numDeltaBlob++;
					break;
				case Constants.OBJ_TAG:
					numDeltaTag++;
					break;
				default:
					throw new IllegalArgumentException(
							"delta should be a delta to a whole object. " + //$NON-NLS-1$
							type + " cannot be a whole object"); //$NON-NLS-1$
			}
			return this;
		}

		ReceivedPackStatistics build() {
			ReceivedPackStatistics s = new ReceivedPackStatistics();
			s.numBytesRead = numBytesRead;
			s.numBytesDuplicated = numBytesDuplicated;
			s.numWholeCommit = numWholeCommit;
			s.numWholeTree = numWholeTree;
			s.numWholeBlob = numWholeBlob;
			s.numWholeTag = numWholeTag;
			s.numOfsDelta = numOfsDelta;
			s.numRefDelta = numRefDelta;
			s.numDeltaCommit = numDeltaCommit;
			s.numDeltaTree = numDeltaTree;
			s.numDeltaBlob = numDeltaBlob;
			s.numDeltaTag = numDeltaTag;
			s.numObjectsDuplicated = numObjectsDuplicated;
			return s;
		}
	}
}