StoredObjectRepresentation.java

  1. /*
  2.  * Copyright (C) 2010, 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 org.eclipse.jgit.lib.ObjectId;

  12. /**
  13.  * An object representation
  14.  * {@link org.eclipse.jgit.internal.storage.pack.PackWriter} can consider for
  15.  * packing.
  16.  */
  17. public class StoredObjectRepresentation {
  18.     /** Special unknown value for {@link #getWeight()}. */
  19.     public static final int WEIGHT_UNKNOWN = Integer.MAX_VALUE;

  20.     /** Stored in pack format, as a delta to another object. */
  21.     public static final int PACK_DELTA = 0;

  22.     /** Stored in pack format, without delta. */
  23.     public static final int PACK_WHOLE = 1;

  24.     /** Only available after inflating to canonical format. */
  25.     public static final int FORMAT_OTHER = 2;

  26.     /**
  27.      * Get relative size of this object's packed form.
  28.      *
  29.      * @return relative size of this object's packed form. The special value
  30.      *         {@link #WEIGHT_UNKNOWN} can be returned to indicate the
  31.      *         implementation doesn't know, or cannot supply the weight up
  32.      *         front.
  33.      */
  34.     public int getWeight() {
  35.         return WEIGHT_UNKNOWN;
  36.     }

  37.     /**
  38.      * Get the storage format type
  39.      *
  40.      * @return the storage format type, which must be one of
  41.      *         {@link #PACK_DELTA}, {@link #PACK_WHOLE}, or
  42.      *         {@link #FORMAT_OTHER}.
  43.      */
  44.     public int getFormat() {
  45.         return FORMAT_OTHER;
  46.     }

  47.     /**
  48.      * Get identity of the object this delta applies to in order to recover the
  49.      * original object content.
  50.      *
  51.      * @return identity of the object this delta applies to in order to recover
  52.      *         the original object content. This method should only be called if
  53.      *         {@link #getFormat()} returned {@link #PACK_DELTA}.
  54.      */
  55.     public ObjectId getDeltaBase() {
  56.         return null;
  57.     }

  58.     /**
  59.      * Whether the current representation of the object has had delta
  60.      * compression attempted on it.
  61.      *
  62.      * @return whether the current representation of the object has had delta
  63.      *         compression attempted on it.
  64.      */
  65.     public boolean wasDeltaAttempted() {
  66.         int fmt = getFormat();
  67.         return fmt == PACK_DELTA || fmt == PACK_WHOLE;
  68.     }
  69. }