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.

GcKeepFilesTest.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2012, Christian Halstrick <christian.halstrick@sap.com> 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 static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertFalse;
  13. import static org.junit.Assert.assertTrue;
  14. import java.util.Iterator;
  15. import org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry;
  16. import org.eclipse.jgit.internal.storage.pack.PackExt;
  17. import org.eclipse.jgit.junit.TestRepository.BranchBuilder;
  18. import org.junit.Test;
  19. public class GcKeepFilesTest extends GcTestCase {
  20. @Test
  21. public void testKeepFiles() throws Exception {
  22. BranchBuilder bb = tr.branch("refs/heads/master");
  23. bb.commit().add("A", "A").add("B", "B").create();
  24. stats = gc.getStatistics();
  25. assertEquals(4, stats.numberOfLooseObjects);
  26. assertEquals(0, stats.numberOfPackedObjects);
  27. assertEquals(0, stats.numberOfPackFiles);
  28. gc.gc();
  29. stats = gc.getStatistics();
  30. assertEquals(0, stats.numberOfLooseObjects);
  31. assertEquals(4, stats.numberOfPackedObjects);
  32. assertEquals(1, stats.numberOfPackFiles);
  33. Iterator<Pack> packIt = repo.getObjectDatabase().getPacks()
  34. .iterator();
  35. Pack singlePack = packIt.next();
  36. assertFalse(packIt.hasNext());
  37. PackFile keepFile = singlePack.getPackFile().create(PackExt.KEEP);
  38. assertFalse(keepFile.exists());
  39. assertTrue(keepFile.createNewFile());
  40. bb.commit().add("A", "A2").add("B", "B2").create();
  41. stats = gc.getStatistics();
  42. assertEquals(4, stats.numberOfLooseObjects);
  43. assertEquals(4, stats.numberOfPackedObjects);
  44. assertEquals(1, stats.numberOfPackFiles);
  45. gc.gc();
  46. stats = gc.getStatistics();
  47. assertEquals(0, stats.numberOfLooseObjects);
  48. assertEquals(8, stats.numberOfPackedObjects);
  49. assertEquals(2, stats.numberOfPackFiles);
  50. // check that no object is packed twice
  51. Iterator<Pack> packs = repo.getObjectDatabase().getPacks()
  52. .iterator();
  53. PackIndex ind1 = packs.next().getIndex();
  54. assertEquals(4, ind1.getObjectCount());
  55. PackIndex ind2 = packs.next().getIndex();
  56. assertEquals(4, ind2.getObjectCount());
  57. for (MutableEntry e: ind1)
  58. if (ind2.hasObject(e.toObjectId()))
  59. assertFalse(
  60. "the following object is in both packfiles: "
  61. + e.toObjectId(),
  62. ind2.hasObject(e.toObjectId()));
  63. }
  64. }