CachedPack.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.internal.storage.pack;

  11. import java.io.IOException;

  12. /**
  13.  * Describes a pack file
  14.  * {@link org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs} can append
  15.  * onto a stream.
  16.  */
  17. public abstract class CachedPack {
  18.     /**
  19.      * Get the number of objects in this pack.
  20.      *
  21.      * @return the total object count for the pack.
  22.      * @throws java.io.IOException
  23.      *             if the object count cannot be read.
  24.      */
  25.     public abstract long getObjectCount() throws IOException;

  26.     /**
  27.      * Get the number of delta objects stored in this pack.
  28.      * <p>
  29.      * This is an optional method, not every cached pack storage system knows
  30.      * the precise number of deltas stored within the pack. This number must be
  31.      * smaller than {@link #getObjectCount()} as deltas are not supposed to span
  32.      * across pack files.
  33.      * <p>
  34.      * This method must be fast, if the only way to determine delta counts is to
  35.      * scan the pack file's contents one object at a time, implementors should
  36.      * return 0 and avoid the high cost of the scan.
  37.      *
  38.      * @return the number of deltas; 0 if the number is not known or there are
  39.      *         no deltas.
  40.      * @throws java.io.IOException
  41.      *             if the delta count cannot be read.
  42.      */
  43.     public long getDeltaCount() throws IOException {
  44.         return 0;
  45.     }

  46.     /**
  47.      * Determine if this pack contains the object representation given.
  48.      * <p>
  49.      * PackWriter uses this method during the finding sources phase to prune
  50.      * away any objects from the leading thin-pack that already appear within
  51.      * this pack and should not be sent twice.
  52.      * <p>
  53.      * Implementors are strongly encouraged to rely on looking at {@code rep}
  54.      * only and using its internal state to decide if this object is within this
  55.      * pack. Implementors should ensure a representation from this cached pack
  56.      * is tested as part of
  57.      * {@link org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs#selectObjectRepresentation(PackWriter, org.eclipse.jgit.lib.ProgressMonitor, Iterable)}
  58.      * , ensuring this method would eventually return true if the object would
  59.      * be included by this cached pack.
  60.      *
  61.      * @param obj
  62.      *            the object being packed. Can be used as an ObjectId.
  63.      * @param rep
  64.      *            representation from the
  65.      *            {@link org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs}
  66.      *            instance that originally supplied this CachedPack.
  67.      * @return true if this pack contains this object.
  68.      */
  69.     public abstract boolean hasObject(ObjectToPack obj,
  70.             StoredObjectRepresentation rep);
  71. }