View Javadoc
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  
11  package org.eclipse.jgit.internal.storage.pack;
12  
13  import org.eclipse.jgit.lib.ObjectId;
14  
15  /**
16   * An object representation
17   * {@link org.eclipse.jgit.internal.storage.pack.PackWriter} can consider for
18   * packing.
19   */
20  public class StoredObjectRepresentation {
21  	/** Special unknown value for {@link #getWeight()}. */
22  	public static final int WEIGHT_UNKNOWN = Integer.MAX_VALUE;
23  
24  	/** Stored in pack format, as a delta to another object. */
25  	public static final int PACK_DELTA = 0;
26  
27  	/** Stored in pack format, without delta. */
28  	public static final int PACK_WHOLE = 1;
29  
30  	/** Only available after inflating to canonical format. */
31  	public static final int FORMAT_OTHER = 2;
32  
33  	/**
34  	 * Get relative size of this object's packed form.
35  	 *
36  	 * @return relative size of this object's packed form. The special value
37  	 *         {@link #WEIGHT_UNKNOWN} can be returned to indicate the
38  	 *         implementation doesn't know, or cannot supply the weight up
39  	 *         front.
40  	 */
41  	public int getWeight() {
42  		return WEIGHT_UNKNOWN;
43  	}
44  
45  	/**
46  	 * Get the storage format type
47  	 *
48  	 * @return the storage format type, which must be one of
49  	 *         {@link #PACK_DELTA}, {@link #PACK_WHOLE}, or
50  	 *         {@link #FORMAT_OTHER}.
51  	 */
52  	public int getFormat() {
53  		return FORMAT_OTHER;
54  	}
55  
56  	/**
57  	 * Get identity of the object this delta applies to in order to recover the
58  	 * original object content.
59  	 *
60  	 * @return identity of the object this delta applies to in order to recover
61  	 *         the original object content. This method should only be called if
62  	 *         {@link #getFormat()} returned {@link #PACK_DELTA}.
63  	 */
64  	public ObjectId getDeltaBase() {
65  		return null;
66  	}
67  
68  	/**
69  	 * Whether the current representation of the object has had delta
70  	 * compression attempted on it.
71  	 *
72  	 * @return whether the current representation of the object has had delta
73  	 *         compression attempted on it.
74  	 */
75  	public boolean wasDeltaAttempted() {
76  		int fmt = getFormat();
77  		return fmt == PACK_DELTA || fmt == PACK_WHOLE;
78  	}
79  }