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.internal.storage.pack;
12
13 import java.io.IOException;
14
15 /**
16 * Describes a pack file
17 * {@link org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs} can append
18 * onto a stream.
19 */
20 public abstract class CachedPack {
21 /**
22 * Get the number of objects in this pack.
23 *
24 * @return the total object count for the pack.
25 * @throws java.io.IOException
26 * if the object count cannot be read.
27 */
28 public abstract long getObjectCount() throws IOException;
29
30 /**
31 * Get the number of delta objects stored in this pack.
32 * <p>
33 * This is an optional method, not every cached pack storage system knows
34 * the precise number of deltas stored within the pack. This number must be
35 * smaller than {@link #getObjectCount()} as deltas are not supposed to span
36 * across pack files.
37 * <p>
38 * This method must be fast, if the only way to determine delta counts is to
39 * scan the pack file's contents one object at a time, implementors should
40 * return 0 and avoid the high cost of the scan.
41 *
42 * @return the number of deltas; 0 if the number is not known or there are
43 * no deltas.
44 * @throws java.io.IOException
45 * if the delta count cannot be read.
46 */
47 public long getDeltaCount() throws IOException {
48 return 0;
49 }
50
51 /**
52 * Determine if this pack contains the object representation given.
53 * <p>
54 * PackWriter uses this method during the finding sources phase to prune
55 * away any objects from the leading thin-pack that already appear within
56 * this pack and should not be sent twice.
57 * <p>
58 * Implementors are strongly encouraged to rely on looking at {@code rep}
59 * only and using its internal state to decide if this object is within this
60 * pack. Implementors should ensure a representation from this cached pack
61 * is tested as part of
62 * {@link org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs#selectObjectRepresentation(PackWriter, org.eclipse.jgit.lib.ProgressMonitor, Iterable)}
63 * , ensuring this method would eventually return true if the object would
64 * be included by this cached pack.
65 *
66 * @param obj
67 * the object being packed. Can be used as an ObjectId.
68 * @param rep
69 * representation from the
70 * {@link org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs}
71 * instance that originally supplied this CachedPack.
72 * @return true if this pack contains this object.
73 */
74 public abstract boolean hasObject(ObjectToPack obj,
75 StoredObjectRepresentation rep);
76 }