DeltaWindowEntry.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. final class DeltaWindowEntry {
  12.     DeltaWindowEntry prev;
  13.     DeltaWindowEntry next;
  14.     ObjectToPack object;

  15.     /** Complete contents of this object. Lazily loaded. */
  16.     byte[] buffer;

  17.     /** Index of this object's content, to encode other deltas. Lazily loaded. */
  18.     DeltaIndex index;

  19.     final void set(ObjectToPack object) {
  20.         this.object = object;
  21.         this.index = null;
  22.         this.buffer = null;
  23.     }

  24.     /** @return current delta chain depth of this object. */
  25.     final int depth() {
  26.         return object.getDeltaDepth();
  27.     }

  28.     /** @return type of the object in this window entry. */
  29.     final int type() {
  30.         return object.getType();
  31.     }

  32.     /** @return estimated unpacked size of the object, in bytes . */
  33.     final int size() {
  34.         return object.getWeight();
  35.     }

  36.     /** @return true if there is no object stored in this entry. */
  37.     final boolean empty() {
  38.         return object == null;
  39.     }

  40.     final void makeNext(DeltaWindowEntry e) {
  41.         // Disconnect e from the chain.
  42.         e.prev.next = e.next;
  43.         e.next.prev = e.prev;

  44.         // Insert e after this.
  45.         e.next = next;
  46.         e.prev = this;
  47.         next.prev = e;
  48.         next = e;
  49.     }

  50.     static DeltaWindowEntry createWindow(int cnt) {
  51.         // C Git increases the window size supplied by the user by 1.
  52.         // We don't know why it does this, but if the user asks for
  53.         // window=10, it actually processes with window=11. Because
  54.         // the window size has the largest direct impact on the final
  55.         // pack file size, we match this odd behavior here to give us
  56.         // a better chance of producing a similar sized pack as C Git.
  57.         //
  58.         // We would prefer to directly honor the user's request since
  59.         // PackWriter has a minimum of 2 for the window size, but then
  60.         // users might complain that JGit is creating a bigger pack file.
  61.         DeltaWindowEntry res = new DeltaWindowEntry();
  62.         DeltaWindowEntry p = res;
  63.         for (int i = 0; i < cnt; i++) {
  64.             DeltaWindowEntry e = new DeltaWindowEntry();
  65.             e.prev = p;
  66.             p.next = e;
  67.             p = e;
  68.         }
  69.         p.next = res;
  70.         res.prev = p;
  71.         return res;
  72.     }
  73. }