選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PackIndexWriterV1.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  3. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
  4. *
  5. * This program and the accompanying materials are made available under the
  6. * terms of the Eclipse Distribution License v. 1.0 which is available at
  7. * https://www.eclipse.org/org/documents/edl-v10.php.
  8. *
  9. * SPDX-License-Identifier: BSD-3-Clause
  10. */
  11. package org.eclipse.jgit.internal.storage.file;
  12. import java.io.IOException;
  13. import java.io.OutputStream;
  14. import org.eclipse.jgit.internal.JGitText;
  15. import org.eclipse.jgit.transport.PackedObjectInfo;
  16. import org.eclipse.jgit.util.NB;
  17. /**
  18. * Creates the version 1 (old style) pack table of contents files.
  19. *
  20. * @see PackIndexWriter
  21. * @see PackIndexV1
  22. */
  23. class PackIndexWriterV1 extends PackIndexWriter {
  24. static boolean canStore(PackedObjectInfo oe) {
  25. // We are limited to 4 GB per pack as offset is 32 bit unsigned int.
  26. //
  27. return oe.getOffset() >>> 1 < Integer.MAX_VALUE;
  28. }
  29. PackIndexWriterV1(final OutputStream dst) {
  30. super(dst);
  31. }
  32. /** {@inheritDoc} */
  33. @Override
  34. protected void writeImpl() throws IOException {
  35. writeFanOutTable();
  36. for (PackedObjectInfo oe : entries) {
  37. if (!canStore(oe))
  38. throw new IOException(JGitText.get().packTooLargeForIndexVersion1);
  39. NB.encodeInt32(tmp, 0, (int) oe.getOffset());
  40. oe.copyRawTo(tmp, 4);
  41. out.write(tmp);
  42. }
  43. writeChecksumFooter();
  44. }
  45. }