You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LocalObjectRepresentation.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.file;
  11. import java.io.IOException;
  12. import org.eclipse.jgit.internal.storage.pack.StoredObjectRepresentation;
  13. import org.eclipse.jgit.lib.ObjectId;
  14. class LocalObjectRepresentation extends StoredObjectRepresentation {
  15. static LocalObjectRepresentation newWhole(Pack pack, long offset, long length) {
  16. LocalObjectRepresentation r = new LocalObjectRepresentation() {
  17. @Override
  18. public int getFormat() {
  19. return PACK_WHOLE;
  20. }
  21. };
  22. r.pack = pack;
  23. r.offset = offset;
  24. r.length = length;
  25. return r;
  26. }
  27. static LocalObjectRepresentation newDelta(Pack pack, long offset, long length,
  28. ObjectId base) {
  29. LocalObjectRepresentation r = new Delta();
  30. r.pack = pack;
  31. r.offset = offset;
  32. r.length = length;
  33. r.baseId = base;
  34. return r;
  35. }
  36. static LocalObjectRepresentation newDelta(Pack pack, long offset, long length,
  37. long base) {
  38. LocalObjectRepresentation r = new Delta();
  39. r.pack = pack;
  40. r.offset = offset;
  41. r.length = length;
  42. r.baseOffset = base;
  43. return r;
  44. }
  45. Pack pack;
  46. long offset;
  47. long length;
  48. private long baseOffset;
  49. private ObjectId baseId;
  50. /** {@inheritDoc} */
  51. @Override
  52. public int getWeight() {
  53. return (int) Math.min(length, Integer.MAX_VALUE);
  54. }
  55. /** {@inheritDoc} */
  56. @Override
  57. public ObjectId getDeltaBase() {
  58. if (baseId == null && getFormat() == PACK_DELTA) {
  59. try {
  60. baseId = pack.findObjectForOffset(baseOffset);
  61. } catch (IOException error) {
  62. return null;
  63. }
  64. }
  65. return baseId;
  66. }
  67. private static final class Delta extends LocalObjectRepresentation {
  68. @Override
  69. public int getFormat() {
  70. return PACK_DELTA;
  71. }
  72. }
  73. }