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 final class DeltaWindowEntry {
14 DeltaWindowEntry prev;
15 DeltaWindowEntry next;
16 ObjectToPack object;
17
18 /** Complete contents of this object. Lazily loaded. */
19 byte[] buffer;
20
21 /** Index of this object's content, to encode other deltas. Lazily loaded. */
22 DeltaIndex index;
23
24 final void set(ObjectToPack object) {
25 this.object = object;
26 this.index = null;
27 this.buffer = null;
28 }
29
30 /** @return current delta chain depth of this object. */
31 final int depth() {
32 return object.getDeltaDepth();
33 }
34
35 /** @return type of the object in this window entry. */
36 final int type() {
37 return object.getType();
38 }
39
40 /** @return estimated unpacked size of the object, in bytes . */
41 final int size() {
42 return object.getWeight();
43 }
44
45 /** @return true if there is no object stored in this entry. */
46 final boolean empty() {
47 return object == null;
48 }
49
50 final void makeNext(DeltaWindowEntry e) {
51 // Disconnect e from the chain.
52 e.prev.next = e.next;
53 e.next.prev = e.prev;
54
55 // Insert e after this.
56 e.next = next;
57 e.prev = this;
58 next.prev = e;
59 next = e;
60 }
61
62 static DeltaWindowEntry createWindow(int cnt) {
63 // C Git increases the window size supplied by the user by 1.
64 // We don't know why it does this, but if the user asks for
65 // window=10, it actually processes with window=11. Because
66 // the window size has the largest direct impact on the final
67 // pack file size, we match this odd behavior here to give us
68 // a better chance of producing a similar sized pack as C Git.
69 //
70 // We would prefer to directly honor the user's request since
71 // PackWriter has a minimum of 2 for the window size, but then
72 // users might complain that JGit is creating a bigger pack file.
73 DeltaWindowEntry res = new DeltaWindowEntry();
74 DeltaWindowEntry p = res;
75 for (int i = 0; i < cnt; i++) {
76 DeltaWindowEntry e = new DeltaWindowEntry();
77 e.prev = p;
78 p.next = e;
79 p = e;
80 }
81 p.next = res;
82 res.prev = p;
83 return res;
84 }
85 }