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.

RevWalkCarryFlagsTest.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2016, 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.revwalk;
  11. import static org.junit.Assert.assertNull;
  12. import static org.junit.Assert.assertTrue;
  13. import org.junit.Test;
  14. public class RevWalkCarryFlagsTest extends RevWalkTestCase {
  15. /**
  16. * Test that the uninteresting flag is carried over correctly. Every commit
  17. * should have the uninteresting flag resulting in a RevWalk returning no
  18. * commit.
  19. *
  20. * @throws Exception
  21. */
  22. @Test
  23. public void testRevWalkCarryUninteresting_fastClock() throws Exception {
  24. final RevCommit a = commit();
  25. final RevCommit b = commit(a);
  26. final RevCommit c = commit(a);
  27. final RevCommit d = commit(c);
  28. final RevCommit e = commit(b, d);
  29. markStart(d);
  30. markUninteresting(e);
  31. assertNull("Found an unexpected commit", rw.next());
  32. }
  33. /**
  34. * Similar to {@link #testRevWalkCarryUninteresting_fastClock()} but the
  35. * last merge commit is created so fast that he has the same creationdate as
  36. * the previous commit. This will cause the underlying {@link DateRevQueue}
  37. * is not able to sort the commits in a way matching the topology. A parent
  38. * (one of the commits which are merged) is handled before the child (the
  39. * merge commit). This makes carrying over flags more complicated
  40. *
  41. * @throws Exception
  42. */
  43. @Test
  44. public void testRevWalkCarryUninteresting_SlowClock() throws Exception {
  45. final RevCommit a = commit();
  46. final RevCommit b = commit(a);
  47. final RevCommit c = commit(a);
  48. final RevCommit d = commit(c);
  49. final RevCommit e = commit(0, b, d);
  50. markStart(d);
  51. markUninteresting(e);
  52. assertNull("Found an unexpected commit", rw.next());
  53. }
  54. /**
  55. * Similar to {@link #testRevWalkCarryUninteresting_SlowClock()} but the
  56. * last merge commit is created with a inconsistent creationdate. The merge
  57. * commit has a older creationdate then one of the commits he is merging.
  58. *
  59. * @throws Exception
  60. */
  61. @Test
  62. public void testRevWalkCarryUninteresting_WrongClock() throws Exception {
  63. final RevCommit a = commit();
  64. final RevCommit b = commit(a);
  65. final RevCommit c = commit(a);
  66. final RevCommit d = commit(c);
  67. final RevCommit e = commit(-1, b, d);
  68. markStart(d);
  69. markUninteresting(e);
  70. assertNull("Found an unexpected commit", rw.next());
  71. }
  72. /**
  73. * Same as {@link #testRevWalkCarryUninteresting_SlowClock()} but this time
  74. * we focus on the carrying over a custom flag.
  75. *
  76. * @throws Exception
  77. */
  78. @Test
  79. public void testRevWalkCarryCustom_SlowClock() throws Exception {
  80. final RevCommit a = commit();
  81. final RevCommit b = commit(a);
  82. final RevCommit c = commit(a);
  83. final RevCommit d = commit(c);
  84. final RevCommit e = commit(0, b, d);
  85. markStart(d);
  86. markStart(e);
  87. RevFlag customFlag = rw.newFlag("CUSTOM");
  88. e.flags |= customFlag.mask;
  89. rw.carry(customFlag);
  90. // the merge commit has the flag and it should be carried over -> every
  91. // commit should have this flag
  92. int count = 0;
  93. for (RevCommit cm : rw) {
  94. assertTrue(
  95. "Found a commit which doesn't have the custom flag: " + cm,
  96. cm.has(customFlag));
  97. count++;
  98. }
  99. assertTrue("Didn't walked over all commits", count == 5);
  100. }
  101. }