Guest User

Untitled

a guest
Feb 28th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. commit ba14acbc31a2d8e1e5ab8d040b2867620702851f
  2. Author: Tor Arne Vestbø <torarnv@gmail.com>
  3. Date: Mon Feb 2 20:07:44 2009 +0100
  4.  
  5. Fix AbstractTreeIterator path comparion betwen 'a' and 'a/b'
  6.  
  7. Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
  8.  
  9. diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/AbstractTreeIteratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/AbstractTreeIteratorTest.java
  10. new file mode 100644
  11. index 0000000..4c74094
  12. --- /dev/null
  13. +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/AbstractTreeIteratorTest.java
  14. @@ -0,0 +1,93 @@
  15. +/*
  16. + * Copyright (C) 2009, Tor Arne Vestbø <torarnv@gmail.com>
  17. + *
  18. + * All rights reserved.
  19. + *
  20. + * Redistribution and use in source and binary forms, with or
  21. + * without modification, are permitted provided that the following
  22. + * conditions are met:
  23. + *
  24. + * - Redistributions of source code must retain the above copyright
  25. + * notice, this list of conditions and the following disclaimer.
  26. + *
  27. + * - Redistributions in binary form must reproduce the above
  28. + * copyright notice, this list of conditions and the following
  29. + * disclaimer in the documentation and/or other materials provided
  30. + * with the distribution.
  31. + *
  32. + * - Neither the name of the Git Development Community nor the
  33. + * names of its contributors may be used to endorse or promote
  34. + * products derived from this software without specific prior
  35. + * written permission.
  36. + *
  37. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  38. + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  39. + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  40. + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  41. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43. + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  44. + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  45. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  46. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  47. + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  48. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  49. + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50. + */
  51. +
  52. +package org.spearce.jgit.treewalk;
  53. +
  54. +import java.io.IOException;
  55. +
  56. +import org.spearce.jgit.errors.IncorrectObjectTypeException;
  57. +import org.spearce.jgit.lib.FileMode;
  58. +import org.spearce.jgit.lib.Repository;
  59. +import org.spearce.jgit.lib.RepositoryTestCase;
  60. +
  61. +
  62. +public class AbstractTreeIteratorTest extends RepositoryTestCase {
  63. +
  64. +
  65. + public class FakeTreeIterator extends WorkingTreeIterator {
  66. + public FakeTreeIterator(String path, FileMode fileMode) {
  67. + super(path);
  68. + mode = fileMode.getBits();
  69. + pathLen -= 1; // Get rid of extra '/'
  70. + }
  71. +
  72. + @Override
  73. + public AbstractTreeIterator createSubtreeIterator(Repository repo)
  74. + throws IncorrectObjectTypeException, IOException {
  75. + return null;
  76. + }
  77. +
  78. + }
  79. +
  80. + public void testPathCompare() throws Exception {
  81. +
  82. + assertTrue(new FakeTreeIterator("a", FileMode.TREE).pathCompare(
  83. + new FakeTreeIterator("a/b", FileMode.REGULAR_FILE)) < 0);
  84. +
  85. + assertTrue(new FakeTreeIterator("a", FileMode.TREE).pathCompare(
  86. + new FakeTreeIterator("a//", FileMode.TREE)) == 0);
  87. +
  88. + assertTrue(new FakeTreeIterator("a/b", FileMode.REGULAR_FILE).pathCompare(
  89. + new FakeTreeIterator("a", FileMode.TREE)) > 0);
  90. +
  91. + assertTrue(new FakeTreeIterator("a//", FileMode.TREE).pathCompare(
  92. + new FakeTreeIterator("a", FileMode.TREE)) == 0);
  93. +
  94. + assertTrue(new FakeTreeIterator("a", FileMode.REGULAR_FILE).pathCompare(
  95. + new FakeTreeIterator("a", FileMode.TREE)) < 0);
  96. +
  97. + assertTrue(new FakeTreeIterator("a", FileMode.TREE).pathCompare(
  98. + new FakeTreeIterator("a", FileMode.REGULAR_FILE)) > 0);
  99. +
  100. + assertTrue(new FakeTreeIterator("a", FileMode.REGULAR_FILE).pathCompare(
  101. + new FakeTreeIterator("a", FileMode.REGULAR_FILE)) == 0);
  102. +
  103. + assertTrue(new FakeTreeIterator("a", FileMode.TREE).pathCompare(
  104. + new FakeTreeIterator("a", FileMode.TREE)) == 0);
  105. + }
  106. +
  107. +}
  108. diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
  109. index 2ff3b99..7dd3f38 100644
  110. --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
  111. +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
  112. @@ -289,9 +289,9 @@ int pathCompare(final AbstractTreeIterator p, final int pMode) {
  113. }
  114.  
  115. if (cPos < aLen)
  116. - return (a[cPos] & 0xff) - lastPathChar(pMode);
  117. + return ((a[cPos] & 0xff) - lastPathChar(pMode)) + (aLen - cPos - 1);
  118. if (cPos < bLen)
  119. - return lastPathChar(mode) - (b[cPos] & 0xff);
  120. + return (lastPathChar(mode) - (b[cPos] & 0xff)) - (bLen - cPos - 1);
  121. return lastPathChar(mode) - lastPathChar(pMode);
  122. }
Add Comment
Please, Sign In to add comment