{"thread":{"id":"13642","subject":"[JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","startedAt":"2008-05-23T20:34:09Z","lastAt":"2008-06-09T17:11:30Z","messageCount":41,"participants":["Florian Koeberle","Florian Köberle","Robin Rosenberg","Shawn O. Pearce"],"isPatch":true,"patchVersion":3,"patchTotal":23},"messages":[{"id":"77575","messageId":"1211574872-23676-1-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":null,"subject":"[JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:09Z","receivedAt":"2008-05-23T20:34:09Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"\nHi\n\nThis patch set contains a new fnmatch implementation.\n\nI dropped the idea of an regex based Matcher and implemented my own one.\n\nThe matcher matches character for character and can produce another matcher, which always starts at the position where it's parent was at creation time.\n\nIf you need to match:\nvery/long/path/a.txt\nvery/long/path/b.txt\nvery/long/path/c.txt\n\nThen you can match \"very/long/path\" in matcher p and then \"a.txt\", \"b.txt\" and \"c.txt\" in another matcher c.\n\nThat works for any input pattern which are currently supported:\n* characters\n* the wildcards ? and *\n* the wildcards ? and * with one character which should not appear like '/' \n* simple groups like [ab]\n* ranges in groups like [a-c]\n* inversed groups like [!ab]\n\nUnsupported are colon expressions like \":alpha:\". I didn't expect git-add to support it, but as I just noticed git does.\n \nAlso backslashes expressions like \"\\d\" for digits are evaluated as the characters \\ and d. Looks like git does the same for backslashes. In \"git-add\" patterns \\  characters get replaced by / characters, as windows users might want to type a\\b.txt instead of a/b.txt.\n\nAll implementations of FilePattern are now based on this matcher.\nI combined as suggested the TreeFilePattern and the ComplexFilePattern into one class named FilePathPattern. I furthermore renamed the GlobalFilePattern into FileNamePattern.\n\n\"git add\" patterns are now handled very similar to git, except that\na/\\*/b.txt is also a valid pattern. It would match any path that starts with \"a/\" and ends with \"/b.txt\" independent of the number of slahes between.\n\n .../org/spearce/jgit/lib/FileNameMatcherTest.java  |  311 +++++++++++++\n .../jgit/treewalk/LightFileTreeIteratorTest.java   |  114 +++++\n .../treewalk/rules/AddCommandIterationTest.java    |  321 +++++++++++++\n .../treewalk/rules/OverallIgnoreRulesTest.java     |  375 +++++++++++++++\n .../jgit/errors/InvalidPatternException.java       |   44 ++\n .../jgit/errors/NoGitRepositoryFoundException.java |   28 ++\n .../errors/PathNotInProjectDirectoryException.java |   25 +\n .../src/org/spearce/jgit/lib/Constants.java        |   30 +-\n .../src/org/spearce/jgit/lib/FileNameMatcher.java  |  376 +++++++++++++++\n .../src/org/spearce/jgit/lib/Repository.java       |  482 +++++++++++++-------\n .../src/org/spearce/jgit/lib/WorkTree.java         |   67 +++\n .../jgit/treewalk/LightFileTreeIterable.java       |   59 +++\n .../jgit/treewalk/LightFileTreeIterator.java       |  112 +++++\n .../jgit/treewalk/rules/AddRuleListFactory.java    |   75 +++\n .../jgit/treewalk/rules/AddRulesFactory.java       |   90 ++++\n .../jgit/treewalk/rules/FileNamePattern.java       |   58 +++\n .../jgit/treewalk/rules/FilePathPattern.java       |   76 +++\n .../spearce/jgit/treewalk/rules/FilePattern.java   |  107 +++++\n .../jgit/treewalk/rules/IgnoreRuleListFactory.java |   94 ++++\n .../src/org/spearce/jgit/treewalk/rules/Rule.java  |   61 +++\n .../treewalk/rules/RuleListToObjectConverter.java  |  130 ++++++\n .../src/org/spearce/jgit/treewalk/rules/Rules.java |   99 ++++\n .../jgit/treewalk/rules/RulesImplementation.java   |   73 +++\n\nBest regards,\nFlorian Koeberle\n"},{"id":"77584","messageId":"1211574872-23676-2-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 01/23] Added the class InvalidPatternException.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:10Z","receivedAt":"2008-05-23T20:34:10Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/errors/InvalidPatternException.java       |   44 ++++++++++++++++++++\n 1 files changed, 44 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java\nnew file mode 100644\nindex 0000000..d09f0c9\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java\n@@ -0,0 +1,44 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.errors;\n+\n+/**\n+ * Thrown when a pattern passed in an argument was wrong.\n+ * \n+ */\n+public class InvalidPatternException extends Exception {\n+\tprivate final String pattern;\n+\n+\t/**\n+\t * @param message\n+\t *            explains what was wrong with the pattern.\n+\t * @param pattern\n+\t *            the invalid pattern.\n+\t */\n+\tpublic InvalidPatternException(String message, String pattern) {\n+\t\tsuper(message);\n+\t\tthis.pattern = pattern;\n+\t}\n+\n+\t/**\n+\t * @return the invalid pattern.\n+\t */\n+\tpublic String getPattern() {\n+\t\treturn pattern;\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77580","messageId":"1211574872-23676-3-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 02/23] Added the class FileNameMatcher and a test class for it.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:11Z","receivedAt":"2008-05-23T20:34:11Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../org/spearce/jgit/lib/FileNameMatcherTest.java  |  311 ++++++++++++++++\n .../src/org/spearce/jgit/lib/FileNameMatcher.java  |  376 ++++++++++++++++++++\n 2 files changed, 687 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/FileNameMatcherTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/FileNameMatcher.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/FileNameMatcherTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/FileNameMatcherTest.java\nnew file mode 100644\nindex 0000000..fb0d8b2\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/FileNameMatcherTest.java\n@@ -0,0 +1,311 @@\n+package org.spearce.jgit.lib;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+\n+import junit.framework.TestCase;\n+\n+public class FileNameMatcherTest extends TestCase {\n+\n+\tprivate void assertMatch(final String pattern, final String input,\n+\t\t\tfinal boolean matchExpected,\n+\t\t\tfinal boolean extendResultInNoMatchExpected)\n+\t\t\tthrows InvalidPatternException {\n+\t\tfinal FileNameMatcher matcher = new FileNameMatcher(pattern, null);\n+\t\tmatcher.extendStringToMatch(input);\n+\t\tassertEquals(matchExpected, matcher.isMatch());\n+\t\tassertEquals(extendResultInNoMatchExpected, matcher\n+\t\t\t\t.willExtendResultInNoMatch());\n+\t}\n+\n+\tprivate void assertFileNameMatch(final String pattern, final String input,\n+\t\t\tfinal char excludedCharacter, final boolean matchExpected,\n+\t\t\tfinal boolean extendResultInNoMatchExpected)\n+\t\t\tthrows InvalidPatternException {\n+\t\tfinal FileNameMatcher matcher = new FileNameMatcher(pattern,\n+\t\t\t\tnew Character(excludedCharacter));\n+\t\tmatcher.extendStringToMatch(input);\n+\t\tassertEquals(matchExpected, matcher.isMatch());\n+\t\tassertEquals(extendResultInNoMatchExpected, matcher\n+\t\t\t\t.willExtendResultInNoMatch());\n+\t}\n+\n+\tpublic void testVerySimplePatternCase0() throws Exception {\n+\t\tassertMatch(\"\", \"\", true, true);\n+\t}\n+\n+\tpublic void testVerySimplePatternCase1() throws Exception {\n+\t\tassertMatch(\"ab\", \"a\", false, false);\n+\t}\n+\n+\tpublic void testVerySimplePatternCase2() throws Exception {\n+\t\tassertMatch(\"ab\", \"ab\", true, true);\n+\t}\n+\n+\tpublic void testVerySimplePatternCase3() throws Exception {\n+\t\tassertMatch(\"ab\", \"ac\", false, true);\n+\t}\n+\n+\tpublic void testVerySimplePatternCase4() throws Exception {\n+\t\tassertMatch(\"ab\", \"abc\", false, true);\n+\t}\n+\n+\tpublic void testVerySimpleWirdcardCase0() throws Exception {\n+\t\tassertMatch(\"?\", \"a\", true, true);\n+\t}\n+\n+\tpublic void testVerySimpleWildCardCase1() throws Exception {\n+\t\tassertMatch(\"??\", \"a\", false, false);\n+\t}\n+\n+\tpublic void testVerySimpleWildCardCase2() throws Exception {\n+\t\tassertMatch(\"??\", \"ab\", true, true);\n+\t}\n+\n+\tpublic void testVerySimpleWildCardCase3() throws Exception {\n+\t\tassertMatch(\"??\", \"abc\", false, true);\n+\t}\n+\n+\tpublic void testVerySimpleStarCase0() throws Exception {\n+\t\tassertMatch(\"*\", \"\", true, false);\n+\t}\n+\n+\tpublic void testVerySimpleStarCase1() throws Exception {\n+\t\tassertMatch(\"*\", \"a\", true, false);\n+\t}\n+\n+\tpublic void testVerySimpleStarCase2() throws Exception {\n+\t\tassertMatch(\"*\", \"ab\", true, false);\n+\t}\n+\n+\tpublic void testSimpleStarCase0() throws Exception {\n+\t\tassertMatch(\"a*b\", \"a\", false, false);\n+\t}\n+\n+\tpublic void testSimpleStarCase1() throws Exception {\n+\t\tassertMatch(\"a*c\", \"ac\", true, false);\n+\t}\n+\n+\tpublic void testSimpleStarCase2() throws Exception {\n+\t\tassertMatch(\"a*c\", \"ab\", false, false);\n+\t}\n+\n+\tpublic void testSimpleStarCase3() throws Exception {\n+\t\tassertMatch(\"a*c\", \"abc\", true, false);\n+\t}\n+\n+\tpublic void testManySolutionsCase0() throws Exception {\n+\t\tassertMatch(\"a*a*a\", \"aaa\", true, false);\n+\t}\n+\n+\tpublic void testManySolutionsCase1() throws Exception {\n+\t\tassertMatch(\"a*a*a\", \"aaaa\", true, false);\n+\t}\n+\n+\tpublic void testManySolutionsCase2() throws Exception {\n+\t\tassertMatch(\"a*a*a\", \"ababa\", true, false);\n+\t}\n+\n+\tpublic void testManySolutionsCase3() throws Exception {\n+\t\tassertMatch(\"a*a*a\", \"aaaaaaaa\", true, false);\n+\t}\n+\n+\tpublic void testManySolutionsCase4() throws Exception {\n+\t\tassertMatch(\"a*a*a\", \"aaaaaaab\", false, false);\n+\t}\n+\n+\tpublic void testVerySimpleGroupCase0() throws Exception {\n+\t\tassertMatch(\"[ab]\", \"a\", true, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupCase1() throws Exception {\n+\t\tassertMatch(\"[ab]\", \"b\", true, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupCase2() throws Exception {\n+\t\tassertMatch(\"[ab]\", \"ab\", false, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupRangeCase0() throws Exception {\n+\t\tassertMatch(\"[b-d]\", \"a\", false, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupRangeCase1() throws Exception {\n+\t\tassertMatch(\"[b-d]\", \"b\", true, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupRangeCase2() throws Exception {\n+\t\tassertMatch(\"[b-d]\", \"c\", true, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupRangeCase3() throws Exception {\n+\t\tassertMatch(\"[b-d]\", \"d\", true, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupRangeCase4() throws Exception {\n+\t\tassertMatch(\"[b-d]\", \"e\", false, true);\n+\t}\n+\n+\tpublic void testVerySimpleGroupRangeCase5() throws Exception {\n+\t\tassertMatch(\"[b-d]\", \"-\", false, true);\n+\t}\n+\n+\tpublic void testTwoGroupsCase0() throws Exception {\n+\t\tassertMatch(\"[b-d][ab]\", \"bb\", true, true);\n+\t}\n+\n+\tpublic void testTwoGroupsCase1() throws Exception {\n+\t\tassertMatch(\"[b-d][ab]\", \"ca\", true, true);\n+\t}\n+\n+\tpublic void testTwoGroupsCase2() throws Exception {\n+\t\tassertMatch(\"[b-d][ab]\", \"fa\", false, true);\n+\t}\n+\n+\tpublic void testTwoGroupsCase3() throws Exception {\n+\t\tassertMatch(\"[b-d][ab]\", \"bc\", false, true);\n+\t}\n+\n+\tpublic void testTwoRangesInOneGroupCase0() throws Exception {\n+\t\tassertMatch(\"[b-ce-e]\", \"a\", false, true);\n+\t}\n+\n+\tpublic void testTwoRangesInOneGroupCase1() throws Exception {\n+\t\tassertMatch(\"[b-ce-e]\", \"b\", true, true);\n+\t}\n+\n+\tpublic void testTwoRangesInOneGroupCase2() throws Exception {\n+\t\tassertMatch(\"[b-ce-e]\", \"c\", true, true);\n+\t}\n+\n+\tpublic void testTwoRangesInOneGroupCase3() throws Exception {\n+\t\tassertMatch(\"[b-ce-e]\", \"d\", false, true);\n+\t}\n+\n+\tpublic void testTwoRangesInOneGroupCase4() throws Exception {\n+\t\tassertMatch(\"[b-ce-e]\", \"e\", true, true);\n+\t}\n+\n+\tpublic void testTwoRangesInOneGroupCase5() throws Exception {\n+\t\tassertMatch(\"[b-ce-e]\", \"f\", false, true);\n+\t}\n+\n+\tpublic void testIncompleteRangesInOneGroupCase0() throws Exception {\n+\t\tassertMatch(\"a[b-]\", \"ab\", true, true);\n+\t}\n+\n+\tpublic void testIncompleteRangesInOneGroupCase1() throws Exception {\n+\t\tassertMatch(\"a[b-]\", \"ac\", false, true);\n+\t}\n+\n+\tpublic void testIncompleteRangesInOneGroupCase2() throws Exception {\n+\t\tassertMatch(\"a[b-]\", \"a-\", true, true);\n+\t}\n+\n+\tpublic void testCombinedRangesInOneGroupCase0() throws Exception {\n+\t\tassertMatch(\"[a-c-e]\", \"b\", true, true);\n+\t}\n+\n+\t/**\n+\t * The c belongs to the range a-c. \"-e\" is no valid range so d should not\n+\t * match.\n+\t * \n+\t * @throws Exception\n+\t *             for some reasons\n+\t */\n+\tpublic void testCombinedRangesInOneGroupCase1() throws Exception {\n+\t\tassertMatch(\"[a-c-e]\", \"d\", false, true);\n+\t}\n+\n+\tpublic void testCombinedRangesInOneGroupCase2() throws Exception {\n+\t\tassertMatch(\"[a-c-e]\", \"e\", true, true);\n+\t}\n+\n+\tpublic void testInversedGroupCase0() throws Exception {\n+\t\tassertMatch(\"[!b-c]\", \"a\", true, true);\n+\t}\n+\n+\tpublic void testInversedGroupCase1() throws Exception {\n+\t\tassertMatch(\"[!b-c]\", \"b\", false, true);\n+\t}\n+\n+\tpublic void testInversedGroupCase2() throws Exception {\n+\t\tassertMatch(\"[!b-c]\", \"c\", false, true);\n+\t}\n+\n+\tpublic void testInversedGroupCase3() throws Exception {\n+\t\tassertMatch(\"[!b-c]\", \"d\", true, true);\n+\t}\n+\n+\tpublic void testFilePathSimpleCase() throws Exception {\n+\t\tassertFileNameMatch(\"a/b\", \"a/b\", '/', true, true);\n+\t}\n+\n+\tpublic void testFilePathCase0() throws Exception {\n+\t\tassertFileNameMatch(\"a*b\", \"a/b\", '/', false, true);\n+\t}\n+\n+\tpublic void testFilePathCase1() throws Exception {\n+\t\tassertFileNameMatch(\"a?b\", \"a/b\", '/', false, true);\n+\t}\n+\n+\tpublic void testFilePathCase2() throws Exception {\n+\t\tassertFileNameMatch(\"a*b\", \"a\\\\b\", '\\\\', false, true);\n+\t}\n+\n+\tpublic void testFilePathCase3() throws Exception {\n+\t\tassertFileNameMatch(\"a?b\", \"a\\\\b\", '\\\\', false, true);\n+\t}\n+\n+\tpublic void testReset() throws Exception {\n+\t\tfinal String pattern = \"helloworld\";\n+\t\tfinal FileNameMatcher matcher = new FileNameMatcher(pattern, null);\n+\t\tmatcher.extendStringToMatch(\"helloworld\");\n+\t\tassertEquals(true, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t\tmatcher.resetStringToMatch();\n+\t\tmatcher.extendStringToMatch(\"hello\");\n+\t\tassertEquals(false, matcher.isMatch());\n+\t\tassertEquals(false, matcher.willExtendResultInNoMatch());\n+\t\tmatcher.extendStringToMatch(\"world\");\n+\t\tassertEquals(true, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t\tmatcher.extendStringToMatch(\"to much\");\n+\t\tassertEquals(false, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t\tmatcher.resetStringToMatch();\n+\t\tmatcher.extendStringToMatch(\"helloworld\");\n+\t\tassertEquals(true, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t}\n+\n+\tpublic void testCreateMatcherForSuffix() throws Exception {\n+\t\tfinal String pattern = \"helloworld\";\n+\t\tfinal FileNameMatcher matcher = new FileNameMatcher(pattern, null);\n+\t\tmatcher.extendStringToMatch(\"hello\");\n+\t\tfinal FileNameMatcher childMatcher = matcher.createMatcherForSuffix();\n+\t\tassertEquals(false, matcher.isMatch());\n+\t\tassertEquals(false, matcher.willExtendResultInNoMatch());\n+\t\tassertEquals(false, childMatcher.isMatch());\n+\t\tassertEquals(false, childMatcher.willExtendResultInNoMatch());\n+\t\tmatcher.extendStringToMatch(\"world\");\n+\t\tassertEquals(true, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t\tassertEquals(false, childMatcher.isMatch());\n+\t\tassertEquals(false, childMatcher.willExtendResultInNoMatch());\n+\t\tchildMatcher.extendStringToMatch(\"world\");\n+\t\tassertEquals(true, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t\tassertEquals(true, childMatcher.isMatch());\n+\t\tassertEquals(true, childMatcher.willExtendResultInNoMatch());\n+\t\tchildMatcher.resetStringToMatch();\n+\t\tassertEquals(true, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t\tassertEquals(false, childMatcher.isMatch());\n+\t\tassertEquals(false, childMatcher.willExtendResultInNoMatch());\n+\t\tchildMatcher.extendStringToMatch(\"world\");\n+\t\tassertEquals(true, matcher.isMatch());\n+\t\tassertEquals(true, matcher.willExtendResultInNoMatch());\n+\t\tassertEquals(true, childMatcher.isMatch());\n+\t\tassertEquals(true, childMatcher.willExtendResultInNoMatch());\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/FileNameMatcher.java b/org.spearce.jgit/src/org/spearce/jgit/lib/FileNameMatcher.java\nnew file mode 100644\nindex 0000000..4177e27\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/FileNameMatcher.java\n@@ -0,0 +1,376 @@\n+package org.spearce.jgit.lib;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.List;\n+import java.util.ListIterator;\n+import java.util.regex.Matcher;\n+import java.util.regex.Pattern;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+\n+/**\n+ * This class can be used to match filenames against fnmatch like patterns. It\n+ * is not thread save.\n+ */\n+public class FileNameMatcher {\n+\tprivate static final List<Head> EMPTY_HEAD_LIST = Collections.emptyList();\n+\n+\tprivate List<Head> headsStartValue;\n+\n+\tprivate List<Head> heads;\n+\n+\t/**\n+\t * {{@link #extendStringToMatchByOneCharacter(char)} needs a list for the\n+\t * new heads, allocating a new array would be bad for the performance, as\n+\t * the method gets called very often.\n+\t * \n+\t */\n+\tprivate List<Head> listForLocalUseage;\n+\n+\t/**\n+\t * \n+\t * @param headsStartValue\n+\t *            must be a list which will never be modified.\n+\t */\n+\tprivate FileNameMatcher(final List<Head> headsStartValue) {\n+\t\tthis.headsStartValue = headsStartValue;\n+\t\tthis.heads = new ArrayList<Head>(headsStartValue.size());\n+\t\tthis.heads.addAll(this.headsStartValue);\n+\t\tthis.listForLocalUseage = new ArrayList<Head>(headsStartValue.size());\n+\t}\n+\n+\t/**\n+\t * @param patternString\n+\t *            must contain a pattern which fnmatch would accept.\n+\t * @param invalidWildgetCharacter\n+\t *            if this parameter isn't null then this character will not\n+\t *            match at wildcards(* and ? are wildcards).\n+\t * @throws InvalidPatternException\n+\t *             if the patternString contains a invalid fnmatch pattern.\n+\t */\n+\tpublic FileNameMatcher(final String patternString,\n+\t\t\tfinal Character invalidWildgetCharacter)\n+\t\t\tthrows InvalidPatternException {\n+\t\tthis(createHeadsStartValues(patternString, invalidWildgetCharacter));\n+\t}\n+\n+\tprivate static List<Head> createHeadsStartValues(\n+\t\t\tfinal String patternString, final Character invalidWildgetCharacter)\n+\t\t\tthrows InvalidPatternException {\n+\t\tList<Head> nextHeadsSuggestion = new ArrayList<Head>(2);\n+\t\tnextHeadsSuggestion.add(LastHead.INSTANCE);\n+\n+\t\tfinal char previosChracter = '\\n';\n+\t\tint i = patternString.length() - 1;\n+\t\twhile (i >= 0) {\n+\t\t\tfinal char c = patternString.charAt(i);\n+\n+\t\t\tswitch (c) {\n+\t\t\tcase '*': {\n+\t\t\t\tif (previosChracter != '*') {\n+\t\t\t\t\tfinal AbstractHead head = createWildCardHead(invalidWildgetCharacter);\n+\t\t\t\t\tnextHeadsSuggestion.add(head);\n+\t\t\t\t\thead.setNewHeads(nextHeadsSuggestion);\n+\t\t\t\t}\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tcase '?': {\n+\t\t\t\tfinal AbstractHead head = createWildCardHead(invalidWildgetCharacter);\n+\t\t\t\thead.setNewHeads(nextHeadsSuggestion);\n+\t\t\t\tnextHeadsSuggestion = new ArrayList<Head>(2);\n+\t\t\t\tnextHeadsSuggestion.add(head);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tcase ']': {\n+\t\t\t\tfinal String groupPattern = extractGroupPatternWithoutBrackets(\n+\t\t\t\t\t\tpatternString, i);\n+\t\t\t\ti -= groupPattern.length() + 1;\n+\t\t\t\tfinal AbstractHead head = new GroupHead(groupPattern);\n+\t\t\t\thead.setNewHeads(nextHeadsSuggestion);\n+\t\t\t\tnextHeadsSuggestion = new ArrayList<Head>(2);\n+\t\t\t\tnextHeadsSuggestion.add(head);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tcase '[': {\n+\t\t\t\tfinal String message = String\n+\t\t\t\t\t\t.format(\"There is no closing ] for the character [ at \"\n+\t\t\t\t\t\t\t\t+ i);\n+\t\t\t\tthrow new InvalidPatternException(message, patternString);\n+\t\t\t}\n+\t\t\tdefault: {\n+\t\t\t\tfinal CharacterHead head = new CharacterHead(c);\n+\t\t\t\thead.setNewHeads(nextHeadsSuggestion);\n+\t\t\t\tnextHeadsSuggestion = new ArrayList<Head>(2);\n+\t\t\t\tnextHeadsSuggestion.add(head);\n+\t\t\t}\n+\t\t\t}\n+\t\t\ti--;\n+\n+\t\t}\n+\t\treturn nextHeadsSuggestion;\n+\t}\n+\n+\tprivate static String extractGroupPatternWithoutBrackets(\n+\t\t\tfinal String patternString, int closingBracketIndex)\n+\t\t\tthrows InvalidPatternException {\n+\t\tint start = closingBracketIndex - 1;\n+\t\twhile (start >= 0) {\n+\t\t\tfinal char possibleStartCharacter = patternString.charAt(start);\n+\t\t\tif (possibleStartCharacter == '[') {\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tif (possibleStartCharacter == ']') {\n+\t\t\t\tfinal String message = String\n+\t\t\t\t\t\t.format(\n+\t\t\t\t\t\t\t\t\"Found two ] characters at %s and %s without a [ character between.\",\n+\t\t\t\t\t\t\t\tString.valueOf(start), String\n+\t\t\t\t\t\t\t\t\t\t.valueOf(closingBracketIndex));\n+\t\t\t\tthrow new InvalidPatternException(message, patternString);\n+\t\t\t}\n+\t\t\tstart--;\n+\t\t}\n+\t\tif (start < 0) {\n+\t\t\tfinal String message = String\n+\t\t\t\t\t.format(\n+\t\t\t\t\t\t\t\"Found a ] character at %s but no [ character infront of it.\",\n+\t\t\t\t\t\t\tString.valueOf(closingBracketIndex));\n+\t\t\tthrow new InvalidPatternException(message, patternString);\n+\t\t}\n+\t\tfinal String groupPatternWithOutBrackets = patternString.substring(\n+\t\t\t\tstart + 1, closingBracketIndex);\n+\t\treturn groupPatternWithOutBrackets;\n+\t}\n+\n+\tprivate static AbstractHead createWildCardHead(\n+\t\t\tfinal Character invalidWildgetCharacter) {\n+\t\tif (invalidWildgetCharacter != null)\n+\t\t\treturn new RestrictedWildCardHead(invalidWildgetCharacter\n+\t\t\t\t\t.charValue());\n+\t\telse\n+\t\t\treturn new WildCardHead();\n+\t}\n+\n+\tprivate void extendStringToMatchByOneCharacter(final char c) {\n+\t\tfinal List<Head> newHeads = listForLocalUseage;\n+\t\tnewHeads.clear();\n+\t\tList<Head> lastAddedHeads = null;\n+\t\tfor (int i = 0; i < heads.size(); i++) {\n+\t\t\tfinal Head head = heads.get(i);\n+\t\t\tfinal List<Head> headsToAdd = head.getNextHeads(c);\n+\t\t\t// Why the next performance optimization isn't wrong:\n+\t\t\t// Some times two heads return the very same list.\n+\t\t\t// We save future effort if we don't add these heads again.\n+\t\t\t// This is the case with the heads \"a\" and \"*\" of \"a*b\" which\n+\t\t\t// both can return the list [\"*\",\"b\"]\n+\t\t\tif (headsToAdd != lastAddedHeads) {\n+\t\t\t\tnewHeads.addAll(headsToAdd);\n+\t\t\t\tlastAddedHeads = headsToAdd;\n+\t\t\t}\n+\t\t}\n+\t\tlistForLocalUseage = heads;\n+\t\theads = newHeads;\n+\t}\n+\n+\t/**\n+\t * \n+\t * @param stringToMatch\n+\t *            extends the string which is matched against the patterns of\n+\t *            this class.\n+\t */\n+\tpublic void extendStringToMatch(final String stringToMatch) {\n+\t\tfor (int i = 0; i < stringToMatch.length(); i++) {\n+\t\t\tfinal char c = stringToMatch.charAt(i);\n+\t\t\textendStringToMatchByOneCharacter(c);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Resets this matcher to it's state right after construction.\n+\t */\n+\tpublic void resetStringToMatch() {\n+\t\theads.clear();\n+\t\theads.addAll(headsStartValue);\n+\t}\n+\n+\t/**\n+\t * \n+\t * @return a {@link FileNameMatcher} instance which uses the same pattern\n+\t *         like this matcher, but has the current state of this matcher as\n+\t *         reset and start point.\n+\t */\n+\tpublic FileNameMatcher createMatcherForSuffix() {\n+\t\tfinal List<Head> copyOfHeads = new ArrayList<Head>(heads.size());\n+\t\tcopyOfHeads.addAll(heads);\n+\t\treturn new FileNameMatcher(copyOfHeads);\n+\t}\n+\n+\tprivate interface Head {\n+\t\t/**\n+\t\t * \n+\t\t * @param c\n+\t\t *            the character which decides which heads are returned.\n+\t\t * @return a list of heads based on the input.\n+\t\t */\n+\t\tpublic abstract List<Head> getNextHeads(char c);\n+\t}\n+\n+\tprivate static abstract class AbstractHead implements Head {\n+\t\tprivate List<Head> newHeads = null;\n+\n+\t\tprotected abstract boolean matches(char c);\n+\n+\t\t/**\n+\t\t * \n+\t\t * @param newHeads\n+\t\t *            a list of {@link Head}s which will not be modified.\n+\t\t */\n+\t\tpublic final void setNewHeads(List<Head> newHeads) {\n+\t\t\tif (this.newHeads != null)\n+\t\t\t\tthrow new IllegalStateException(\"Property is already non null\");\n+\t\t\tthis.newHeads = newHeads;\n+\t\t}\n+\n+\t\tpublic List<Head> getNextHeads(char c) {\n+\t\t\tif (matches(c))\n+\t\t\t\treturn newHeads;\n+\t\t\telse\n+\t\t\t\treturn EMPTY_HEAD_LIST;\n+\t\t}\n+\t}\n+\n+\tprivate static final class LastHead implements Head {\n+\t\tstatic final Head INSTANCE = new LastHead();\n+\n+\t\t/**\n+\t\t * Don't call this constructor, use {@link #INSTANCE}\n+\t\t */\n+\t\tprivate LastHead() {\n+\t\t\t// defined because of javadoc and visibility modifier.\n+\t\t}\n+\n+\t\tpublic List<Head> getNextHeads(char c) {\n+\t\t\treturn EMPTY_HEAD_LIST;\n+\t\t}\n+\n+\t}\n+\n+\tprivate static final class CharacterHead extends AbstractHead {\n+\t\tprivate final char expectedCharacter;\n+\n+\t\tprotected CharacterHead(final char expectedCharacter) {\n+\t\t\tthis.expectedCharacter = expectedCharacter;\n+\t\t}\n+\n+\t\t@Override\n+\t\tprotected final boolean matches(final char c) {\n+\t\t\treturn c == expectedCharacter;\n+\t\t}\n+\n+\t}\n+\n+\tprivate static final class WildCardHead extends AbstractHead {\n+\t\t@Override\n+\t\tprotected final boolean matches(final char c) {\n+\t\t\treturn true;\n+\t\t}\n+\t}\n+\n+\tprivate static final class RestrictedWildCardHead extends AbstractHead {\n+\t\tprivate final char excludedCharacter;\n+\n+\t\tRestrictedWildCardHead(final char excludedCharacter) {\n+\t\t\tthis.excludedCharacter = excludedCharacter;\n+\t\t}\n+\n+\t\t@Override\n+\t\tprotected final boolean matches(final char c) {\n+\t\t\treturn c != excludedCharacter;\n+\t\t}\n+\t}\n+\n+\tprivate static final class GroupHead extends AbstractHead {\n+\t\tprivate final List<CharacterRange> ranges;\n+\n+\t\tprivate final boolean inverse;\n+\n+\t\tGroupHead(String pattern) {\n+\t\t\tthis.ranges = new ArrayList<CharacterRange>();\n+\t\t\tthis.inverse = pattern.startsWith(\"!\");\n+\t\t\tif (inverse) {\n+\t\t\t\tpattern = pattern.substring(1);\n+\t\t\t}\n+\t\t\tfinal Pattern regexPattern = Pattern.compile(\"[^-][-][^-]\");\n+\t\t\tfinal Matcher matcher = regexPattern.matcher(pattern);\n+\t\t\twhile (matcher.find()) {\n+\t\t\t\tfinal String rangeString = matcher.group(0);\n+\t\t\t\tfinal char start = rangeString.charAt(0);\n+\t\t\t\tfinal char end = rangeString.charAt(2);\n+\t\t\t\tranges.add(new CharacterRange(start, end));\n+\t\t\t\tpattern = matcher.replaceFirst(\"\");\n+\t\t\t\tmatcher.reset(pattern);\n+\t\t\t}\n+\t\t\t// pattern contains now no ranges\n+\t\t\tfor (int i = 0; i < pattern.length(); i++) {\n+\t\t\t\tfinal char c = pattern.charAt(i);\n+\t\t\t\tranges.add(new CharacterRange(c, c));\n+\t\t\t}\n+\t\t}\n+\n+\t\t@Override\n+\t\tprotected final boolean matches(final char c) {\n+\t\t\tfor (CharacterRange range : ranges) {\n+\t\t\t\tif (range.inRange(c)) {\n+\t\t\t\t\treturn !inverse;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\treturn inverse;\n+\t\t}\n+\n+\t\tprivate static final class CharacterRange {\n+\t\t\tprivate final char start;\n+\n+\t\t\tprivate final char end;\n+\n+\t\t\tCharacterRange(char start, char end) {\n+\t\t\t\tthis.start = start;\n+\t\t\t\tthis.end = end;\n+\t\t\t}\n+\n+\t\t\tboolean inRange(char c) {\n+\t\t\t\treturn start <= c && c <= end;\n+\t\t\t}\n+\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * \n+\t * @return true, if the string currently beeing matched does match.\n+\t */\n+\tpublic boolean isMatch() {\n+\t\tfinal ListIterator<Head> headIterator = heads\n+\t\t\t\t.listIterator(heads.size());\n+\t\twhile (headIterator.hasPrevious()) {\n+\t\t\tfinal Head head = headIterator.previous();\n+\t\t\tif (head == LastHead.INSTANCE) {\n+\t\t\t\treturn true;\n+\t\t\t}\n+\t\t}\n+\t\treturn false;\n+\t}\n+\n+\t/**\n+\t * \n+\t * @return true, if the string beeing matched will not match when the string\n+\t *         gets extended.\n+\t */\n+\tpublic boolean willExtendResultInNoMatch() {\n+\t\tfor (int i = 0; i < heads.size(); i++) {\n+\t\t\tif (heads.get(i) != LastHead.INSTANCE) {\n+\t\t\t\treturn false;\n+\t\t\t}\n+\t\t}\n+\t\treturn true;\n+\t}\n+}\n-- \n1.5.4.3\n"},{"id":"77582","messageId":"1211574872-23676-4-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 03/23] Added the interface FilePattern.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:12Z","receivedAt":"2008-05-23T20:34:12Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../spearce/jgit/treewalk/rules/FilePattern.java   |  107 ++++++++++++++++++++\n 1 files changed, 107 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePattern.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePattern.java\nnew file mode 100644\nindex 0000000..75262c8\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePattern.java\n@@ -0,0 +1,107 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+/**\n+ * A {@link FilePattern} can be used to check if files in a directory matches a\n+ * pattern. It provides with the {@link #getPatternForSubDirectory(String)}\n+ * method {@link FilePattern}s for sub directories.\n+ * \n+ * Implementations of this interface should be immutable.\n+ * \n+ */\n+interface FilePattern {\n+\t/**\n+\t * Contains the only instance of {@link FilePatternMatchAlways}.\n+\t */\n+\tpublic static final FilePattern MATCH_ALWAYS = new FilePatternMatchAlways();\n+\n+\t/**\n+\t * Contains the only instance of {@link FilePatternMatchNever}.\n+\t */\n+\tpublic static final FilePattern MATCH_NEVER = new FilePatternMatchNever();\n+\n+\t/**\n+\t * @param fileName\n+\t *            the name of the file or directory\n+\t * @param fileIsDirectory\n+\t *            determines if the file is a directory.\n+\t * @return true if the pattern matches.\n+\t */\n+\tboolean match(String fileName, boolean fileIsDirectory);\n+\n+\t/**\n+\t * \n+\t * @param directoryName\n+\t *            the name of a subdirectory.\n+\t * @return a pattern which can be used to match files in sub directories. A\n+\t *         user may check if the returned value is {@link #MATCH_NEVER} in\n+\t *         order to do some performance optimizations.\n+\t * \n+\t */\n+\tFilePattern getPatternForSubDirectory(String directoryName);\n+\n+\t/**\n+\t * @return true if {@link #getPatternForSubDirectory(String)} returns true\n+\t *         for every value.\n+\t */\n+\tboolean isSameForSubDirectories();\n+\n+\t/**\n+\t * This implementation does always match.\n+\t */\n+\tpublic static final class FilePatternMatchAlways implements FilePattern {\n+\n+\t\tprivate FilePatternMatchAlways() {\n+\t\t\t// declared to make the constructor private\n+\t\t}\n+\n+\t\tpublic FilePattern getPatternForSubDirectory(String directoryName) {\n+\t\t\treturn MATCH_ALWAYS;\n+\t\t}\n+\n+\t\tpublic boolean match(String fileName, boolean fileIsDirectory) {\n+\t\t\treturn true;\n+\t\t}\n+\n+\t\tpublic boolean isSameForSubDirectories() {\n+\t\t\treturn true;\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * This implementation does never match.\n+\t */\n+\tpublic static final class FilePatternMatchNever implements FilePattern {\n+\t\tprivate FilePatternMatchNever() {\n+\t\t\t// declared to make the constructor private\n+\t\t}\n+\n+\t\tpublic FilePattern getPatternForSubDirectory(String directoryName) {\n+\t\t\treturn MATCH_NEVER;\n+\t\t}\n+\n+\t\tpublic boolean match(String fileName, boolean fileIsDirectory) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tpublic boolean isSameForSubDirectories() {\n+\t\t\treturn true;\n+\t\t}\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77578","messageId":"1211574872-23676-5-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 04/23] Added the class Rule.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:13Z","receivedAt":"2008-05-23T20:34:13Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../src/org/spearce/jgit/treewalk/rules/Rule.java  |   61 ++++++++++++++++++++\n 1 files changed, 61 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rule.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rule.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rule.java\nnew file mode 100644\nindex 0000000..1cc74f5\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rule.java\n@@ -0,0 +1,61 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+/**\n+ * A Rule defines what to do with a files which match a specified\n+ * {@link FilePattern}.\n+ */\n+public class Rule {\n+\tprivate boolean ignoreAtMatch;\n+\n+\tprivate FilePattern pattern;\n+\n+\t/**\n+\t * \n+\t * @param ignoreAtMatch\n+\t *            defines if the rules ignores or accepts at a match.\n+\t * @param pattern\n+\t *            the pattern used to test if a file matches.\n+\t */\n+\tRule(boolean ignoreAtMatch, FilePattern pattern) {\n+\t\tthis.ignoreAtMatch = ignoreAtMatch;\n+\t\tthis.pattern = pattern;\n+\t}\n+\n+\tFilePattern getPattern() {\n+\t\treturn pattern;\n+\t}\n+\n+\tboolean isIgnoreAtMatch() {\n+\t\treturn ignoreAtMatch;\n+\t}\n+\n+\tRule getRuleForSubDirectory(String directoryName) {\n+\t\tfinal FilePattern subPattern = pattern\n+\t\t\t\t.getPatternForSubDirectory(directoryName);\n+\t\tif (subPattern == pattern) {\n+\t\t\treturn this;\n+\t\t}\n+\t\treturn new Rule(ignoreAtMatch, subPattern);\n+\t}\n+\n+\tboolean isSameForSubDirectories() {\n+\t\treturn pattern.isSameForSubDirectories();\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77579","messageId":"1211574872-23676-6-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 05/23] Added the iterface Rules.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:14Z","receivedAt":"2008-05-23T20:34:14Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../src/org/spearce/jgit/treewalk/rules/Rules.java |   99 ++++++++++++++++++++\n 1 files changed, 99 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rules.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rules.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rules.java\nnew file mode 100644\nindex 0000000..627d974\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rules.java\n@@ -0,0 +1,99 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+/**\n+ * A {@link Rules} instances defines ignore or do not ignore rules for files in\n+ * a directory. It can't directly be used to match files in sub directories, but\n+ * provides a method {@link #getRulesForSubDirectory}.\n+ * \n+ */\n+public interface Rules {\n+\n+\t/**\n+\t * Provides the instance of {@link IgnoreAllRules}.\n+\t */\n+\tpublic static final Rules IGNORE_ALL = new IgnoreAllRules();\n+\n+\t/**\n+\t * Provides the instance of {@link IgnoreNothingRules}.\n+\t */\n+\tpublic static final Rules IGNORE_NOTHING = new IgnoreNothingRules();\n+\n+\t/**\n+\t * @param fileName\n+\t *            the name of the file or directory.\n+\t * @param fileIsDirectory\n+\t *            should be true if the file is a directory.\n+\t * @return true if the file or directory should be ignored.\n+\t */\n+\tpublic abstract boolean toIgnore(String fileName, boolean fileIsDirectory);\n+\n+\t/**\n+\t * @param directoryName\n+\t *            the sub directory for which you want an {@link Rules}\n+\t *            instance.\n+\t * @return an {@link Rules} instance, which can be used to check files in\n+\t *         the specified sub directory.\n+\t */\n+\tpublic abstract Rules getRulesForSubDirectory(String directoryName);\n+\n+\t/**\n+\t * This implementation ignores everything.\n+\t */\n+\tpublic static final class IgnoreAllRules implements Rules {\n+\t\tprivate IgnoreAllRules() {\n+\t\t\t// declared to make the constructor private\n+\t\t}\n+\n+\t\tpublic Rules getRulesForSubDirectory(String directoryName) {\n+\t\t\treturn this;\n+\t\t}\n+\n+\t\tpublic boolean toIgnore(String fileName, boolean fileIsDirectory) {\n+\t\t\treturn true;\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic String toString() {\n+\t\t\treturn \"ignore all rules\";\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * This implementation ignores nothing.\n+\t */\n+\tpublic static final class IgnoreNothingRules implements Rules {\n+\t\tprivate IgnoreNothingRules() {\n+\t\t\t// declared to make the constructor private\n+\t\t}\n+\n+\t\tpublic Rules getRulesForSubDirectory(String directoryName) {\n+\t\t\treturn this;\n+\t\t}\n+\n+\t\tpublic boolean toIgnore(String fileName, boolean fileIsDirectory) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic String toString() {\n+\t\t\treturn \"ignore nothing rules\";\n+\t\t}\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77591","messageId":"1211574872-23676-7-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 06/23] Added the class FileNamePattern.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:15Z","receivedAt":"2008-05-23T20:34:15Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/rules/FileNamePattern.java       |   58 ++++++++++++++++++++\n 1 files changed, 58 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java\nnew file mode 100644\nindex 0000000..f14fdef\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java\n@@ -0,0 +1,58 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.lib.FileNameMatcher;\n+\n+/**\n+ * A {@link FileNamePattern} defines a pattern for all files in a tree. A\n+ * typical example would be \"*.txt\", which would match at any file or subtree\n+ * which ends with \".txt\" like \"a/b/c.txt\" and \"a.txt/a.c\".\n+ * \n+ */\n+class FileNamePattern implements FilePattern {\n+\tprivate final FileNameMatcher fileNameMatcher;\n+\n+\tprivate final boolean matchDirectoriesOnly;\n+\n+\tFileNamePattern(String fnMatchPatternString, boolean matchDirectoriesOnly)\n+\t\t\tthrows InvalidPatternException {\n+\t\tthis.fileNameMatcher = new FileNameMatcher(fnMatchPatternString, null);\n+\t\tthis.matchDirectoriesOnly = matchDirectoriesOnly;\n+\t}\n+\n+\tpublic FilePattern getPatternForSubDirectory(String directoryName) {\n+\t\tif (match(directoryName, true)) {\n+\t\t\treturn MATCH_ALWAYS;\n+\t\t}\n+\t\treturn this;\n+\t}\n+\n+\tpublic boolean match(String fileName, boolean fileIsDirectory) {\n+\t\tif (matchDirectoriesOnly && !fileIsDirectory) {\n+\t\t\treturn false;\n+\t\t}\n+\t\tfileNameMatcher.resetStringToMatch();\n+\t\tfileNameMatcher.extendStringToMatch(fileName);\n+\t\treturn fileNameMatcher.isMatch();\n+\t}\n+\n+\tpublic boolean isSameForSubDirectories() {\n+\t\treturn false;\n+\t}\n+}\n-- \n1.5.4.3\n"},{"id":"77581","messageId":"1211574872-23676-8-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 07/23] Added the class FilePathPattern.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:16Z","receivedAt":"2008-05-23T20:34:16Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/rules/FilePathPattern.java       |   76 ++++++++++++++++++++\n 1 files changed, 76 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java\nnew file mode 100644\nindex 0000000..4a5f021\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java\n@@ -0,0 +1,76 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.lib.FileNameMatcher;\n+\n+/**\n+ * A {@link FilePathPattern} represents a pattern for a file path.\n+ * \n+ */\n+class FilePathPattern implements FilePattern {\n+\tprivate final FileNameMatcher matcher;\n+\n+\tprivate final boolean matchDirectoriesOnly;\n+\n+\tprivate FilePathPattern(final FileNameMatcher matcher,\n+\t\t\tfinal boolean matchDirectoriesOnly) {\n+\t\tthis.matcher = matcher;\n+\t\tthis.matchDirectoriesOnly = matchDirectoriesOnly;\n+\t}\n+\n+\tFilePathPattern(final String pattern, final boolean allowSlashInWildCard,\n+\t\t\tfinal boolean matchDirectoriesOnly) throws InvalidPatternException {\n+\n+\t\tif (allowSlashInWildCard)\n+\t\t\tthis.matcher = new FileNameMatcher(pattern, null);\n+\t\telse\n+\t\t\tthis.matcher = new FileNameMatcher(pattern, new Character('/'));\n+\t\tthis.matchDirectoriesOnly = matchDirectoriesOnly;\n+\t}\n+\n+\tpublic FilePattern getPatternForSubDirectory(String directoryName) {\n+\t\tmatcher.resetStringToMatch();\n+\t\tmatcher.extendStringToMatch(directoryName);\n+\n+\t\tif (matcher.isMatch())\n+\t\t\treturn FilePattern.MATCH_ALWAYS;\n+\n+\t\tmatcher.extendStringToMatch(\"/\");\n+\n+\t\tif (matcher.willExtendResultInNoMatch())\n+\t\t\treturn FilePattern.MATCH_NEVER;\n+\n+\t\tfinal FileNameMatcher childMatcher = matcher.createMatcherForSuffix();\n+\t\treturn new FilePathPattern(childMatcher, matchDirectoriesOnly);\n+\t}\n+\n+\tpublic boolean match(String fileName, boolean fileIsDirectory) {\n+\t\tif (!fileIsDirectory && matchDirectoriesOnly) {\n+\t\t\treturn false;\n+\t\t}\n+\t\tmatcher.resetStringToMatch();\n+\t\tmatcher.extendStringToMatch(fileName);\n+\t\treturn matcher.isMatch();\n+\t}\n+\n+\tpublic boolean isSameForSubDirectories() {\n+\t\treturn false;\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77590","messageId":"1211574872-23676-9-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 08/23] Added the class IgnoreRuleListFactory.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:17Z","receivedAt":"2008-05-23T20:34:17Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/rules/IgnoreRuleListFactory.java |   94 ++++++++++++++++++++\n 1 files changed, 94 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/IgnoreRuleListFactory.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/IgnoreRuleListFactory.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/IgnoreRuleListFactory.java\nnew file mode 100644\nindex 0000000..98f1169\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/IgnoreRuleListFactory.java\n@@ -0,0 +1,94 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.io.File;\n+import java.io.FileNotFoundException;\n+import java.util.ArrayList;\n+import java.util.LinkedList;\n+import java.util.List;\n+import java.util.Scanner;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+\n+/**\n+ * This class can be used to create lists of {@link Rule} objects from lines of\n+ * .gitignore like files.\n+ * \n+ */\n+class IgnoreRuleListFactory {\n+\n+\tList<Rule> createIgnoreRuleList(final Iterable<String> lineIterable)\n+\t\t\tthrows InvalidPatternException {\n+\t\tLinkedList<Rule> rules = new LinkedList<Rule>();\n+\t\tfor (String line : lineIterable) {\n+\t\t\tfinal String trimmedLine = line.trim();\n+\t\t\tif (trimmedLine.startsWith(\"#\")) {\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (trimmedLine.length() == 0) {\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\trules.add(0, createRule(trimmedLine));\n+\t\t}\n+\t\treturn rules;\n+\t}\n+\n+\tList<Rule> createIgnoreRuleList(final List<File> files)\n+\t\t\tthrows FileNotFoundException, InvalidPatternException {\n+\t\tfinal List<String> lines = new ArrayList<String>();\n+\t\tfor (File file : files) {\n+\t\t\tScanner scanner = new Scanner(file);\n+\t\t\ttry {\n+\t\t\t\twhile (scanner.hasNextLine()) {\n+\t\t\t\t\tlines.add(scanner.nextLine());\n+\t\t\t\t}\n+\t\t\t} finally {\n+\t\t\t\tscanner.close();\n+\t\t\t}\n+\t\t}\n+\t\treturn createIgnoreRuleList(lines);\n+\t}\n+\n+\tprivate Rule createRule(String patternString)\n+\t\t\tthrows InvalidPatternException {\n+\t\tfinal boolean inverse = patternString.startsWith(\"!\");\n+\t\tif (inverse)\n+\t\t\tpatternString = patternString.substring(1);\n+\n+\t\tfinal FilePattern pattern = createFilePattern(patternString);\n+\t\treturn new Rule(!inverse, pattern);\n+\t}\n+\n+\tprivate FilePattern createFilePattern(String patternString)\n+\t\t\tthrows InvalidPatternException {\n+\t\tfinal boolean matchDirectoriesOnly = patternString.endsWith(\"/\");\n+\t\tif (matchDirectoriesOnly)\n+\t\t\tpatternString = patternString.substring(0,\n+\t\t\t\t\tpatternString.length() - 1);\n+\t\tif (patternString.contains(\"/\")) {\n+\t\t\tif (patternString.startsWith(\"/\"))\n+\t\t\t\tpatternString = patternString.substring(1);\n+\n+\t\t\treturn new FilePathPattern(patternString, false,\n+\t\t\t\t\tmatchDirectoriesOnly);\n+\t\t} else {\n+\t\t\treturn new FileNamePattern(patternString, matchDirectoriesOnly);\n+\t\t}\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77589","messageId":"1211574872-23676-10-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 09/23] Added a Rules interface implementation and a factory for it.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:18Z","receivedAt":"2008-05-23T20:34:18Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../treewalk/rules/RuleListToObjectConverter.java  |  130 ++++++++++++++++++++\n .../jgit/treewalk/rules/RulesImplementation.java   |   73 +++++++++++\n 2 files changed, 203 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RuleListToObjectConverter.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RulesImplementation.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RuleListToObjectConverter.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RuleListToObjectConverter.java\nnew file mode 100644\nindex 0000000..b67beff\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RuleListToObjectConverter.java\n@@ -0,0 +1,130 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.util.ArrayList;\n+import java.util.Iterator;\n+import java.util.List;\n+\n+/**\n+ * This class converts a list of {@link Rule} objects into a {@Rules} object.\n+ * During the conversion some optimizations are done:\n+ * <ul>\n+ * <li>Rules which can never match are removed. e.g. There is no need to check\n+ * the rule \"/a\" in the directory b.</li>\n+ * <li>The list is cut at the first rule which match always. *.txt\\n/a for\n+ * example would result in an internal list \"ignore all, ignore *.txt\" which is\n+ * then reduced to \"ignore all\".</li>\n+ * <li>Ignore rules which are direcly before an \"ignore all\" all rule are\n+ * removed. /a\\n*.txt for example would result in an intern \"ignore *.txt,\n+ * ignore all\" list which is then reduced to \"ignore all\",</li>\n+ * <li>\"do not ignore\" rules at the bottom of the intern list are removed. This\n+ * optimization would remove !a from \"!a\\n/b\" as it is in the inversed list at\n+ * the bottom.</li>\n+ * </ul>\n+ */\n+class RuleListToObjectConverter {\n+\tprotected Rules createIgnoreRules(Iterator<Rule> ruleIterator) {\n+\t\tfinal List<Rule> rules = getNessesaryRulesFromIterator(ruleIterator);\n+\t\tremoveUnnecessaryDoNotIgnoreRulesAtTheEndOfTheList(rules);\n+\t\tremoveUnnecessaryIgnoreRulesNearTheEndOfTheList(rules);\n+\n+\t\tif (rules.size() == 1) {\n+\t\t\tfinal Rule rule = rules.get(0);\n+\t\t\tif (rule.getPattern() == FilePattern.MATCH_ALWAYS) {\n+\t\t\t\tif (rule.isIgnoreAtMatch()) {\n+\t\t\t\t\treturn Rules.IGNORE_ALL;\n+\t\t\t\t} else {\n+\t\t\t\t\treturn Rules.IGNORE_NOTHING;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t} else if (rules.isEmpty()) {\n+\t\t\treturn Rules.IGNORE_NOTHING;\n+\t\t}\n+\t\treturn new RulesImplementation(rules, this);\n+\t}\n+\n+\tprivate List<Rule> getNessesaryRulesFromIterator(Iterator<Rule> ruleIterator) {\n+\t\tfinal List<Rule> rules = new ArrayList<Rule>();\n+\t\twhile (ruleIterator.hasNext()) {\n+\t\t\tfinal Rule subRule = ruleIterator.next();\n+\t\t\tif (subRule.getPattern() == FilePattern.MATCH_NEVER) {\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\trules.add(subRule);\n+\t\t\t// There is no need for rules after a rule witch match always,\n+\t\t\t// as such a rule would never be the first rule which matches.\n+\t\t\tif (subRule.getPattern() == FilePattern.MATCH_ALWAYS) {\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\treturn rules;\n+\t}\n+\n+\t/**\n+\t * Expects that\n+\t * {@link #removeUnnecessaryDoNotIgnoreRulesAtTheEndOfTheList(List)} has\n+\t * been executed first.\n+\t * \n+\t * @param rules\n+\t *            rule list to reduce.\n+\t */\n+\tprivate void removeUnnecessaryIgnoreRulesNearTheEndOfTheList(\n+\t\t\tfinal List<Rule> rules) {\n+\t\t// Why the following optimization makes only sense for the end of the\n+\t\t// list:\n+\t\t// If there is a \"ignore all\"- rule,\n+\t\t// then it is located at the end of the list\n+\t\t// See how the list is filled to prove this statement.\n+\t\tif (rules.size() >= 2) {\n+\t\t\tfinal Rule lastRule = rules.get(rules.size() - 1);\n+\t\t\tassert lastRule.isIgnoreAtMatch() : \"Expected that no 'not ignore'-rule is at the end of the list any more\";\n+\t\t\tfinal boolean ignoreAllAtEnd = lastRule.getPattern().equals(\n+\t\t\t\t\tFilePattern.MATCH_ALWAYS);\n+\t\t\tif (ignoreAllAtEnd) {\n+\t\t\t\twhile (rules.size() >= 2) {\n+\t\t\t\t\tfinal int ruleBeforeLastIndex = rules.size() - 2;\n+\t\t\t\t\tfinal Rule ruleBeforeLast = rules.get(ruleBeforeLastIndex);\n+\t\t\t\t\tif (ruleBeforeLast.isIgnoreAtMatch()) {\n+\t\t\t\t\t\trules.remove(ruleBeforeLastIndex);\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tprivate void removeUnnecessaryDoNotIgnoreRulesAtTheEndOfTheList(\n+\t\t\tfinal List<Rule> rules) {\n+\t\t// Why it is save to remove \"don't ignore rules\" at the end of the list\n+\t\t// if there is no \"ignore rule\" below a \"don't ignore rule\" then\n+\t\t// the path which haven't match jet will never be ignored:\n+\t\t// -> if another \"don't ignore rule\" match then the patch will not be\n+\t\t// ignored\n+\t\t// -> if no \"don't ignore rule\" match then the path will not be ignored.\n+\t\twhile (!rules.isEmpty()) {\n+\t\t\tfinal int indexOfLastRule = rules.size() - 1;\n+\t\t\tfinal Rule lastRule = rules.get(indexOfLastRule);\n+\t\t\tif (lastRule.isIgnoreAtMatch()) {\n+\t\t\t\tbreak;\n+\t\t\t} else {\n+\t\t\t\trules.remove(indexOfLastRule);\n+\t\t\t}\n+\t\t}\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RulesImplementation.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RulesImplementation.java\nnew file mode 100644\nindex 0000000..458b327\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/RulesImplementation.java\n@@ -0,0 +1,73 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.util.Iterator;\n+import java.util.List;\n+\n+class RulesImplementation implements Rules {\n+\t/**\n+\t * Complete list of rules. Note that order is: determining rule first.\n+\t */\n+\tprivate final List<Rule> rules;\n+\n+\t/**\n+\t * Factory used to create {@link Rules} for sub directories.\n+\t */\n+\tprivate RuleListToObjectConverter factory;\n+\n+\tRulesImplementation(List<Rule> rules, RuleListToObjectConverter factory) {\n+\t\tthis.rules = rules;\n+\t\tthis.factory = factory;\n+\t}\n+\n+\t/**\n+\t * @see Rules#toIgnore(java.lang.String, boolean)\n+\t */\n+\tpublic boolean toIgnore(String fileName, boolean fileIsDirectory) {\n+\t\tfor (Rule rule : rules) {\n+\t\t\tif (rule.getPattern().match(fileName, fileIsDirectory)) {\n+\t\t\t\treturn rule.isIgnoreAtMatch();\n+\t\t\t}\n+\t\t}\n+\t\treturn false;\n+\t}\n+\n+\t/**\n+\t * @see Rules#getRulesForSubDirectory(java.lang.String)\n+\t */\n+\tpublic Rules getRulesForSubDirectory(final String directoryName) {\n+\t\tfinal Iterator<Rule> subRuleIterator = new Iterator<Rule>() {\n+\t\t\tfinal Iterator<Rule> ruleIterator = rules.iterator();\n+\n+\t\t\tpublic boolean hasNext() {\n+\t\t\t\treturn ruleIterator.hasNext();\n+\t\t\t}\n+\n+\t\t\tpublic Rule next() {\n+\t\t\t\treturn ruleIterator.next()\n+\t\t\t\t\t\t.getRuleForSubDirectory(directoryName);\n+\t\t\t}\n+\n+\t\t\tpublic void remove() {\n+\t\t\t\tthrow new UnsupportedOperationException();\n+\t\t\t}\n+\n+\t\t};\n+\t\treturn factory.createIgnoreRules(subRuleIterator);\n+\t}\n+}\n-- \n1.5.4.3\n"},{"id":"77596","messageId":"1211574872-23676-11-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 10/23] Added test class OverallIgnoreRulestest.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:19Z","receivedAt":"2008-05-23T20:34:19Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../treewalk/rules/OverallIgnoreRulesTest.java     |  375 ++++++++++++++++++++\n 1 files changed, 375 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/OverallIgnoreRulesTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/OverallIgnoreRulesTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/OverallIgnoreRulesTest.java\nnew file mode 100644\nindex 0000000..71718bf\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/OverallIgnoreRulesTest.java\n@@ -0,0 +1,375 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.List;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+\n+import junit.framework.TestCase;\n+\n+public class OverallIgnoreRulesTest extends TestCase {\n+\tprivate IgnoreRulesFactory factory;\n+\n+\t@Override\n+\tprotected void setUp() throws Exception {\n+\t\tfactory = new IgnoreRulesFactory();\n+\t}\n+\n+\tpublic void testSimpleGlobalPattern() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"ab\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertTrue(ignoreRules.toIgnore(\"ab\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"ab\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"abc\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"abc\", true));\n+\t}\n+\n+\tpublic void testGlobalPatternWithOneStar() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"a*c\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"ac\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"ac\", true));\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"abc\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"abc\", true));\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"abbc\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"abbc\", true));\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"aabc\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"aabc\", true));\n+\n+\t\tassertFalse(ignoreRules.toIgnore(\"cab\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"cab\", true));\n+\t}\n+\n+\tpublic void testGlobalPatternWithTwoStars() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"a*c*e\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"ace\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"ace\", true));\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"abcde\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"abcde\", true));\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"aHellocWorlde\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"aHellocWorlde\", true));\n+\n+\t\tassertFalse(ignoreRules.toIgnore(\"ae\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"ae\", true));\n+\t}\n+\n+\tpublic void testGlobalPatternWithDots() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"*.tar.gz\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"test.tar.gz\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"test.tar.gz\", true));\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\".tar.gz\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\".tar.gz\", true));\n+\n+\t\tassertFalse(ignoreRules.toIgnore(\"test\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"test\", true));\n+\n+\t\t// test that \".\" isn't handled as \"any character\"\n+\t\tassertFalse(ignoreRules.toIgnore(\".tarogz\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\".tarogz\", true));\n+\t}\n+\n+\tpublic void testGlobalPatternDirectoryOnlyRule() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"a/\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"a\", false));\n+\n+\t\tfinal Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory(\"a\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesA);\n+\n+\t\tfinal Rules ignoreRulesB = ignoreRules.getRulesForSubDirectory(\"b\");\n+\t\tassertTrue(ignoreRulesB.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRulesB.toIgnore(\"a\", false));\n+\n+\t\tfinal Rules ignoreRulesBA = ignoreRulesB.getRulesForSubDirectory(\"a\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesBA);\n+\n+\t}\n+\n+\tpublic void testSimpleFilePathPattern() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"a/b/c\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertFalse(ignoreRules.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"a\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"b\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"b\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"c\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"c\", false));\n+\n+\t\tfinal Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory(\"a\");\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"a\", false));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"b\", true));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"b\", false));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"c\", true));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"c\", false));\n+\n+\t\tfinal Rules ignoreRulesAB = ignoreRulesA.getRulesForSubDirectory(\"b\");\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"a\", false));\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"b\", true));\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"b\", false));\n+\t\tassertTrue(ignoreRulesAB.toIgnore(\"c\", true));\n+\t\tassertTrue(ignoreRulesAB.toIgnore(\"c\", false));\n+\n+\t\tfinal Rules ignoreRulesABA = ignoreRulesAB.getRulesForSubDirectory(\"a\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesABA);\n+\n+\t\tfinal Rules ignoreRulesABB = ignoreRulesAB.getRulesForSubDirectory(\"b\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesABB);\n+\n+\t\tfinal Rules ignoreRulesABC = ignoreRulesAB.getRulesForSubDirectory(\"c\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesABC);\n+\t}\n+\n+\tpublic void testFilePathPatternDirectoryOnlyRule() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"a/b/c/\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertFalse(ignoreRules.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"a\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"b\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"b\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"c\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"c\", false));\n+\n+\t\tfinal Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory(\"a\");\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"a\", false));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"b\", true));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"b\", false));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"c\", true));\n+\t\tassertFalse(ignoreRulesA.toIgnore(\"c\", false));\n+\n+\t\tfinal Rules ignoreRulesAB = ignoreRulesA.getRulesForSubDirectory(\"b\");\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"a\", true));\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"a\", false));\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"b\", true));\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"b\", false));\n+\t\tassertTrue(ignoreRulesAB.toIgnore(\"c\", true));\n+\t\tassertFalse(ignoreRulesAB.toIgnore(\"c\", false));\n+\n+\t\tfinal Rules ignoreRulesABA = ignoreRulesAB.getRulesForSubDirectory(\"a\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesABA);\n+\n+\t\tfinal Rules ignoreRulesABB = ignoreRulesAB.getRulesForSubDirectory(\"b\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesABB);\n+\n+\t\tfinal Rules ignoreRulesABC = ignoreRulesAB.getRulesForSubDirectory(\"c\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesABC);\n+\t}\n+\n+\tpublic void testShortPathPattern() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"/alpha\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertTrue(ignoreRules.toIgnore(\"alpha\", true));\n+\t\tassertTrue(ignoreRules.toIgnore(\"alpha\", false));\n+\n+\t\tfinal Rules ignoreRulesAlpha = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"alpha\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesAlpha);\n+\n+\t\tfinal Rules ignoreRulesBeta = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"beta\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesBeta);\n+\t}\n+\n+\tpublic void testShortDirectoryPathPattern() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"/alpha/\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertTrue(ignoreRules.toIgnore(\"alpha\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"alpha\", false));\n+\n+\t\tfinal Rules ignoreRulesAlpha = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"alpha\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesAlpha);\n+\n+\t\tfinal Rules ignoreRulesBeta = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"beta\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesBeta);\n+\t}\n+\n+\tpublic void testShortPathPatternWithStar() throws Exception {\n+\t\tList<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"/.*\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\n+\t\tassertTrue(ignoreRules.toIgnore(\".test\", true));\n+\t\tassertTrue(ignoreRules.toIgnore(\".test\", false));\n+\n+\t\tassertFalse(ignoreRules.toIgnore(\"test\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"test\", false));\n+\n+\t\tfinal Rules ignoreRulesDotTest = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\".test\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesDotTest);\n+\n+\t\tfinal Rules ignoreRulesTest = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"test\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesTest);\n+\t}\n+\n+\tpublic void testPathPatternWith2Times2Stars() throws Exception {\n+\t\tfinal List<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"he*wor*d/*.*\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\n+\t\tassertFalse(ignoreRules.toIgnore(\"hello\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"hello\", false));\n+\t\tfinal Rules ignoreRulesHello = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"hello\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesHello);\n+\n+\t\tassertFalse(ignoreRules.toIgnore(\"helloworld\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"helloworld\", false));\n+\t\tfinal Rules ignoreRulesHelloWorld = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"helloworld\");\n+\t\tassertNotSame(Rules.IGNORE_NOTHING, ignoreRulesHelloWorld);\n+\n+\t\tassertTrue(ignoreRulesHelloWorld.toIgnore(\"test.txt\", true));\n+\t\tassertTrue(ignoreRulesHelloWorld.toIgnore(\"test.txt\", false));\n+\n+\t\tassertFalse(ignoreRulesHelloWorld.toIgnore(\"test\", true));\n+\t\tassertFalse(ignoreRulesHelloWorld.toIgnore(\"test\", false));\n+\n+\t\tfinal Rules ignoreRulesTestTxt = ignoreRulesHelloWorld\n+\t\t\t\t.getRulesForSubDirectory(\"test.txt\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesTestTxt);\n+\n+\t\tfinal Rules ignoreRulesTest = ignoreRulesHelloWorld\n+\t\t\t\t.getRulesForSubDirectory(\"test\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesTest);\n+\t}\n+\n+\tpublic void testEmptyIgnoreList() throws Exception {\n+\t\tfinal List<String> lines = Collections.emptyList();\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRules);\n+\t}\n+\n+\tpublic void testOnlyOneNegatedIgnore() throws Exception {\n+\t\tfinal List<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"!a\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRules);\n+\t}\n+\n+\tpublic void testOnlyThreeNegatedIgnores() throws Exception {\n+\t\tfinal List<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"!a\");\n+\t\tlines.add(\"!a/b/c\");\n+\t\tlines.add(\"!b*\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRules);\n+\t}\n+\n+\tpublic void testNegatedIgnoreCase1() throws Exception {\n+\t\tfinal List<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"/a\");\n+\t\tlines.add(\"!b\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tfinal Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory(\"a\");\n+\t\tfinal Rules ignoreRulesAB = ignoreRulesA.getRulesForSubDirectory(\"b\");\n+\t\tfinal Rules ignoreRulesB = ignoreRules.getRulesForSubDirectory(\"b\");\n+\t\tfinal Rules ignoreRulesC = ignoreRules.getRulesForSubDirectory(\"c\");\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesB);\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesAB);\n+\t\tassertSame(Rules.IGNORE_NOTHING, ignoreRulesC);\n+\t\tassertTrue(ignoreRules.toIgnore(\"a\", true));\n+\t\tassertTrue(ignoreRules.toIgnore(\"a\", false));\n+\t\tassertTrue(ignoreRulesA.toIgnore(\"c\", true));\n+\t\tassertTrue(ignoreRulesA.toIgnore(\"c\", false));\n+\t}\n+\n+\tpublic void testExceptionOfException() throws Exception {\n+\t\tfinal List<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"*.*\");\n+\t\tlines.add(\"!*.c\");\n+\t\tlines.add(\"a.c\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertTrue(ignoreRules.toIgnore(\"b.txt\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"b.txt\", true));\n+\t\tassertTrue(ignoreRules.toIgnore(\"a.c\", false));\n+\t\tassertTrue(ignoreRules.toIgnore(\"a.c\", true));\n+\t\tassertFalse(ignoreRules.toIgnore(\"b.c\", false));\n+\t\tassertFalse(ignoreRules.toIgnore(\"b.c\", true));\n+\t}\n+\n+\tpublic void testComplexCase() throws Exception {\n+\t\tfinal List<String> lines = new ArrayList<String>();\n+\t\tlines.add(\"*\");\n+\t\tlines.add(\"!/alpha/src\");\n+\t\tlines.add(\"*~\");\n+\t\tfinal Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);\n+\t\tassertTrue(ignoreRules.toIgnore(\"beta\", true));\n+\t\tassertTrue(ignoreRules.toIgnore(\"alpha\", true));\n+\t\tfinal Rules ignoreRulesAlpha = ignoreRules\n+\t\t\t\t.getRulesForSubDirectory(\"alpha\");\n+\t\tfinal Rules ignoreRulesAlphaBin = ignoreRulesAlpha\n+\t\t\t\t.getRulesForSubDirectory(\"bin\");\n+\t\tfinal Rules ignoreRulesAlphaSrc = ignoreRulesAlpha\n+\t\t\t\t.getRulesForSubDirectory(\"src\");\n+\t\tassertSame(Rules.IGNORE_ALL, ignoreRulesAlphaBin);\n+\t\tassertFalse(ignoreRulesAlphaSrc.toIgnore(\"com\", true));\n+\t\tassertFalse(ignoreRulesAlphaSrc.toIgnore(\"b.java\", false));\n+\t\tassertTrue(ignoreRulesAlphaSrc.toIgnore(\"b.java~\", true));\n+\t}\n+\n+\tprivate class IgnoreRulesFactory {\n+\t\tprivate RuleListToObjectConverter converter = new RuleListToObjectConverter();\n+\n+\t\tprivate IgnoreRuleListFactory listFactory = new IgnoreRuleListFactory();\n+\n+\t\t/**\n+\t\t * @param ignoreFileLines\n+\t\t *            the lines of a ignore file like .gitignore.\n+\t\t * @return a immutable IgnoreRules object.\n+\t\t * @throws InvalidPatternException\n+\t\t */\n+\t\tpublic Rules createIgnoreRulesFromLines(Iterable<String> ignoreFileLines)\n+\t\t\t\tthrows InvalidPatternException {\n+\t\t\tfinal List<Rule> rules = listFactory\n+\t\t\t\t\t.createIgnoreRuleList(ignoreFileLines);\n+\t\t\treturn converter.createIgnoreRules(rules.iterator());\n+\t\t}\n+\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77586","messageId":"1211574872-23676-12-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 11/23] Added the class PathNotInProjectDirectoryException.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:20Z","receivedAt":"2008-05-23T20:34:20Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../errors/PathNotInProjectDirectoryException.java |   25 ++++++++++++++++++++\n 1 files changed, 25 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java\nnew file mode 100644\nindex 0000000..a406aef\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java\n@@ -0,0 +1,25 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.errors;\n+\n+/**\n+ * Thrown when a path wasn't in the project directory, but expected to be.\n+ * \n+ */\n+public class PathNotInProjectDirectoryException extends\n+\t\tIllegalArgumentException {\n+}\n-- \n1.5.4.3\n"},{"id":"77592","messageId":"1211574872-23676-13-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 12/23] Added the class AddRuleListFactory.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:21Z","receivedAt":"2008-05-23T20:34:21Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/rules/AddRuleListFactory.java    |   75 ++++++++++++++++++++\n 1 files changed, 75 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java\nnew file mode 100644\nindex 0000000..5c385c1\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java\n@@ -0,0 +1,75 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.errors.PathNotInProjectDirectoryException;\n+\n+class AddRuleListFactory {\n+\n+\tprivate static String getRelativeUnixPath(File projectDirectory, File file)\n+\t\t\tthrows PathNotInProjectDirectoryException, IOException {\n+\t\tfinal StringBuilder resultBuilder = new StringBuilder();\n+\t\tFile currentFile = file.getCanonicalFile();\n+\t\twhile (!currentFile.equals(projectDirectory)) {\n+\t\t\tif (resultBuilder.length() > 0) {\n+\t\t\t\tresultBuilder.insert(0, '/');\n+\t\t\t}\n+\t\t\tresultBuilder.insert(0, currentFile.getName());\n+\t\t\tcurrentFile = currentFile.getParentFile();\n+\t\t\tif (currentFile == null) {\n+\t\t\t\tthrow new PathNotInProjectDirectoryException();\n+\t\t\t}\n+\t\t}\n+\t\treturn resultBuilder.toString();\n+\t}\n+\n+\tList<Rule> createRuleList(File projectDirectory, File workingDirectory,\n+\t\t\tList<String> filePatternsOfAddCommand)\n+\t\t\tthrows PathNotInProjectDirectoryException, IOException,\n+\t\t\tInvalidPatternException {\n+\n+\t\tfinal String workingDirectoryPath = getRelativeUnixPath(\n+\t\t\t\tprojectDirectory, workingDirectory);\n+\n+\t\tfinal List<Rule> ruleList = new ArrayList<Rule>(\n+\t\t\t\tfilePatternsOfAddCommand.size());\n+\t\tfor (String pattern : filePatternsOfAddCommand) {\n+\t\t\tboolean matchDirectoriesOnly = false;\n+\t\t\tif (pattern.endsWith(File.separator)) {\n+\t\t\t\tpattern = pattern.substring(0, pattern.length() - 1);\n+\t\t\t\tmatchDirectoriesOnly = true;\n+\t\t\t}\n+\t\t\tpattern = pattern.replace(File.separatorChar, '/');\n+\t\t\tif (!\"\".equals(workingDirectoryPath)) {\n+\t\t\t\tpattern = workingDirectoryPath + \"/\" + pattern;\n+\n+\t\t\t}\n+\t\t\tfinal FilePattern filePattern = new FilePathPattern(pattern, true,\n+\t\t\t\t\tmatchDirectoriesOnly);\n+\t\t\tfinal Rule rule = new Rule(false, filePattern);\n+\t\t\truleList.add(rule);\n+\n+\t\t}\n+\t\treturn ruleList;\n+\t}\n+}\n-- \n1.5.4.3\n"},{"id":"77576","messageId":"1211574872-23676-14-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 13/23] Formatted Constants class.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:22Z","receivedAt":"2008-05-23T20:34:22Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../src/org/spearce/jgit/lib/Constants.java        |   14 ++++++++------\n 1 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\nindex 0c83cf2..febf469 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n@@ -201,8 +201,9 @@ public final class Constants {\n \n \t/**\n \t * Convert an OBJ_* type constant to a TYPE_* type constant.\n-\t *\n-\t * @param typeCode the type code, from a pack representation.\n+\t * \n+\t * @param typeCode\n+\t *            the type code, from a pack representation.\n \t * @return the canonical string name of this type.\n \t */\n \tpublic static String typeString(final int typeCode) {\n@@ -223,10 +224,11 @@ public final class Constants {\n \t/**\n \t * Convert an OBJ_* type constant to an ASCII encoded string constant.\n \t * <p>\n-\t * The ASCII encoded string is often the canonical representation of\n-\t * the type within a loose object header, or within a tag header.\n-\t *\n-\t * @param typeCode the type code, from a pack representation.\n+\t * The ASCII encoded string is often the canonical representation of the\n+\t * type within a loose object header, or within a tag header.\n+\t * \n+\t * @param typeCode\n+\t *            the type code, from a pack representation.\n \t * @return the canonical ASCII encoded name of this type.\n \t */\n \tpublic static byte[] encodedTypeString(final int typeCode) {\n-- \n1.5.4.3\n"},{"id":"77577","messageId":"1211574872-23676-15-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 14/23] Added constant REPOSITORY_DIRECTORY_NAME to Constants class.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:23Z","receivedAt":"2008-05-23T20:34:23Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../src/org/spearce/jgit/lib/Constants.java        |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\nindex febf469..7444d1d 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n@@ -182,6 +182,12 @@ public final class Constants {\n \tpublic static final String TAGS_PREFIX = \"refs/tags\";\n \n \t/**\n+\t * The name of the repository directory in the project directory. Project\n+\t * directory means here the tree under version control.\n+\t */\n+\tpublic static final String REPOSITORY_DIRECTORY_NAME = \".git\";\n+\n+\t/**\n \t * Create a new digest function for objects.\n \t * \n \t * @return a new digest object.\n-- \n1.5.4.3\n"},{"id":"77585","messageId":"1211574872-23676-16-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 15/23] Added class AddRulesFactory.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:24Z","receivedAt":"2008-05-23T20:34:24Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/rules/AddRulesFactory.java       |   90 ++++++++++++++++++++\n 1 files changed, 90 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRulesFactory.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRulesFactory.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRulesFactory.java\nnew file mode 100644\nindex 0000000..3daa928\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRulesFactory.java\n@@ -0,0 +1,90 @@\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.io.File;\n+import java.io.FileNotFoundException;\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.errors.PathNotInProjectDirectoryException;\n+import static org.spearce.jgit.lib.Constants.REPOSITORY_DIRECTORY_NAME;\n+\n+/**\n+ * This class is designed to serve the needs of someone who want to implement a\n+ * git-add command and needs to determine the files to add.\n+ * \n+ */\n+public class AddRulesFactory {\n+\tprivate final RuleListToObjectConverter converter = new RuleListToObjectConverter();\n+\n+\tprivate final IgnoreRuleListFactory ignoreRuleListFactory = new IgnoreRuleListFactory();\n+\n+\tprivate final AddRuleListFactory addRuleListFactory = new AddRuleListFactory();\n+\n+\t/**\n+\t * @param workTreeDirectory\n+\t *            The directory with the files of the project under version\n+\t *            control.\n+\t * @param workingDirectory\n+\t *            a directory within the workTreeDirectory.\n+\t * @param filePatternsOfAddCommand\n+\t *            the file patterns passed to the add command.\n+\t * @return a {@link Rules} containing the specified rules, the .gitignore\n+\t *         and the .git/info/exclude rules.\n+\t * @throws InvalidPatternException\n+\t *             if a pattern is invalid.\n+\t * @throws PathNotInProjectDirectoryException\n+\t *             if the directory workingDirectory is not in workTreeDirectory\n+\t * @throws IOException\n+\t *             for some reasons.\n+\t */\n+\tpublic Rules createRules(File workTreeDirectory, File workingDirectory,\n+\t\t\tList<String> filePatternsOfAddCommand)\n+\t\t\tthrows InvalidPatternException, PathNotInProjectDirectoryException,\n+\t\t\tIOException {\n+\t\tfinal Rule gitDirectoryIgnoreRule = createGitDirectoryIgnoreRule();\n+\t\tfinal File gitDirectory = new File(workTreeDirectory,\n+\t\t\t\tREPOSITORY_DIRECTORY_NAME);\n+\t\tfinal List<Rule> ignoreRuleListFromFiles = createExcludeRules(\n+\t\t\t\tworkTreeDirectory, gitDirectory);\n+\t\tfinal List<Rule> includeRules = addRuleListFactory.createRuleList(\n+\t\t\t\tworkTreeDirectory, workingDirectory, filePatternsOfAddCommand);\n+\t\tfinal List<Rule> ruleList = new ArrayList<Rule>();\n+\n+\t\truleList.add(gitDirectoryIgnoreRule);\n+\t\truleList.addAll(ignoreRuleListFromFiles);\n+\t\truleList.addAll(includeRules);\n+\t\truleList.add(new Rule(true, FilePattern.MATCH_ALWAYS));\n+\n+\t\treturn converter.createIgnoreRules(ruleList.iterator());\n+\t}\n+\n+\tprivate List<Rule> createExcludeRules(File projectDirectory,\n+\t\t\tFile gitDirectory) throws InvalidPatternException {\n+\t\tfinal List<File> possibleIgnoreFiles = new ArrayList<File>(2);\n+\t\tpossibleIgnoreFiles.add(new File(projectDirectory, \".gitignore\"));\n+\t\tpossibleIgnoreFiles.add(new File(new File(gitDirectory, \"info\"),\n+\t\t\t\t\"exclude\"));\n+\n+\t\tfinal List<File> ignoreFiles = new ArrayList<File>();\n+\t\tfor (File possibleIgnoreFile : possibleIgnoreFiles) {\n+\t\t\tif (possibleIgnoreFile.isFile()) {\n+\t\t\t\tignoreFiles.add(possibleIgnoreFile);\n+\t\t\t}\n+\t\t}\n+\n+\t\ttry {\n+\t\t\treturn ignoreRuleListFactory.createIgnoreRuleList(ignoreFiles);\n+\t\t} catch (FileNotFoundException e) {\n+\t\t\tthrow new RuntimeException(\"unexpected removal of ignore files\", e);\n+\t\t}\n+\t}\n+\n+\tprivate Rule createGitDirectoryIgnoreRule() throws InvalidPatternException {\n+\t\tfinal FilePattern gitDirectoryPattern = new FilePathPattern(\n+\t\t\t\tREPOSITORY_DIRECTORY_NAME, true, true);\n+\t\tfinal Rule gitDirectoryIgnoreRule = new Rule(true, gitDirectoryPattern);\n+\t\treturn gitDirectoryIgnoreRule;\n+\t}\n+}\n-- \n1.5.4.3\n"},{"id":"77587","messageId":"1211574872-23676-17-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 16/23] Added the class LightFileTreeIterator and a test for it.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:25Z","receivedAt":"2008-05-23T20:34:25Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/LightFileTreeIteratorTest.java   |  114 ++++++++++++++++++++\n .../jgit/treewalk/LightFileTreeIterator.java       |  112 +++++++++++++++++++\n 2 files changed, 226 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java\nnew file mode 100644\nindex 0000000..f937182\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java\n@@ -0,0 +1,114 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk;\n+\n+import java.io.File;\n+import java.util.HashSet;\n+import java.util.Iterator;\n+import java.util.Set;\n+\n+import org.spearce.jgit.treewalk.rules.Rules;\n+\n+import junit.framework.TestCase;\n+\n+public class LightFileTreeIteratorTest extends TestCase {\n+\tprivate String DIRECTORY_A_NAME = \"a\";\n+\n+\tprivate String DIRECTORY_AB_NAME = \"b\";\n+\n+\tprivate File projectDirectory;\n+\n+\tprivate File fileB;\n+\n+\tprivate File directoryA;\n+\n+\tprivate File directoryAB;\n+\n+\tprivate File fileABA;\n+\n+\tprivate File directoryAC;\n+\n+\tprivate File fileACA;\n+\n+\tprivate File fileACB;\n+\n+\t@Override\n+\tprotected void setUp() throws Exception {\n+\t\tthis.projectDirectory = File.createTempFile(\"FileTreeIteratorTest\", \"\");\n+\t\tprojectDirectory.delete();\n+\t\tprojectDirectory.mkdir();\n+\t\tprojectDirectory.deleteOnExit();\n+\n+\t\tthis.directoryA = new File(projectDirectory, DIRECTORY_A_NAME);\n+\t\tdirectoryA.mkdir();\n+\n+\t\tthis.directoryAB = new File(directoryA, DIRECTORY_AB_NAME);\n+\t\tdirectoryAB.mkdir();\n+\n+\t\tthis.fileABA = new File(directoryAB, \"a.y\");\n+\t\tfileABA.createNewFile();\n+\n+\t\tthis.directoryAC = new File(directoryA, \"c\");\n+\t\tthis.directoryAC.mkdir();\n+\n+\t\tthis.fileACA = new File(directoryAC, \"a.x\");\n+\t\tfileACA.createNewFile();\n+\n+\t\tthis.fileACB = new File(directoryAC, \"b.y\");\n+\t\tfileACB.createNewFile();\n+\n+\t\tthis.fileB = new File(projectDirectory, \"b.x\");\n+\t\tfileB.createNewFile();\n+\t}\n+\n+\tpublic void testFileTreeIterator() {\n+\t\tfinal Iterator<File> iterator = new LightFileTreeIterator(\n+\t\t\t\tprojectDirectory, Rules.IGNORE_NOTHING, false);\n+\t\tfinal Set<File> actualPathes = new HashSet<File>();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\tfinal File next = iterator.next();\n+\t\t\tassertFalse(actualPathes.contains(next));\n+\t\t\tactualPathes.add(next);\n+\t\t}\n+\n+\t\tfinal Set<File> expectedPathes = new HashSet<File>();\n+\t\texpectedPathes.add(directoryA);\n+\t\texpectedPathes.add(fileB);\n+\t\texpectedPathes.add(directoryAB);\n+\t\texpectedPathes.add(fileABA);\n+\t\texpectedPathes.add(directoryAC);\n+\t\texpectedPathes.add(fileACA);\n+\t\texpectedPathes.add(fileACB);\n+\t\tassertEquals(expectedPathes, actualPathes);\n+\n+\t}\n+\n+\tpublic void testFileTreeIteratorWithIgnoreAllRules() {\n+\t\tfinal Iterator<File> iterator = new LightFileTreeIterator(\n+\t\t\t\tprojectDirectory, Rules.IGNORE_ALL, false);\n+\t\tfinal Set<File> actualPathes = new HashSet<File>();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\tfinal File next = iterator.next();\n+\t\t\tassertFalse(actualPathes.contains(next));\n+\t\t\tactualPathes.add(next);\n+\t\t}\n+\n+\t\tassertEquals(0, actualPathes.size());\n+\n+\t}\n+\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java\nnew file mode 100644\nindex 0000000..45fb167\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java\n@@ -0,0 +1,112 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk;\n+\n+import java.io.File;\n+import java.util.EmptyStackException;\n+import java.util.Iterator;\n+import java.util.NoSuchElementException;\n+import java.util.Stack;\n+\n+import org.spearce.jgit.treewalk.rules.Rules;\n+\n+class LightFileTreeIterator implements Iterator<File> {\n+\tprivate final Stack<File> remainingPathes;\n+\n+\tprivate final Stack<Directory> remainingDirectories;\n+\n+\t/**\n+\t * Creates a new Iterator which allows to iterate over the content of the\n+\t * specified rootDirectory. The rootDirectory itself is never included.\n+\t * \n+\t * @param rootDirectory\n+\t *            the directory tree to iterate over.\n+\t * @param ignoreRules\n+\t *            defines which paths are included and which aren't.\n+\t * @param includeRootDirectory\n+\t *            the iterator will return the rootDirectory if this is flag is\n+\t *            true.\n+\t */\n+\tLightFileTreeIterator(File rootDirectory, Rules ignoreRules,\n+\t\t\tboolean includeRootDirectory) {\n+\t\tremainingPathes = new Stack<File>();\n+\t\tif (includeRootDirectory) {\n+\t\t\tremainingPathes.add(rootDirectory);\n+\t\t}\n+\t\tremainingDirectories = new Stack<Directory>();\n+\t\tremainingDirectories.add(new Directory(rootDirectory, ignoreRules));\n+\t}\n+\n+\tpublic boolean hasNext() {\n+\t\tfindMorePathesIfNessesary();\n+\t\treturn !remainingPathes.empty();\n+\t}\n+\n+\tvoid findMorePathesIfNessesary() {\n+\t\tif (remainingPathes.isEmpty()) {\n+\t\t\tfindMorePathes();\n+\t\t}\n+\t}\n+\n+\tvoid findMorePathes() {\n+\t\twhile (!remainingDirectories.isEmpty() && remainingPathes.isEmpty()) {\n+\t\t\tfinal Directory directory = remainingDirectories.pop();\n+\t\t\tfinal File[] pathes = directory.path.listFiles();\n+\t\t\tfor (File path : pathes) {\n+\t\t\t\tfinal boolean fileIsDirectory = path.isDirectory();\n+\t\t\t\tif (fileIsDirectory) {\n+\t\t\t\t\tfinal Rules subDirectoryIgnoreRules = directory.ignoreRules\n+\t\t\t\t\t\t\t.getRulesForSubDirectory(path.getName());\n+\t\t\t\t\tif (subDirectoryIgnoreRules != Rules.IGNORE_ALL) {\n+\t\t\t\t\t\tfinal Directory subDirectory = new Directory(path,\n+\t\t\t\t\t\t\t\tsubDirectoryIgnoreRules);\n+\t\t\t\t\t\tremainingDirectories.add(subDirectory);\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\tif (!directory.ignoreRules.toIgnore(path.getName(),\n+\t\t\t\t\t\tfileIsDirectory)) {\n+\t\t\t\t\tremainingPathes.add(path);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tpublic File next() {\n+\t\tfindMorePathesIfNessesary();\n+\t\ttry {\n+\t\t\treturn remainingPathes.pop();\n+\t\t} catch (EmptyStackException e) {\n+\t\t\tthrow new NoSuchElementException();\n+\t\t}\n+\t}\n+\n+\tpublic void remove() {\n+\t\tthrow new UnsupportedOperationException();\n+\t}\n+\n+\tprivate class Directory {\n+\t\tfinal File path;\n+\n+\t\tfinal Rules ignoreRules;\n+\n+\t\tDirectory(File path, Rules ignoreRules) {\n+\t\t\tthis.path = path;\n+\t\t\tthis.ignoreRules = ignoreRules;\n+\t\t}\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77595","messageId":"1211574872-23676-18-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 17/23] Added class LightFileTreeIterable.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:26Z","receivedAt":"2008-05-23T20:34:26Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/LightFileTreeIterable.java       |   59 ++++++++++++++++++++\n 1 files changed, 59 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterable.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterable.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterable.java\nnew file mode 100644\nindex 0000000..5768f78\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterable.java\n@@ -0,0 +1,59 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk;\n+\n+import java.io.File;\n+import java.util.Iterator;\n+\n+import org.spearce.jgit.treewalk.rules.Rules;\n+\n+/**\n+ * Use this class to iterate over some by rules determined files in a project\n+ * directory.\n+ * \n+ */\n+public class LightFileTreeIterable implements Iterable<File> {\n+\tprivate final File projectDirectory;\n+\n+\tprivate final Rules ignoreRules;\n+\n+\tprivate final boolean includeRootDirectory;\n+\n+\t/**\n+\t * \n+\t * @param workTreeDirectory\n+\t *            directory with the files which are under version control.\n+\t * @param rules\n+\t *            a {@link Rules} instance which is used to determine which file\n+\t *            are included and which not.\n+\t * @param includeWorkTreeDirectory\n+\t *            determines if the iterators should return the\n+\t *            workTreeDirectory\n+\t */\n+\tpublic LightFileTreeIterable(File workTreeDirectory, Rules rules,\n+\t\t\tboolean includeWorkTreeDirectory) {\n+\t\tthis.projectDirectory = workTreeDirectory;\n+\t\tthis.ignoreRules = rules;\n+\t\tthis.includeRootDirectory = includeWorkTreeDirectory;\n+\t}\n+\n+\tpublic Iterator<File> iterator() {\n+\t\treturn new LightFileTreeIterator(projectDirectory, ignoreRules,\n+\t\t\t\tincludeRootDirectory);\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77598","messageId":"1211574872-23676-19-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 18/23] Added path related constants to the Constants class.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:27Z","receivedAt":"2008-05-23T20:34:27Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"---\n .../src/org/spearce/jgit/lib/Constants.java        |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\nindex 7444d1d..38b0626 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n@@ -188,6 +188,16 @@ public final class Constants {\n \tpublic static final String REPOSITORY_DIRECTORY_NAME = \".git\";\n \n \t/**\n+\t * Contains the name of the objects directory in the repository directory.\n+\t */\n+\tpublic static final String OBJECTS_DIRECTORY_NAME = \"objects\";\n+\n+\t/**\n+\t * Contains the name of the refs directory in the repository directory.\n+\t */\n+\tpublic static final String REFS_DIRECTORY_NAME = \"refs\";\n+\n+\t/**\n \t * Create a new digest function for objects.\n \t * \n \t * @return a new digest object.\n-- \n1.5.4.3\n"},{"id":"77588","messageId":"1211574872-23676-20-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 19/23] Added WorkTree class which can be constructed over Repository.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:28Z","receivedAt":"2008-05-23T20:34:28Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"---\n .../src/org/spearce/jgit/lib/Repository.java       |   57 +++++++++++++++++\n .../src/org/spearce/jgit/lib/WorkTree.java         |   67 ++++++++++++++++++++\n 2 files changed, 124 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/WorkTree.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\nindex 54edc8a..86817c9 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n@@ -1157,4 +1157,61 @@ public class Repository {\n \tpublic File getWorkDir() {\n \t\treturn getDirectory().getParentFile();\n \t}\n+\n+\t/**\n+\t * Setup HEAD and \"master\" refs for a new repository.\n+\t * \n+\t * @param remoteBranch\n+\t *            The remote branch to start with\n+\t * @param branch\n+\t *            The local branch to configure, initially starting at\n+\t *            remoteBranch\n+\t * @return the commit references by the new HEAD\n+\t * @throws IOException\n+\t */\n+\tpublic Commit setupHEADRef(final String remoteBranch, final String branch)\n+\t\t\tthrows IOException {\n+\t\tCommit mapCommit = mapCommit(remoteBranch);\n+\t\tString refName = Constants.HEADS_PREFIX + \"/\" + branch;\n+\t\tLockFile masterRef = lockRef(refName);\n+\t\ttry {\n+\t\t\tmasterRef.write(mapCommit.getCommitId());\n+\t\t\tmasterRef.commit();\n+\t\t} finally {\n+\t\t\tmasterRef.unlock();\n+\t\t}\n+\t\twriteSymref(Constants.HEAD, refName);\n+\t\treturn mapCommit;\n+\t}\n+\n+\t/**\n+\t * Creates a new {@link WorkTree} and initialize a repository for it.\n+\t * \n+\t * @param workTreeDirectory\n+\t *            the directory with the project files.\n+\t * @return a new {@link WorkTree} with a new and open {@link Repository}.\n+\t * @throws IOException\n+\t *             thrown by {@link Repository#create()}\n+\t */\n+\tpublic static WorkTree createWorkTree(File workTreeDirectory)\n+\t\t\tthrows IOException {\n+\t\tfinal File gitDirectory = new File(workTreeDirectory,\n+\t\t\t\tConstants.REPOSITORY_DIRECTORY_NAME);\n+\t\tif (gitDirectory.exists()) {\n+\t\t\tthrow new IllegalArgumentException(\n+\t\t\t\t\t\"Repository exists in given project directory.\");\n+\t\t}\n+\t\tfinal Repository repository = new Repository(gitDirectory);\n+\t\ttry {\n+\t\t\trepository.create();\n+\t\t\treturn new WorkTree(workTreeDirectory, repository);\n+\t\t} catch (RuntimeException e) {\n+\t\t\trepository.close();\n+\t\t\tthrow e;\n+\t\t} catch (IOException e) {\n+\t\t\trepository.close();\n+\t\t\tthrow e;\n+\t\t}\n+\t}\n+\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WorkTree.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WorkTree.java\nnew file mode 100644\nindex 0000000..14bdda0\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WorkTree.java\n@@ -0,0 +1,67 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.lib;\n+\n+import java.io.File;\n+\n+/**\n+ * Represents a work tree controlled by git. Use {@link Repository} in order to\n+ * create an object of this class.\n+ * \n+ */\n+public class WorkTree {\n+\tprivate final File directory;\n+\n+\tprivate final Repository repository;\n+\n+\t/**\n+\t * This constructor should be only used by the class {@link Repository}.\n+\t * \n+\t * @param directory\n+\t *            defines the value of the directory field.\n+\t * @param repository\n+\t *            defines the value of the repository field.\n+\t */\n+\tWorkTree(File directory, Repository repository) {\n+\t\tthis.directory = directory;\n+\t\tthis.repository = repository;\n+\t}\n+\n+\t/**\n+\t * \n+\t * @return the directory which contains the files of the project. Usually\n+\t *         this directory contain a .git directory with the repository.\n+\t */\n+\tpublic File getDirectory() {\n+\t\treturn directory;\n+\t}\n+\n+\t/**\n+\t * @return the {@link Repository} object of the project.\n+\t */\n+\tpublic Repository getRepository() {\n+\t\treturn repository;\n+\t}\n+\n+\t/**\n+\t * Closes the git repository of this project.\n+\t */\n+\tpublic void closeRepository() {\n+\t\trepository.close();\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77594","messageId":"1211574872-23676-21-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 20/23] Added the class NoGitRepositoryFoundException.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:29Z","receivedAt":"2008-05-23T20:34:29Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/errors/NoGitRepositoryFoundException.java |   28 ++++++++++++++++++++\n 1 files changed, 28 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/NoGitRepositoryFoundException.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/NoGitRepositoryFoundException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/NoGitRepositoryFoundException.java\nnew file mode 100644\nindex 0000000..a0c6e83\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/NoGitRepositoryFoundException.java\n@@ -0,0 +1,28 @@\n+package org.spearce.jgit.errors;\n+\n+import java.io.File;\n+\n+/**\n+ * No git repository could be found for a file or directory.\n+ */\n+public class NoGitRepositoryFoundException extends Exception {\n+\tprivate final File fileWeSearchedRepositoryFor;\n+\n+\t/**\n+\t * @param fileWeSearchedRepositoryFor\n+\t *            the file for which a repository was searched.\n+\t */\n+\tpublic NoGitRepositoryFoundException(final File fileWeSearchedRepositoryFor) {\n+\t\tsuper(String.format(\"No repository found for file '%s'\",\n+\t\t\t\tfileWeSearchedRepositoryFor));\n+\t\tthis.fileWeSearchedRepositoryFor = fileWeSearchedRepositoryFor;\n+\t}\n+\n+\t/**\n+\t * @return the file searched for.\n+\t */\n+\tpublic File getFileWeSearchedRepositoryFor() {\n+\t\treturn fileWeSearchedRepositoryFor;\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"77597","messageId":"1211574872-23676-22-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 21/23] Formatted Repository class.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:30Z","receivedAt":"2008-05-23T20:34:30Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../src/org/spearce/jgit/lib/Repository.java       |  345 +++++++++++---------\n 1 files changed, 192 insertions(+), 153 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\nindex 86817c9..06e686f 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n@@ -38,24 +38,25 @@ import org.spearce.jgit.util.FS;\n  * Represents a Git repository. A repository holds all objects and refs used for\n  * managing source code (could by any type of file, but source code is what\n  * SCM's are typically used for).\n- *\n+ * \n  * In Git terms all data is stored in GIT_DIR, typically a directory called\n  * .git. A work tree is maintained unless the repository is a bare repository.\n  * Typically the .git directory is located at the root of the work dir.\n- *\n+ * \n  * <ul>\n  * <li>GIT_DIR\n- * \t<ul>\n- * \t\t<li>objects/ - objects</li>\n- * \t\t<li>refs/ - tags and heads</li>\n- * \t\t<li>config - configuration</li>\n- * \t\t<li>info/ - more configurations</li>\n- * \t</ul>\n+ * <ul>\n+ * <li>objects/ - objects</li>\n+ * <li>refs/ - tags and heads</li>\n+ * <li>config - configuration</li>\n+ * <li>info/ - more configurations</li>\n+ * </ul>\n  * </li>\n  * </ul>\n- *\n- * This implementation only handles a subtly undocumented subset of git features.\n- *\n+ * \n+ * This implementation only handles a subtly undocumented subset of git\n+ * features.\n+ * \n  */\n public class Repository {\n \tprivate static final String[] refSearchPaths = { \"\", \"refs/\",\n@@ -80,7 +81,7 @@ public class Repository {\n \n \t/**\n \t * Construct a representation of this git repo managing a Git repository.\n-\t *\n+\t * \n \t * @param d\n \t *            GIT_DIR\n \t * @throws IOException\n@@ -109,7 +110,8 @@ public class Repository {\n \t\t\tobjectsDirs = readObjectsDirs(FS.resolve(gitDir, \"objects\"),\n \t\t\t\t\tnew ArrayList<File>()).toArray(new File[0]);\n \t\t} catch (IOException e) {\n-\t\t\tIOException ex = new IOException(\"Cannot find all object dirs for \" + gitDir);\n+\t\t\tIOException ex = new IOException(\"Cannot find all object dirs for \"\n+\t\t\t\t\t+ gitDir);\n \t\t\tex.initCause(e);\n \t\t\tthrow ex;\n \t\t}\n@@ -135,12 +137,13 @@ public class Repository {\n \t\t\tscanForPacks();\n \t}\n \n-\tprivate Collection<File> readObjectsDirs(File objectsDir, Collection<File> ret) throws IOException {\n+\tprivate Collection<File> readObjectsDirs(File objectsDir,\n+\t\t\tCollection<File> ret) throws IOException {\n \t\tret.add(objectsDir);\n \t\tfinal File altFile = FS.resolve(objectsDir, \"info/alternates\");\n \t\tif (altFile.exists()) {\n \t\t\tBufferedReader ar = new BufferedReader(new FileReader(altFile));\n-\t\t\tfor (String alt=ar.readLine(); alt!=null; alt=ar.readLine()) {\n+\t\t\tfor (String alt = ar.readLine(); alt != null; alt = ar.readLine()) {\n \t\t\t\treadObjectsDirs(FS.resolve(objectsDir, alt), ret);\n \t\t\t}\n \t\t\tar.close();\n@@ -151,7 +154,7 @@ public class Repository {\n \t/**\n \t * Create a new Git repository initializing the necessary files and\n \t * directories.\n-\t *\n+\t * \n \t * @throws IOException\n \t */\n \tpublic void create() throws IOException {\n@@ -213,15 +216,15 @@ public class Repository {\n \t * to the alternative repo will be returned. If the object is not yet store\n \t * a usable path in this repo will be returned. It is assumed that callers\n \t * will look for objects in a pack first.\n-\t *\n+\t * \n \t * @param objectId\n \t * @return suggested file name\n \t */\n \tpublic File toFile(final AnyObjectId objectId) {\n \t\tfinal String n = objectId.toString();\n-\t\tString d=n.substring(0, 2);\n-\t\tString f=n.substring(2);\n-\t\tfor (int i=0; i<objectsDirs.length; ++i) {\n+\t\tString d = n.substring(0, 2);\n+\t\tString f = n.substring(2);\n+\t\tfor (int i = 0; i < objectsDirs.length; ++i) {\n \t\t\tFile ret = new File(new File(objectsDirs[i], d), f);\n \t\t\tif (ret.exists())\n \t\t\t\treturn ret;\n@@ -253,9 +256,8 @@ public class Repository {\n \t *         object, or null if the object does not exist.\n \t * @throws IOException\n \t */\n-\tpublic ObjectLoader openObject(final AnyObjectId id)\n-\t\t\tthrows IOException {\n-\t\treturn openObject(new WindowCursor(),id);\n+\tpublic ObjectLoader openObject(final AnyObjectId id) throws IOException {\n+\t\treturn openObject(new WindowCursor(), id);\n \t}\n \n \t/**\n@@ -281,7 +283,8 @@ public class Repository {\n \t\t\t\t\t// This shouldn't happen unless the pack was corrupted\n \t\t\t\t\t// after we opened it or the VM runs out of memory. This is\n \t\t\t\t\t// a know problem with memory mapped I/O in java and have\n-\t\t\t\t\t// been noticed with JDK < 1.6. Tell the gc that now is a good\n+\t\t\t\t\t// been noticed with JDK < 1.6. Tell the gc that now is a\n+\t\t\t\t\t// good\n \t\t\t\t\t// time to collect and try once more.\n \t\t\t\t\ttry {\n \t\t\t\t\t\tcurs.release();\n@@ -327,14 +330,16 @@ public class Repository {\n \t}\n \n \t/**\n-\t * Access a Commit object using a symbolic reference. This reference may\n-\t * be a SHA-1 or ref in combination with a number of symbols translating\n-\t * from one ref or SHA1-1 to another, such as HEAD^ etc.\n-\t *\n-\t * @param revstr a reference to a git commit object\n+\t * Access a Commit object using a symbolic reference. This reference may be\n+\t * a SHA-1 or ref in combination with a number of symbols translating from\n+\t * one ref or SHA1-1 to another, such as HEAD^ etc.\n+\t * \n+\t * @param revstr\n+\t *            a reference to a git commit object\n \t * @return a Commit named by the specified string\n-\t * @throws IOException for I/O error or unexpected object type.\n-\t *\n+\t * @throws IOException\n+\t *             for I/O error or unexpected object type.\n+\t * \n \t * @see #resolve(String)\n \t */\n \tpublic Commit mapCommit(final String revstr) throws IOException {\n@@ -344,14 +349,16 @@ public class Repository {\n \n \t/**\n \t * Access any type of Git object by id and\n-\t *\n+\t * \n \t * @param id\n \t *            SHA-1 of object to read\n-\t * @param refName optional, only relevant for simple tags\n+\t * @param refName\n+\t *            optional, only relevant for simple tags\n \t * @return The Git object if found or null\n \t * @throws IOException\n \t */\n-\tpublic Object mapObject(final ObjectId id, final String refName) throws IOException {\n+\tpublic Object mapObject(final ObjectId id, final String refName)\n+\t\t\tthrows IOException {\n \t\tfinal ObjectLoader or = openObject(id);\n \t\tfinal byte[] raw = or.getBytes();\n \t\tif (or.getType() == Constants.OBJ_TREE)\n@@ -367,9 +374,11 @@ public class Repository {\n \n \t/**\n \t * Access a Commit by SHA'1 id.\n+\t * \n \t * @param id\n \t * @return Commit or null\n-\t * @throws IOException for I/O error or unexpected object type.\n+\t * @throws IOException\n+\t *             for I/O error or unexpected object type.\n \t */\n \tpublic Commit mapCommit(final ObjectId id) throws IOException {\n \t\tfinal ObjectLoader or = openObject(id);\n@@ -387,14 +396,15 @@ public class Repository {\n \t}\n \n \t/**\n-\t * Access a Tree object using a symbolic reference. This reference may\n-\t * be a SHA-1 or ref in combination with a number of symbols translating\n-\t * from one ref or SHA1-1 to another, such as HEAD^{tree} etc.\n-\t *\n-\t * @param revstr a reference to a git commit object\n+\t * Access a Tree object using a symbolic reference. This reference may be a\n+\t * SHA-1 or ref in combination with a number of symbols translating from one\n+\t * ref or SHA1-1 to another, such as HEAD^{tree} etc.\n+\t * \n+\t * @param revstr\n+\t *            a reference to a git commit object\n \t * @return a Tree named by the specified string\n \t * @throws IOException\n-\t *\n+\t * \n \t * @see #resolve(String)\n \t */\n \tpublic Tree mapTree(final String revstr) throws IOException {\n@@ -404,9 +414,11 @@ public class Repository {\n \n \t/**\n \t * Access a Tree by SHA'1 id.\n+\t * \n \t * @param id\n \t * @return Tree or null\n-\t * @throws IOException for I/O error or unexpected object type.\n+\t * @throws IOException\n+\t *             for I/O error or unexpected object type.\n \t */\n \tpublic Tree mapTree(final ObjectId id) throws IOException {\n \t\tfinal ObjectLoader or = openObject(id);\n@@ -421,22 +433,25 @@ public class Repository {\n \t\tthrow new IncorrectObjectTypeException(id, Constants.TYPE_TREE);\n \t}\n \n-\tprivate Tree makeTree(final ObjectId id, final byte[] raw) throws IOException {\n+\tprivate Tree makeTree(final ObjectId id, final byte[] raw)\n+\t\t\tthrows IOException {\n \t\tTree ret = new Tree(this, id, raw);\n \t\treturn ret;\n \t}\n \n-\tprivate Tag makeTag(final ObjectId id, final String refName, final byte[] raw) {\n+\tprivate Tag makeTag(final ObjectId id, final String refName,\n+\t\t\tfinal byte[] raw) {\n \t\tTag ret = new Tag(this, id, refName, raw);\n \t\treturn ret;\n \t}\n \n \t/**\n \t * Access a tag by symbolic name.\n-\t *\n+\t * \n \t * @param revstr\n \t * @return a Tag or null\n-\t * @throws IOException on I/O error or unexpected type\n+\t * @throws IOException\n+\t *             on I/O error or unexpected type\n \t */\n \tpublic Tag mapTag(String revstr) throws IOException {\n \t\tfinal ObjectId id = resolve(revstr);\n@@ -445,12 +460,15 @@ public class Repository {\n \n \t/**\n \t * Access a Tag by SHA'1 id\n+\t * \n \t * @param refName\n \t * @param id\n \t * @return Commit or null\n-\t * @throws IOException for I/O error or unexpected object type.\n+\t * @throws IOException\n+\t *             for I/O error or unexpected object type.\n \t */\n-\tpublic Tag mapTag(final String refName, final ObjectId id) throws IOException {\n+\tpublic Tag mapTag(final String refName, final ObjectId id)\n+\t\t\tthrows IOException {\n \t\tfinal ObjectLoader or = openObject(id);\n \t\tif (or == null)\n \t\t\treturn null;\n@@ -462,8 +480,9 @@ public class Repository {\n \n \t/**\n \t * Get a locked handle to a ref suitable for updating or creating.\n-\t *\n-\t * @param ref name to lock\n+\t * \n+\t * @param ref\n+\t *            name to lock\n \t * @return a locked ref\n \t * @throws IOException\n \t */\n@@ -492,27 +511,29 @@ public class Repository {\n \n \t/**\n \t * Parse a git revision string and return an object id.\n-\t *\n+\t * \n \t * Currently supported is combinations of these.\n \t * <ul>\n-\t *  <li>SHA-1 - a SHA-1</li>\n-\t *  <li>refs/... - a ref name</li>\n-\t *  <li>ref^n - nth parent reference</li>\n-\t *  <li>ref~n - distance via parent reference</li>\n-\t *  <li>ref@{n} - nth version of ref</li>\n-\t *  <li>ref^{tree} - tree references by ref</li>\n-\t *  <li>ref^{commit} - commit references by ref</li>\n+\t * <li>SHA-1 - a SHA-1</li>\n+\t * <li>refs/... - a ref name</li>\n+\t * <li>ref^n - nth parent reference</li>\n+\t * <li>ref~n - distance via parent reference</li>\n+\t * <li>ref@{n} - nth version of ref</li>\n+\t * <li>ref^{tree} - tree references by ref</li>\n+\t * <li>ref^{commit} - commit references by ref</li>\n \t * </ul>\n-\t *\n+\t * \n \t * Not supported is\n \t * <ul>\n \t * <li>timestamps in reflogs, ref@{full or relative timestamp}</li>\n \t * <li>abbreviated SHA-1's</li>\n \t * </ul>\n-\t *\n-\t * @param revstr A git object references expression\n+\t * \n+\t * @param revstr\n+\t *            A git object references expression\n \t * @return an ObjectId\n-\t * @throws IOException on serious errors\n+\t * @throws IOException\n+\t *             on serious errors\n \t */\n \tpublic ObjectId resolve(final String revstr) throws IOException {\n \t\tchar[] rev = revstr.toCharArray();\n@@ -522,7 +543,7 @@ public class Repository {\n \t\t\tswitch (rev[i]) {\n \t\t\tcase '^':\n \t\t\t\tif (refId == null) {\n-\t\t\t\t\tString refstr = new String(rev,0,i);\n+\t\t\t\t\tString refstr = new String(rev, 0, i);\n \t\t\t\t\trefId = resolveSimple(refstr);\n \t\t\t\t\tif (refId == null)\n \t\t\t\t\t\treturn null;\n@@ -542,23 +563,24 @@ public class Repository {\n \t\t\t\t\t\tint j;\n \t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\tif (!(ref instanceof Commit))\n-\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId, Constants.TYPE_COMMIT);\n-\t\t\t\t\t\tfor (j=i+1; j<rev.length; ++j) {\n+\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,\n+\t\t\t\t\t\t\t\t\tConstants.TYPE_COMMIT);\n+\t\t\t\t\t\tfor (j = i + 1; j < rev.length; ++j) {\n \t\t\t\t\t\t\tif (!Character.isDigit(rev[j]))\n \t\t\t\t\t\t\t\tbreak;\n \t\t\t\t\t\t}\n-\t\t\t\t\t\tString parentnum = new String(rev, i+1, j-i-1);\n+\t\t\t\t\t\tString parentnum = new String(rev, i + 1, j - i - 1);\n \t\t\t\t\t\tint pnum = Integer.parseInt(parentnum);\n \t\t\t\t\t\tif (pnum != 0)\n-\t\t\t\t\t\t\trefId = ((Commit)ref).getParentIds()[pnum - 1];\n+\t\t\t\t\t\t\trefId = ((Commit) ref).getParentIds()[pnum - 1];\n \t\t\t\t\t\ti = j - 1;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\tcase '{':\n \t\t\t\t\t\tint k;\n \t\t\t\t\t\tString item = null;\n-\t\t\t\t\t\tfor (k=i+2; k<rev.length; ++k) {\n+\t\t\t\t\t\tfor (k = i + 2; k < rev.length; ++k) {\n \t\t\t\t\t\t\tif (rev[k] == '}') {\n-\t\t\t\t\t\t\t\titem = new String(rev, i+2, k-i-2);\n+\t\t\t\t\t\t\t\titem = new String(rev, i + 2, k - i - 2);\n \t\t\t\t\t\t\t\tbreak;\n \t\t\t\t\t\t\t}\n \t\t\t\t\t\t}\n@@ -567,44 +589,43 @@ public class Repository {\n \t\t\t\t\t\t\tif (item.equals(\"tree\")) {\n \t\t\t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\t\t\twhile (ref instanceof Tag) {\n-\t\t\t\t\t\t\t\t\tTag t = (Tag)ref;\n+\t\t\t\t\t\t\t\t\tTag t = (Tag) ref;\n \t\t\t\t\t\t\t\t\trefId = t.getObjId();\n \t\t\t\t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\t\t\t}\n \t\t\t\t\t\t\t\tif (ref instanceof Treeish)\n-\t\t\t\t\t\t\t\t\trefId = ((Treeish)ref).getTreeId();\n+\t\t\t\t\t\t\t\t\trefId = ((Treeish) ref).getTreeId();\n \t\t\t\t\t\t\t\telse\n-\t\t\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,  Constants.TYPE_TREE);\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t\telse if (item.equals(\"commit\")) {\n+\t\t\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(\n+\t\t\t\t\t\t\t\t\t\t\trefId, Constants.TYPE_TREE);\n+\t\t\t\t\t\t\t} else if (item.equals(\"commit\")) {\n \t\t\t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\t\t\twhile (ref instanceof Tag) {\n-\t\t\t\t\t\t\t\t\tTag t = (Tag)ref;\n+\t\t\t\t\t\t\t\t\tTag t = (Tag) ref;\n \t\t\t\t\t\t\t\t\trefId = t.getObjId();\n \t\t\t\t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\t\t\t}\n \t\t\t\t\t\t\t\tif (!(ref instanceof Commit))\n-\t\t\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,  Constants.TYPE_COMMIT);\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t\telse if (item.equals(\"blob\")) {\n+\t\t\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(\n+\t\t\t\t\t\t\t\t\t\t\trefId, Constants.TYPE_COMMIT);\n+\t\t\t\t\t\t\t} else if (item.equals(\"blob\")) {\n \t\t\t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\t\t\twhile (ref instanceof Tag) {\n-\t\t\t\t\t\t\t\t\tTag t = (Tag)ref;\n+\t\t\t\t\t\t\t\t\tTag t = (Tag) ref;\n \t\t\t\t\t\t\t\t\trefId = t.getObjId();\n \t\t\t\t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\t\t\t}\n \t\t\t\t\t\t\t\tif (!(ref instanceof byte[]))\n-\t\t\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,  Constants.TYPE_COMMIT);\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t\telse if (item.equals(\"\")) {\n+\t\t\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(\n+\t\t\t\t\t\t\t\t\t\t\trefId, Constants.TYPE_COMMIT);\n+\t\t\t\t\t\t\t} else if (item.equals(\"\")) {\n \t\t\t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\t\t\tif (ref instanceof Tag)\n-\t\t\t\t\t\t\t\t\trefId = ((Tag)ref).getObjId();\n+\t\t\t\t\t\t\t\t\trefId = ((Tag) ref).getObjId();\n \t\t\t\t\t\t\t\telse {\n \t\t\t\t\t\t\t\t\t// self\n \t\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t\telse\n+\t\t\t\t\t\t\t} else\n \t\t\t\t\t\t\t\tthrow new RevisionSyntaxException(revstr);\n \t\t\t\t\t\telse\n \t\t\t\t\t\t\tthrow new RevisionSyntaxException(revstr);\n@@ -612,22 +633,24 @@ public class Repository {\n \t\t\t\t\tdefault:\n \t\t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\t\tif (ref instanceof Commit)\n-\t\t\t\t\t\t\trefId = ((Commit)ref).getParentIds()[0];\n+\t\t\t\t\t\t\trefId = ((Commit) ref).getParentIds()[0];\n \t\t\t\t\t\telse\n-\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,  Constants.TYPE_COMMIT);\n-\t\t\t\t\t\t\n+\t\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,\n+\t\t\t\t\t\t\t\t\tConstants.TYPE_COMMIT);\n+\n \t\t\t\t\t}\n \t\t\t\t} else {\n \t\t\t\t\tref = mapObject(refId, null);\n \t\t\t\t\tif (ref instanceof Commit)\n-\t\t\t\t\t\trefId = ((Commit)ref).getParentIds()[0];\n+\t\t\t\t\t\trefId = ((Commit) ref).getParentIds()[0];\n \t\t\t\t\telse\n-\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,  Constants.TYPE_COMMIT);\n+\t\t\t\t\t\tthrow new IncorrectObjectTypeException(refId,\n+\t\t\t\t\t\t\t\tConstants.TYPE_COMMIT);\n \t\t\t\t}\n \t\t\t\tbreak;\n \t\t\tcase '~':\n \t\t\t\tif (ref == null) {\n-\t\t\t\t\tString refstr = new String(rev,0,i);\n+\t\t\t\t\tString refstr = new String(rev, 0, i);\n \t\t\t\t\trefId = resolveSimple(refstr);\n \t\t\t\t\tref = mapCommit(refId);\n \t\t\t\t}\n@@ -636,10 +659,10 @@ public class Repository {\n \t\t\t\t\tif (!Character.isDigit(rev[l]))\n \t\t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\tString distnum = new String(rev, i+1, l-i-1);\n+\t\t\t\tString distnum = new String(rev, i + 1, l - i - 1);\n \t\t\t\tint dist = Integer.parseInt(distnum);\n \t\t\t\twhile (dist >= 0) {\n-\t\t\t\t\trefId = ((Commit)ref).getParentIds()[0];\n+\t\t\t\t\trefId = ((Commit) ref).getParentIds()[0];\n \t\t\t\t\tref = mapCommit(refId);\n \t\t\t\t\t--dist;\n \t\t\t\t}\n@@ -648,14 +671,16 @@ public class Repository {\n \t\t\tcase '@':\n \t\t\t\tint m;\n \t\t\t\tString time = null;\n-\t\t\t\tfor (m=i+2; m<rev.length; ++m) {\n+\t\t\t\tfor (m = i + 2; m < rev.length; ++m) {\n \t\t\t\t\tif (rev[m] == '}') {\n-\t\t\t\t\t\ttime = new String(rev, i+2, m-i-2);\n+\t\t\t\t\t\ttime = new String(rev, i + 2, m - i - 2);\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tif (time != null)\n-\t\t\t\t\tthrow new RevisionSyntaxException(\"reflogs not yet supported by revision parser yet\", revstr);\n+\t\t\t\t\tthrow new RevisionSyntaxException(\n+\t\t\t\t\t\t\t\"reflogs not yet supported by revision parser yet\",\n+\t\t\t\t\t\t\trevstr);\n \t\t\t\ti = m - 1;\n \t\t\t\tbreak;\n \t\t\tdefault:\n@@ -707,10 +732,10 @@ public class Repository {\n \t\tfinal String p = pack.getName();\n \t\tfinal String i = idx.getName();\n \t\tif (p.length() != 50 || !p.startsWith(\"pack-\") || !p.endsWith(\".pack\"))\n-\t\t    throw new IllegalArgumentException(\"Not a valid pack \" + pack);\n+\t\t\tthrow new IllegalArgumentException(\"Not a valid pack \" + pack);\n \t\tif (i.length() != 49 || !i.startsWith(\"pack-\") || !i.endsWith(\".idx\"))\n-\t\t    throw new IllegalArgumentException(\"Not a valid pack \" + idx);\n-\t\tif (!p.substring(0,45).equals(i.substring(0,45)))\n+\t\t\tthrow new IllegalArgumentException(\"Not a valid pack \" + idx);\n+\t\tif (!p.substring(0, 45).equals(i.substring(0, 45)))\n \t\t\tthrow new IllegalArgumentException(\"Pack \" + pack\n \t\t\t\t\t+ \"does not match index \" + idx);\n \n@@ -722,12 +747,11 @@ public class Repository {\n \t}\n \n \t/**\n-\t * Scan the object dirs, including alternates for packs\n-\t * to use.\n+\t * Scan the object dirs, including alternates for packs to use.\n \t */\n \tpublic void scanForPacks() {\n \t\tfinal ArrayList<PackFile> p = new ArrayList<PackFile>();\n-\t\tfor (int i=0; i<objectsDirs.length; ++i)\n+\t\tfor (int i = 0; i < objectsDirs.length; ++i)\n \t\t\tscanForPacks(new File(objectsDirs[i], \"pack\"), p);\n \t\tfinal PackFile[] arr = new PackFile[p.size()];\n \t\tp.toArray(arr);\n@@ -758,14 +782,16 @@ public class Repository {\n \t\t}\n \t}\n \n-    /**\n-     * Writes a symref (e.g. HEAD) to disk\n-     *\n-     * @param name symref name\n-     * @param target pointed to ref\n-     * @throws IOException\n-     */\n-    public void writeSymref(final String name, final String target)\n+\t/**\n+\t * Writes a symref (e.g. HEAD) to disk\n+\t * \n+\t * @param name\n+\t *            symref name\n+\t * @param target\n+\t *            pointed to ref\n+\t * @throws IOException\n+\t */\n+\tpublic void writeSymref(final String name, final String target)\n \t\t\tthrows IOException {\n \t\tfinal byte[] content = (\"ref: \" + target + \"\\n\").getBytes(\"UTF-8\");\n \t\tfinal LockFile lck = new LockFile(fileForRef(name));\n@@ -802,7 +828,7 @@ public class Repository {\n \t\t\t\tObjectId id = packedRefs.get(name);\n \t\t\t\tif (id != null)\n \t\t\t\t\treturn new Ref(name, id);\n-\t\t\t\t\n+\n \t\t\t\t// no packed ref found, return blank one\n \t\t\t\treturn new Ref(name, null);\n \t\t\t}\n@@ -840,12 +866,13 @@ public class Repository {\n \t * @throws IOException\n \t */\n \tpublic String getPatch() throws IOException {\n-\t\tfinal File ptr = new File(getDirectory(),\"patches/\"+getBranch()+\"/applied\");\n+\t\tfinal File ptr = new File(getDirectory(), \"patches/\" + getBranch()\n+\t\t\t\t+ \"/applied\");\n \t\tfinal BufferedReader br = new BufferedReader(new FileReader(ptr));\n-\t\tString last=null;\n+\t\tString last = null;\n \t\ttry {\n \t\t\tString line;\n-\t\t\twhile ((line=br.readLine())!=null) {\n+\t\t\twhile ((line = br.readLine()) != null) {\n \t\t\t\tlast = line;\n \t\t\t}\n \t\t} finally {\n@@ -859,7 +886,7 @@ public class Repository {\n \t * @throws IOException\n \t */\n \tpublic String getFullBranch() throws IOException {\n-\t\tfinal File ptr = new File(getDirectory(),\"HEAD\");\n+\t\tfinal File ptr = new File(getDirectory(), \"HEAD\");\n \t\tfinal BufferedReader br = new BufferedReader(new FileReader(ptr));\n \t\tString ref;\n \t\ttry {\n@@ -871,7 +898,7 @@ public class Repository {\n \t\t\tref = ref.substring(5);\n \t\treturn ref;\n \t}\n-\t\n+\n \t/**\n \t * @return name of current branch.\n \t * @throws IOException\n@@ -892,7 +919,7 @@ public class Repository {\n \t\t\t\tref = ref.substring(11);\n \t\t\treturn ref;\n \t\t} catch (FileNotFoundException e) {\n-\t\t\tfinal File ptr = new File(getDirectory(),\"head-name\");\n+\t\t\tfinal File ptr = new File(getDirectory(), \"head-name\");\n \t\t\tfinal BufferedReader br = new BufferedReader(new FileReader(ptr));\n \t\t\tString ref;\n \t\t\ttry {\n@@ -910,25 +937,27 @@ public class Repository {\n \tpublic Collection<String> getBranches() {\n \t\treturn listRefs(\"heads\");\n \t}\n-\t\n+\n \t/**\n \t * @return the names of all refs (local and remotes branches, tags)\n \t */\n \tpublic Collection<String> getAllRefs() {\n \t\treturn listRefs(\"\");\n \t}\n-\t\n+\n \tprivate Collection<String> listRefs(String refSubDir) {\n \t\t// add / to end, unless empty\n-\t\tif (refSubDir.length() > 0 && refSubDir.charAt(refSubDir.length() -1 ) != '/')\n+\t\tif (refSubDir.length() > 0\n+\t\t\t\t&& refSubDir.charAt(refSubDir.length() - 1) != '/')\n \t\t\trefSubDir += \"/\";\n-\t\t\n-\t\tCollection<String> branchesRaw = listFilesRecursively(new File(refsDir, refSubDir), null);\n+\n+\t\tCollection<String> branchesRaw = listFilesRecursively(new File(refsDir,\n+\t\t\t\trefSubDir), null);\n \t\tArrayList<String> branches = new ArrayList<String>();\n \t\tfor (String b : branchesRaw) {\n \t\t\tbranches.add(\"refs/\" + refSubDir + b);\n \t\t}\n-\t\t\n+\n \t\trefreshPackedRefsCache();\n \t\tSet<String> keySet = packedRefs.keySet();\n \t\tfor (String s : keySet)\n@@ -944,22 +973,23 @@ public class Repository {\n \t\treturn listRefs(\"tags\");\n \t}\n \n-\tprivate Map<String,ObjectId> packedRefs = new HashMap<String,ObjectId>();\n+\tprivate Map<String, ObjectId> packedRefs = new HashMap<String, ObjectId>();\n+\n \tprivate long packedrefstime = 0;\n \n \tprivate void refreshPackedRefsCache() {\n \t\tif (!packedRefsFile.exists()) {\n \t\t\tif (packedRefs.size() > 0)\n-\t\t\t\tpackedRefs = new HashMap<String,ObjectId>();\n+\t\t\t\tpackedRefs = new HashMap<String, ObjectId>();\n \t\t\treturn;\n \t\t}\n \t\tif (packedRefsFile.lastModified() == packedrefstime)\n \t\t\treturn;\n-\t\tMap<String,ObjectId> newPackedRefs = new HashMap<String,ObjectId>();\n+\t\tMap<String, ObjectId> newPackedRefs = new HashMap<String, ObjectId>();\n \t\tFileReader fileReader = null;\n \t\ttry {\n \t\t\tfileReader = new FileReader(packedRefsFile);\n-\t\t\tBufferedReader b=new BufferedReader(fileReader);\n+\t\t\tBufferedReader b = new BufferedReader(fileReader);\n \t\t\tString p;\n \t\t\twhile ((p = b.readLine()) != null) {\n \t\t\t\tif (p.charAt(0) == '#')\n@@ -968,12 +998,12 @@ public class Repository {\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n \t\t\t\tint spos = p.indexOf(' ');\n-\t\t\t\tObjectId id = ObjectId.fromString(p.substring(0,spos));\n-\t\t\t\tString name = p.substring(spos+1);\n+\t\t\t\tObjectId id = ObjectId.fromString(p.substring(0, spos));\n+\t\t\t\tString name = p.substring(spos + 1);\n \t\t\t\tnewPackedRefs.put(name, id);\n \t\t\t}\n \t\t} catch (IOException e) {\n-\t\t\tthrow new Error(\"Cannot read packed refs\",e);\n+\t\t\tthrow new Error(\"Cannot read packed refs\", e);\n \t\t} finally {\n \t\t\tif (fileReader != null) {\n \t\t\t\ttry {\n@@ -1016,13 +1046,17 @@ public class Repository {\n \t * @return applied patches in a map indexed on current commit id\n \t * @throws IOException\n \t */\n-\tpublic Map<ObjectId,StGitPatch> getAppliedPatches() throws IOException {\n-\t\tMap<ObjectId,StGitPatch> ret = new HashMap<ObjectId,StGitPatch>();\n+\tpublic Map<ObjectId, StGitPatch> getAppliedPatches() throws IOException {\n+\t\tMap<ObjectId, StGitPatch> ret = new HashMap<ObjectId, StGitPatch>();\n \t\tif (isStGitMode()) {\n-\t\t\tFile patchDir = new File(new File(getDirectory(),\"patches\"),getBranch());\n-\t\t\tBufferedReader apr = new BufferedReader(new FileReader(new File(patchDir,\"applied\")));\n-\t\t\tfor (String patchName=apr.readLine(); patchName!=null; patchName=apr.readLine()) {\n-\t\t\t\tFile topFile = new File(new File(new File(patchDir,\"patches\"), patchName), \"top\");\n+\t\t\tFile patchDir = new File(new File(getDirectory(), \"patches\"),\n+\t\t\t\t\tgetBranch());\n+\t\t\tBufferedReader apr = new BufferedReader(new FileReader(new File(\n+\t\t\t\t\tpatchDir, \"applied\")));\n+\t\t\tfor (String patchName = apr.readLine(); patchName != null; patchName = apr\n+\t\t\t\t\t.readLine()) {\n+\t\t\t\tFile topFile = new File(new File(new File(patchDir, \"patches\"),\n+\t\t\t\t\t\tpatchName), \"top\");\n \t\t\t\tBufferedReader tfr = new BufferedReader(new FileReader(topFile));\n \t\t\t\tString objectId = tfr.readLine();\n \t\t\t\tObjectId id = ObjectId.fromString(objectId);\n@@ -1052,7 +1086,7 @@ public class Repository {\n \t\t}\n \t\treturn ret;\n \t}\n-\t\n+\n \t/** Clean up stale caches */\n \tpublic void refreshFromDisk() {\n \t\tpackedRefs = null;\n@@ -1075,7 +1109,7 @@ public class Repository {\n \tstatic byte[] gitInternalSlash(byte[] bytes) {\n \t\tif (File.separatorChar == '/')\n \t\t\treturn bytes;\n-\t\tfor (int i=0; i<bytes.length; ++i)\n+\t\tfor (int i = 0; i < bytes.length; ++i)\n \t\t\tif (bytes[i] == File.separatorChar)\n \t\t\t\tbytes[i] = '/';\n \t\treturn bytes;\n@@ -1087,32 +1121,32 @@ public class Repository {\n \tpublic RepositoryState getRepositoryState() {\n \t\tif (new File(getWorkDir(), \".dotest\").exists())\n \t\t\treturn RepositoryState.REBASING;\n-\t\tif (new File(gitDir,\".dotest-merge\").exists())\n+\t\tif (new File(gitDir, \".dotest-merge\").exists())\n \t\t\treturn RepositoryState.REBASING_INTERACTIVE;\n-\t\tif (new File(gitDir,\"MERGE_HEAD\").exists())\n+\t\tif (new File(gitDir, \"MERGE_HEAD\").exists())\n \t\t\treturn RepositoryState.MERGING;\n-\t\tif (new File(gitDir,\"BISECT_LOG\").exists())\n+\t\tif (new File(gitDir, \"BISECT_LOG\").exists())\n \t\t\treturn RepositoryState.BISECTING;\n \t\treturn RepositoryState.SAFE;\n \t}\n \n \t/**\n-\t * Check validty of a ref name. It must not contain character that has\n-\t * a special meaning in a Git object reference expression. Some other\n+\t * Check validty of a ref name. It must not contain character that has a\n+\t * special meaning in a Git object reference expression. Some other\n \t * dangerous characters are also excluded.\n-\t *\n+\t * \n \t * @param refName\n-\t *\n+\t * \n \t * @return true if refName is a valid ref name\n \t */\n \tpublic static boolean isValidRefName(final String refName) {\n \t\tfinal int len = refName.length();\n \t\tchar p = '\\0';\n-\t\tfor (int i=0; i<len; ++i) {\n+\t\tfor (int i = 0; i < len; ++i) {\n \t\t\tchar c = refName.charAt(i);\n \t\t\tif (c <= ' ')\n \t\t\t\treturn false;\n-\t\t\tswitch(c) {\n+\t\t\tswitch (c) {\n \t\t\tcase '.':\n \t\t\t\tif (i == 0)\n \t\t\t\t\treturn false;\n@@ -1124,11 +1158,14 @@ public class Repository {\n \t\t\tcase '/':\n \t\t\t\tif (i == 0)\n \t\t\t\t\treturn false;\n-\t\t\t\tif (i == len -1)\n+\t\t\t\tif (i == len - 1)\n \t\t\t\t\treturn false;\n \t\t\t\tbreak;\n-\t\t\tcase '~': case '^': case ':':\n-\t\t\tcase '?': case '[':\n+\t\t\tcase '~':\n+\t\t\tcase '^':\n+\t\t\tcase ':':\n+\t\t\tcase '?':\n+\t\t\tcase '[':\n \t\t\t\treturn false;\n \t\t\tcase '*':\n \t\t\t\treturn false;\n@@ -1140,9 +1177,11 @@ public class Repository {\n \n \t/**\n \t * String work dir and return normalized repository path\n-\t *\n-\t * @param wd Work dir\n-\t * @param f File whose path shall be stripp off it's workdir\n+\t * \n+\t * @param wd\n+\t *            Work dir\n+\t * @param f\n+\t *            File whose path shall be stripp off it's workdir\n \t * @return normalized repository relative path\n \t */\n \tpublic static String stripWorkDir(File wd, File f) {\n-- \n1.5.4.3\n"},{"id":"77583","messageId":"1211574872-23676-23-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 22/23] Added findWorkTree method to Repository class.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:31Z","receivedAt":"2008-05-23T20:34:31Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../src/org/spearce/jgit/lib/Repository.java       |   80 ++++++++++++++++++++\n 1 files changed, 80 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\nindex 06e686f..71e0e04 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n@@ -16,6 +16,11 @@\n  */\n package org.spearce.jgit.lib;\n \n+import static org.spearce.jgit.lib.Constants.HEAD;\n+import static org.spearce.jgit.lib.Constants.OBJECTS_DIRECTORY_NAME;\n+import static org.spearce.jgit.lib.Constants.REFS_DIRECTORY_NAME;\n+import static org.spearce.jgit.lib.Constants.REPOSITORY_DIRECTORY_NAME;\n+\n import java.io.BufferedReader;\n import java.io.File;\n import java.io.FileNotFoundException;\n@@ -29,6 +34,7 @@ import java.util.Map;\n import java.util.Set;\n \n import org.spearce.jgit.errors.IncorrectObjectTypeException;\n+import org.spearce.jgit.errors.NoGitRepositoryFoundException;\n import org.spearce.jgit.errors.ObjectWritingException;\n import org.spearce.jgit.errors.RevisionSyntaxException;\n import org.spearce.jgit.stgit.StGitPatch;\n@@ -1253,4 +1259,78 @@ public class Repository {\n \t\t}\n \t}\n \n+\t/**\n+\t * Find the git repository for the current working directory.\n+\t * \n+\t * @return a {@link Repository}.\n+\t * @throws NoGitRepositoryFoundException\n+\t *             if no git repository could be found for the current\n+\t *             directory.\n+\t * @throws IOException\n+\t *             if not able to determine the absolute path of the current\n+\t *             working directory.\n+\t */\n+\tpublic static WorkTree findWorkTree() throws NoGitRepositoryFoundException,\n+\t\t\tIOException {\n+\t\treturn findWorkTree(new File(\".\"));\n+\t}\n+\n+\t/**\n+\t * Checks if a path is a valid git repository. Works similar like the method\n+\t * is_git_directory from the original setup.c file.\n+\t * \n+\t * @param directory\n+\t *            the path which should be checked.\n+\t * @return true if the path is a valid git repository.\n+\t */\n+\tprivate static boolean isRepository(File directory) {\n+\t\tif (!directory.isDirectory()) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tfinal File objectDirectory = new File(directory, OBJECTS_DIRECTORY_NAME);\n+\t\tif (!objectDirectory.isDirectory()) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tfinal File refsDirectory = new File(directory, REFS_DIRECTORY_NAME);\n+\t\tif (!refsDirectory.isDirectory()) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tfinal File head = new File(directory, HEAD);\n+\t\tif (!hasValidateHeadRef(head)) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\treturn true;\n+\t}\n+\n+\t/**\n+\t * Checks for example if a path is a valid HEAD file.\n+\t * \n+\t * @param path\n+\t *            is the path of the HEAD file.\n+\t * @return true if it has a valid head reference.\n+\t */\n+\tprivate static final boolean hasValidateHeadRef(File path) {\n+\t\treturn true; // TODO implement this method\n+\t}\n+\n+\tprivate static WorkTree findWorkTree(final File directory)\n+\t\t\tthrows IOException, NoGitRepositoryFoundException {\n+\t\tFile currentDirectory = directory.getAbsoluteFile();\n+\t\twhile (currentDirectory != null) {\n+\t\t\tfinal File commonGitDirectory = new File(directory,\n+\t\t\t\t\tREPOSITORY_DIRECTORY_NAME);\n+\t\t\tif (isRepository(commonGitDirectory))\n+\t\t\t\treturn new WorkTree(currentDirectory, new Repository(\n+\t\t\t\t\t\tcommonGitDirectory));\n+\t\t\tif (isRepository(currentDirectory))\n+\t\t\t\treturn new WorkTree(null, new Repository(currentDirectory));\n+\t\t\tcurrentDirectory = currentDirectory.getParentFile();\n+\t\t}\n+\t\tthrow new NoGitRepositoryFoundException(directory);\n+\t}\n+\n }\n-- \n1.5.4.3\n"},{"id":"77593","messageId":"1211574872-23676-24-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3 23/23] Added the test class AddCommandIterationTest.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-23T20:34:32Z","receivedAt":"2008-05-23T20:34:32Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../treewalk/rules/AddCommandIterationTest.java    |  321 ++++++++++++++++++++\n 1 files changed, 321 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java\nnew file mode 100644\nindex 0000000..a96c880\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java\n@@ -0,0 +1,321 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.io.PrintWriter;\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.Collections;\n+import java.util.HashSet;\n+import java.util.Iterator;\n+import java.util.List;\n+import java.util.NoSuchElementException;\n+import java.util.Set;\n+\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.errors.PathNotInProjectDirectoryException;\n+import org.spearce.jgit.lib.Repository;\n+import org.spearce.jgit.lib.WorkTree;\n+import org.spearce.jgit.treewalk.LightFileTreeIterable;\n+\n+public class AddCommandIterationTest extends TestCase {\n+\n+\tprivate WorkTree workTree;\n+\n+\tprivate AddRulesFactory factory;\n+\n+\tprivate Iterable<File> createIterable(File workingDirectory,\n+\t\t\tList<String> filePatternsOfAddCommand)\n+\t\t\tthrows PathNotInProjectDirectoryException, InvalidPatternException,\n+\t\t\tIOException {\n+\t\tfinal Rules rules = factory.createRules(workTree.getDirectory(),\n+\t\t\t\tworkingDirectory, filePatternsOfAddCommand);\n+\t\treturn new LightFileTreeIterable(workTree.getDirectory(), rules, false);\n+\t}\n+\n+\t@Override\n+\tprotected void setUp() throws Exception {\n+\t\tfinal File projectDirectory = File.createTempFile(\"test\", \"\");\n+\t\tprojectDirectory.delete();\n+\t\tprojectDirectory.mkdir();\n+\t\tprojectDirectory.deleteOnExit();\n+\t\tthis.workTree = Repository.createWorkTree(projectDirectory);\n+\t\tthis.factory = new AddRulesFactory();\n+\t}\n+\n+\tpublic void testNoPattern() throws Exception {\n+\t\tcreateFile(\"a.txt\");\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tCollections.<String> emptyList());\n+\t\tfinal Set<File> expectedPathes = Collections.emptySet();\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPathes, iterable);\n+\t}\n+\n+\tpublic void testTreePattern1() throws Exception {\n+\t\tfinal Set<File> expectedFiles = new HashSet<File>();\n+\t\tcreateFile(\"a.txt\");\n+\t\texpectedFiles.add(createFile(\"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(directoryA, Arrays\n+\t\t\t\t.asList(\"*.txt\"));\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedFiles, iterable);\n+\t}\n+\n+\tpublic void testTreePattern2() throws Exception {\n+\t\tfinal Set<File> expectedFiles = new HashSet<File>();\n+\t\tcreateFile(\"a.txt\");\n+\t\texpectedFiles.add(createFile(\"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tArrays.asList(\"a\" + File.separator + \"*.txt\"));\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedFiles, iterable);\n+\t}\n+\n+\tpublic void testSelectCompleteSubdirectory() throws Exception {\n+\t\tfinal Set<File> expectedPathes = new HashSet<File>();\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\t\tfinal File directoryAA = new File(directoryA, \"a\");\n+\t\tfinal File directoryAB = new File(directoryA, \"b\");\n+\t\tcreateFile(\"a.txt\");\n+\t\texpectedPathes.add(directoryA);\n+\t\texpectedPathes.add(directoryAA);\n+\t\texpectedPathes.add(createFile(\"a\", \"a.txt\"));\n+\t\texpectedPathes.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedPathes.add(directoryAB);\n+\t\texpectedPathes.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\texpectedPathes.add(createFile(\"a\", \"b\", \"a.c\"));\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tArrays.asList(\"a\"));\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPathes, iterable);\n+\t}\n+\n+\tpublic void testSelectTwoSubdirectories() throws Exception {\n+\t\tfinal Set<File> expectedPathes = new HashSet<File>();\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\t\tfinal File directoryAA = new File(directoryA, \"a\");\n+\t\tfinal File directoryAB = new File(directoryA, \"b\");\n+\t\tcreateFile(\"a.txt\");\n+\t\tcreateFile(\"a\", \"a.txt\");\n+\t\texpectedPathes.add(directoryAA);\n+\t\texpectedPathes.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedPathes.add(directoryAB);\n+\t\texpectedPathes.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\texpectedPathes.add(createFile(\"a\", \"b\", \"a.c\"));\n+\n+\t\tfinal List<String> patternList = new ArrayList<String>(2);\n+\t\tpatternList.add(\"a\" + File.separator + \"a\");\n+\t\tpatternList.add(\"a\" + File.separator + \"b\");\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tpatternList);\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPathes, iterable);\n+\t}\n+\n+\tpublic void testTwoDifferentSelects() throws Exception {\n+\t\tfinal Set<File> expectedPathes = new HashSet<File>();\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\t\tfinal File directoryAA = new File(directoryA, \"a\");\n+\t\tcreateFile(\"a.txt\");\n+\t\tcreateFile(\"a\", \"a.txt\");\n+\t\texpectedPathes.add(directoryAA);\n+\t\texpectedPathes.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedPathes.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\texpectedPathes.add(createFile(\"a\", \"b\", \"c\", \"a.txt\"));\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal List<String> patternList = new ArrayList<String>(2);\n+\t\tpatternList.add(\"a\" + File.separator + \"a\");\n+\t\tpatternList.add(\"a\" + File.separator + \"b\" + File.separator + \"*.txt\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tpatternList);\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPathes, iterable);\n+\t}\n+\n+\tpublic void testRealisticExample() throws Exception {\n+\t\tfinal Set<File> expectedPathes = new HashSet<File>();\n+\n+\t\t// write the .gitignore file\n+\t\tfinal File dotGitIgnoreFile = createFile(\".gitignore\");\n+\t\tfinal PrintWriter dotGitIgnoreFilePrinter = new PrintWriter(\n+\t\t\t\tdotGitIgnoreFile);\n+\t\ttry {\n+\t\t\tdotGitIgnoreFilePrinter.println(\"/alpha/config.xml\");\n+\t\t\tdotGitIgnoreFilePrinter.println(\"*.class\");\n+\t\t\tdotGitIgnoreFilePrinter.println(\"!/alpha/test/ressources/\");\n+\t\t\tdotGitIgnoreFilePrinter.println(\"*~\");\n+\t\t} finally {\n+\t\t\tdotGitIgnoreFilePrinter.close();\n+\t\t}\n+\n+\t\t// write the .git/info/exclude file\n+\t\tfinal File repositoryDirectory = workTree.getRepository()\n+\t\t\t\t.getDirectory();\n+\t\tfinal File infoDirectory = new File(repositoryDirectory, \"info\");\n+\t\tinfoDirectory.mkdir();\n+\t\tfinal File infoExcludeFile = new File(infoDirectory, \"exclude\");\n+\t\tfinal PrintWriter infoExcludeFilePrinter = new PrintWriter(\n+\t\t\t\tinfoExcludeFile);\n+\t\ttry {\n+\t\t\tinfoExcludeFilePrinter.println(\"/alpha/test/ressources/mytest.txt\");\n+\t\t} finally {\n+\t\t\tinfoExcludeFilePrinter.close();\n+\t\t}\n+\n+\t\tcreateFile(\"alpha\", \"config.xml\");\n+\t\texpectedPathes.add(createFile(\"alpha\", \"src\", \"Main.java\"));\n+\t\tcreateFile(\"alpha\", \"src\", \"Main.class\");\n+\t\texpectedPathes.add(createFile(\"alpha\", \"test\", \"ressources\",\n+\t\t\t\t\"Example.class\"));\n+\t\texpectedPathes.add(createFile(\"alpha\", \"test\", \"ressources\",\n+\t\t\t\t\"input.txt\"));\n+\t\tcreateFile(\"alpha\", \"test\", \"ressources\", \"input.txt~\");\n+\t\tcreateFile(\"alpha\", \"test\", \"ressources\", \"mytest.txt\");\n+\n+\t\tfinal File alphaDirectory = new File(workTree.getDirectory(), \"alpha\");\n+\t\tfinal File srcDirectory = new File(alphaDirectory, \"src\");\n+\t\tfinal File testDirectory = new File(alphaDirectory, \"test\");\n+\t\tfinal File ressources = new File(testDirectory, \"ressources\");\n+\n+\t\texpectedPathes.add(alphaDirectory);\n+\t\texpectedPathes.add(srcDirectory);\n+\t\texpectedPathes.add(testDirectory);\n+\t\texpectedPathes.add(ressources);\n+\n+\t\tfinal List<String> patternList = new ArrayList<String>(2);\n+\t\tpatternList.add(\"alpha\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tpatternList);\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPathes, iterable);\n+\t}\n+\n+\tpublic void testSingleFile() throws Exception {\n+\t\tcreateFile(\"a.txt\");\n+\t\tcreateFile(\"a\", \"a.txt\");\n+\t\tcreateFile(\"a\", \"a\", \"a.txt\");\n+\t\tfinal File expectedFile = createFile(\"a\", \"b\", \"a.txt\");\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal String pattern = \"a\" + File.separator + \"b\" + File.separator\n+\t\t\t\t+ \"a.txt\";\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tArrays.asList(pattern));\n+\t\tfinal Set<File> expectedPathes = Collections.singleton(expectedFile);\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPathes, iterable);\n+\t}\n+\n+\t/**\n+\t * Tests if the specified {@link Iterable} returns the specified set of\n+\t * {@link File}s. The assertion will fail if the {@link Iterable} returns\n+\t * to much, to less files. It will also fail if the {@link Iterable} returns\n+\t * a file twice.\n+\t * \n+\t * @param expectedContent\n+\t *            the expected set of files.\n+\t * @param iterable\n+\t *            the {@link Iterable} to test.\n+\t */\n+\tprivate void assertIterableReturnsSet(Set<File> expectedContent,\n+\t\t\tIterable<File> iterable) {\n+\t\tfinal Set<File> returnedFiles = new HashSet<File>();\n+\t\tfinal List<File> doubleReturnedFiles = new ArrayList<File>();\n+\n+\t\tfinal Iterator<File> iterator = iterable.iterator();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\tfinal File file = iterator.next();\n+\t\t\tif (!returnedFiles.add(file)) {\n+\t\t\t\tdoubleReturnedFiles.add(file);\n+\t\t\t}\n+\t\t}\n+\t\tfinal Set<File> missingFiles = new HashSet<File>();\n+\t\tfor (File file : expectedContent) {\n+\t\t\tif (!returnedFiles.contains(file)) {\n+\t\t\t\tmissingFiles.add(file);\n+\t\t\t}\n+\t\t}\n+\t\tif (!missingFiles.isEmpty()) {\n+\t\t\tfail(String.format(\"missing pathes: %s\", missingFiles));\n+\t\t}\n+\n+\t\tfinal Set<File> unexpectedFiles = new HashSet<File>();\n+\t\tfor (File file : returnedFiles) {\n+\t\t\tif (!expectedContent.contains(file)) {\n+\t\t\t\tunexpectedFiles.add(file);\n+\t\t\t}\n+\t\t}\n+\t\tif (!unexpectedFiles.isEmpty()) {\n+\t\t\tfail(String.format(\"unexpected pathes: %s\", unexpectedFiles));\n+\t\t}\n+\n+\t\tif (!doubleReturnedFiles.isEmpty()) {\n+\t\t\tfail(String.format(\"multiple times returned pathes: %s\",\n+\t\t\t\t\tdoubleReturnedFiles));\n+\t\t}\n+\n+\t}\n+\n+\tprivate static void assertIsValidIterable(Iterable<File> iterable) {\n+\t\tfinal Iterator<File> iterator = iterable.iterator();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\titerator.next();\n+\t\t}\n+\t\ttry {\n+\t\t\titerator.next();\n+\t\t\tfail();\n+\t\t} catch (NoSuchElementException e) {\n+\t\t\t// expected\n+\t\t}\n+\t}\n+\n+\tprivate File createFile(String... path) throws IOException {\n+\t\tFile file = workTree.getDirectory();\n+\t\tfor (int i = 0; i < path.length; i++) {\n+\t\t\tfile = new File(file, path[i]);\n+\t\t\tif (i == path.length - 1) {\n+\t\t\t\tfile.getParentFile().mkdirs();\n+\t\t\t\tfile.createNewFile();\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\treturn file;\n+\t}\n+}\n-- \n1.5.4.3\n"},{"id":"78211","messageId":"1212228236-8572-1-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-17-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3.1 16/23] Added the class LightFileTreeIterator and a test for it.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-31T10:03:56Z","receivedAt":"2008-05-31T10:03:56Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../jgit/treewalk/LightFileTreeIteratorTest.java   |  114 ++++++++++++++++++++\n .../jgit/treewalk/LightFileTreeIterator.java       |  112 +++++++++++++++++++\n 2 files changed, 226 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java\nnew file mode 100644\nindex 0000000..6febbdc\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/LightFileTreeIteratorTest.java\n@@ -0,0 +1,114 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk;\n+\n+import java.io.File;\n+import java.util.HashSet;\n+import java.util.Iterator;\n+import java.util.Set;\n+\n+import org.spearce.jgit.treewalk.rules.Rules;\n+\n+import junit.framework.TestCase;\n+\n+public class LightFileTreeIteratorTest extends TestCase {\n+\tprivate String DIRECTORY_A_NAME = \"a\";\n+\n+\tprivate String DIRECTORY_AB_NAME = \"b\";\n+\n+\tprivate File projectDirectory;\n+\n+\tprivate File fileB;\n+\n+\tprivate File directoryA;\n+\n+\tprivate File directoryAB;\n+\n+\tprivate File fileABA;\n+\n+\tprivate File directoryAC;\n+\n+\tprivate File fileACA;\n+\n+\tprivate File fileACB;\n+\n+\t@Override\n+\tprotected void setUp() throws Exception {\n+\t\tthis.projectDirectory = File.createTempFile(\"FileTreeIteratorTest\", \"\");\n+\t\tprojectDirectory.delete();\n+\t\tprojectDirectory.mkdir();\n+\t\tprojectDirectory.deleteOnExit();\n+\n+\t\tthis.directoryA = new File(projectDirectory, DIRECTORY_A_NAME);\n+\t\tdirectoryA.mkdir();\n+\n+\t\tthis.directoryAB = new File(directoryA, DIRECTORY_AB_NAME);\n+\t\tdirectoryAB.mkdir();\n+\n+\t\tthis.fileABA = new File(directoryAB, \"a.y\");\n+\t\tfileABA.createNewFile();\n+\n+\t\tthis.directoryAC = new File(directoryA, \"c\");\n+\t\tthis.directoryAC.mkdir();\n+\n+\t\tthis.fileACA = new File(directoryAC, \"a.x\");\n+\t\tfileACA.createNewFile();\n+\n+\t\tthis.fileACB = new File(directoryAC, \"b.y\");\n+\t\tfileACB.createNewFile();\n+\n+\t\tthis.fileB = new File(projectDirectory, \"b.x\");\n+\t\tfileB.createNewFile();\n+\t}\n+\n+\tpublic void testFileTreeIterator() {\n+\t\tfinal Iterator<File> iterator = new LightFileTreeIterator(\n+\t\t\t\tprojectDirectory, Rules.IGNORE_NOTHING, false);\n+\t\tfinal Set<File> actualPaths = new HashSet<File>();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\tfinal File next = iterator.next();\n+\t\t\tassertFalse(actualPaths.contains(next));\n+\t\t\tactualPaths.add(next);\n+\t\t}\n+\n+\t\tfinal Set<File> expectedPaths = new HashSet<File>();\n+\t\texpectedPaths.add(directoryA);\n+\t\texpectedPaths.add(fileB);\n+\t\texpectedPaths.add(directoryAB);\n+\t\texpectedPaths.add(fileABA);\n+\t\texpectedPaths.add(directoryAC);\n+\t\texpectedPaths.add(fileACA);\n+\t\texpectedPaths.add(fileACB);\n+\t\tassertEquals(expectedPaths, actualPaths);\n+\n+\t}\n+\n+\tpublic void testFileTreeIteratorWithIgnoreAllRules() {\n+\t\tfinal Iterator<File> iterator = new LightFileTreeIterator(\n+\t\t\t\tprojectDirectory, Rules.IGNORE_ALL, false);\n+\t\tfinal Set<File> actualPaths = new HashSet<File>();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\tfinal File next = iterator.next();\n+\t\t\tassertFalse(actualPaths.contains(next));\n+\t\t\tactualPaths.add(next);\n+\t\t}\n+\n+\t\tassertEquals(0, actualPaths.size());\n+\n+\t}\n+\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java\nnew file mode 100644\nindex 0000000..a3822cd\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/LightFileTreeIterator.java\n@@ -0,0 +1,112 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk;\n+\n+import java.io.File;\n+import java.util.EmptyStackException;\n+import java.util.Iterator;\n+import java.util.NoSuchElementException;\n+import java.util.Stack;\n+\n+import org.spearce.jgit.treewalk.rules.Rules;\n+\n+class LightFileTreeIterator implements Iterator<File> {\n+\tprivate final Stack<File> remainingPaths;\n+\n+\tprivate final Stack<Directory> remainingDirectories;\n+\n+\t/**\n+\t * Creates a new Iterator which allows to iterate over the content of the\n+\t * specified rootDirectory. The rootDirectory itself is never included.\n+\t * \n+\t * @param rootDirectory\n+\t *            the directory tree to iterate over.\n+\t * @param ignoreRules\n+\t *            defines which paths are included and which aren't.\n+\t * @param includeRootDirectory\n+\t *            the iterator will return the rootDirectory if this is flag is\n+\t *            true.\n+\t */\n+\tLightFileTreeIterator(File rootDirectory, Rules ignoreRules,\n+\t\t\tboolean includeRootDirectory) {\n+\t\tremainingPaths = new Stack<File>();\n+\t\tif (includeRootDirectory) {\n+\t\t\tremainingPaths.add(rootDirectory);\n+\t\t}\n+\t\tremainingDirectories = new Stack<Directory>();\n+\t\tremainingDirectories.add(new Directory(rootDirectory, ignoreRules));\n+\t}\n+\n+\tpublic boolean hasNext() {\n+\t\tfindMorePathsIfNessesary();\n+\t\treturn !remainingPaths.empty();\n+\t}\n+\n+\tvoid findMorePathsIfNessesary() {\n+\t\tif (remainingPaths.isEmpty()) {\n+\t\t\tfindMorePaths();\n+\t\t}\n+\t}\n+\n+\tvoid findMorePaths() {\n+\t\twhile (!remainingDirectories.isEmpty() && remainingPaths.isEmpty()) {\n+\t\t\tfinal Directory directory = remainingDirectories.pop();\n+\t\t\tfinal File[] paths = directory.path.listFiles();\n+\t\t\tfor (File path : paths) {\n+\t\t\t\tfinal boolean fileIsDirectory = path.isDirectory();\n+\t\t\t\tif (fileIsDirectory) {\n+\t\t\t\t\tfinal Rules subDirectoryIgnoreRules = directory.ignoreRules\n+\t\t\t\t\t\t\t.getRulesForSubDirectory(path.getName());\n+\t\t\t\t\tif (subDirectoryIgnoreRules != Rules.IGNORE_ALL) {\n+\t\t\t\t\t\tfinal Directory subDirectory = new Directory(path,\n+\t\t\t\t\t\t\t\tsubDirectoryIgnoreRules);\n+\t\t\t\t\t\tremainingDirectories.add(subDirectory);\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\tif (!directory.ignoreRules.toIgnore(path.getName(),\n+\t\t\t\t\t\tfileIsDirectory)) {\n+\t\t\t\t\tremainingPaths.add(path);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tpublic File next() {\n+\t\tfindMorePathsIfNessesary();\n+\t\ttry {\n+\t\t\treturn remainingPaths.pop();\n+\t\t} catch (EmptyStackException e) {\n+\t\t\tthrow new NoSuchElementException();\n+\t\t}\n+\t}\n+\n+\tpublic void remove() {\n+\t\tthrow new UnsupportedOperationException();\n+\t}\n+\n+\tprivate class Directory {\n+\t\tfinal File path;\n+\n+\t\tfinal Rules ignoreRules;\n+\n+\t\tDirectory(File path, Rules ignoreRules) {\n+\t\t\tthis.path = path;\n+\t\t\tthis.ignoreRules = ignoreRules;\n+\t\t}\n+\t}\n+\n+}\n-- \n1.5.4.3\n"},{"id":"78212","messageId":"1212228572-8607-1-git-send-email-florianskarten@web.de","threadId":"13642","inReplyTo":"1211574872-23676-24-git-send-email-florianskarten@web.de","subject":"[JGIT PATCH v3.1 23/23] Added the test class AddCommandIterationTest.","fromName":"Florian Koeberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-31T10:09:32Z","receivedAt":"2008-05-31T10:09:32Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Signed-off-by: Florian Koeberle <florianskarten@web.de>\n---\n .../treewalk/rules/AddCommandIterationTest.java    |  321 ++++++++++++++++++++\n 1 files changed, 321 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java\nnew file mode 100644\nindex 0000000..9203f26\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java\n@@ -0,0 +1,321 @@\n+/*\n+ *  Copyright (C) 2008 Florian KÃ¶berle\n+ *\n+ *  This library is free software; you can redistribute it and/or\n+ *  modify it under the terms of the GNU General Public\n+ *  License, version 2, as published by the Free Software Foundation.\n+ *\n+ *  This library is distributed in the hope that it will be useful,\n+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *  General Public License for more details.\n+ *\n+ *  You should have received a copy of the GNU General Public\n+ *  License along with this library; if not, write to the Free Software\n+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+ */\n+package org.spearce.jgit.treewalk.rules;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.io.PrintWriter;\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.Collections;\n+import java.util.HashSet;\n+import java.util.Iterator;\n+import java.util.List;\n+import java.util.NoSuchElementException;\n+import java.util.Set;\n+\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.errors.PathNotInProjectDirectoryException;\n+import org.spearce.jgit.lib.Repository;\n+import org.spearce.jgit.lib.WorkTree;\n+import org.spearce.jgit.treewalk.LightFileTreeIterable;\n+\n+public class AddCommandIterationTest extends TestCase {\n+\n+\tprivate WorkTree workTree;\n+\n+\tprivate AddRulesFactory factory;\n+\n+\tprivate Iterable<File> createIterable(File workingDirectory,\n+\t\t\tList<String> filePatternsOfAddCommand)\n+\t\t\tthrows PathNotInProjectDirectoryException, InvalidPatternException,\n+\t\t\tIOException {\n+\t\tfinal Rules rules = factory.createRules(workTree.getDirectory(),\n+\t\t\t\tworkingDirectory, filePatternsOfAddCommand);\n+\t\treturn new LightFileTreeIterable(workTree.getDirectory(), rules, false);\n+\t}\n+\n+\t@Override\n+\tprotected void setUp() throws Exception {\n+\t\tfinal File projectDirectory = File.createTempFile(\"test\", \"\");\n+\t\tprojectDirectory.delete();\n+\t\tprojectDirectory.mkdir();\n+\t\tprojectDirectory.deleteOnExit();\n+\t\tthis.workTree = Repository.createWorkTree(projectDirectory);\n+\t\tthis.factory = new AddRulesFactory();\n+\t}\n+\n+\tpublic void testNoPattern() throws Exception {\n+\t\tcreateFile(\"a.txt\");\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tCollections.<String> emptyList());\n+\t\tfinal Set<File> expectedPaths = Collections.emptySet();\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPaths, iterable);\n+\t}\n+\n+\tpublic void testTreePattern1() throws Exception {\n+\t\tfinal Set<File> expectedFiles = new HashSet<File>();\n+\t\tcreateFile(\"a.txt\");\n+\t\texpectedFiles.add(createFile(\"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(directoryA, Arrays\n+\t\t\t\t.asList(\"*.txt\"));\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedFiles, iterable);\n+\t}\n+\n+\tpublic void testTreePattern2() throws Exception {\n+\t\tfinal Set<File> expectedFiles = new HashSet<File>();\n+\t\tcreateFile(\"a.txt\");\n+\t\texpectedFiles.add(createFile(\"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedFiles.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tArrays.asList(\"a\" + File.separator + \"*.txt\"));\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedFiles, iterable);\n+\t}\n+\n+\tpublic void testSelectCompleteSubdirectory() throws Exception {\n+\t\tfinal Set<File> expectedPaths = new HashSet<File>();\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\t\tfinal File directoryAA = new File(directoryA, \"a\");\n+\t\tfinal File directoryAB = new File(directoryA, \"b\");\n+\t\tcreateFile(\"a.txt\");\n+\t\texpectedPaths.add(directoryA);\n+\t\texpectedPaths.add(directoryAA);\n+\t\texpectedPaths.add(createFile(\"a\", \"a.txt\"));\n+\t\texpectedPaths.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedPaths.add(directoryAB);\n+\t\texpectedPaths.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\texpectedPaths.add(createFile(\"a\", \"b\", \"a.c\"));\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tArrays.asList(\"a\"));\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPaths, iterable);\n+\t}\n+\n+\tpublic void testSelectTwoSubdirectories() throws Exception {\n+\t\tfinal Set<File> expectedPaths = new HashSet<File>();\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\t\tfinal File directoryAA = new File(directoryA, \"a\");\n+\t\tfinal File directoryAB = new File(directoryA, \"b\");\n+\t\tcreateFile(\"a.txt\");\n+\t\tcreateFile(\"a\", \"a.txt\");\n+\t\texpectedPaths.add(directoryAA);\n+\t\texpectedPaths.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedPaths.add(directoryAB);\n+\t\texpectedPaths.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\texpectedPaths.add(createFile(\"a\", \"b\", \"a.c\"));\n+\n+\t\tfinal List<String> patternList = new ArrayList<String>(2);\n+\t\tpatternList.add(\"a\" + File.separator + \"a\");\n+\t\tpatternList.add(\"a\" + File.separator + \"b\");\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tpatternList);\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPaths, iterable);\n+\t}\n+\n+\tpublic void testTwoDifferentSelects() throws Exception {\n+\t\tfinal Set<File> expectedPaths = new HashSet<File>();\n+\t\tfinal File directoryA = new File(workTree.getDirectory(), \"a\");\n+\t\tfinal File directoryAA = new File(directoryA, \"a\");\n+\t\tcreateFile(\"a.txt\");\n+\t\tcreateFile(\"a\", \"a.txt\");\n+\t\texpectedPaths.add(directoryAA);\n+\t\texpectedPaths.add(createFile(\"a\", \"a\", \"a.txt\"));\n+\t\texpectedPaths.add(createFile(\"a\", \"b\", \"a.txt\"));\n+\t\texpectedPaths.add(createFile(\"a\", \"b\", \"c\", \"a.txt\"));\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal List<String> patternList = new ArrayList<String>(2);\n+\t\tpatternList.add(\"a\" + File.separator + \"a\");\n+\t\tpatternList.add(\"a\" + File.separator + \"b\" + File.separator + \"*.txt\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tpatternList);\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPaths, iterable);\n+\t}\n+\n+\tpublic void testRealisticExample() throws Exception {\n+\t\tfinal Set<File> expectedPaths = new HashSet<File>();\n+\n+\t\t// write the .gitignore file\n+\t\tfinal File dotGitIgnoreFile = createFile(\".gitignore\");\n+\t\tfinal PrintWriter dotGitIgnoreFilePrinter = new PrintWriter(\n+\t\t\t\tdotGitIgnoreFile);\n+\t\ttry {\n+\t\t\tdotGitIgnoreFilePrinter.println(\"/alpha/config.xml\");\n+\t\t\tdotGitIgnoreFilePrinter.println(\"*.class\");\n+\t\t\tdotGitIgnoreFilePrinter.println(\"!/alpha/test/ressources/\");\n+\t\t\tdotGitIgnoreFilePrinter.println(\"*~\");\n+\t\t} finally {\n+\t\t\tdotGitIgnoreFilePrinter.close();\n+\t\t}\n+\n+\t\t// write the .git/info/exclude file\n+\t\tfinal File repositoryDirectory = workTree.getRepository()\n+\t\t\t\t.getDirectory();\n+\t\tfinal File infoDirectory = new File(repositoryDirectory, \"info\");\n+\t\tinfoDirectory.mkdir();\n+\t\tfinal File infoExcludeFile = new File(infoDirectory, \"exclude\");\n+\t\tfinal PrintWriter infoExcludeFilePrinter = new PrintWriter(\n+\t\t\t\tinfoExcludeFile);\n+\t\ttry {\n+\t\t\tinfoExcludeFilePrinter.println(\"/alpha/test/ressources/mytest.txt\");\n+\t\t} finally {\n+\t\t\tinfoExcludeFilePrinter.close();\n+\t\t}\n+\n+\t\tcreateFile(\"alpha\", \"config.xml\");\n+\t\texpectedPaths.add(createFile(\"alpha\", \"src\", \"Main.java\"));\n+\t\tcreateFile(\"alpha\", \"src\", \"Main.class\");\n+\t\texpectedPaths.add(createFile(\"alpha\", \"test\", \"ressources\",\n+\t\t\t\t\"Example.class\"));\n+\t\texpectedPaths\n+\t\t\t\t.add(createFile(\"alpha\", \"test\", \"ressources\", \"input.txt\"));\n+\t\tcreateFile(\"alpha\", \"test\", \"ressources\", \"input.txt~\");\n+\t\tcreateFile(\"alpha\", \"test\", \"ressources\", \"mytest.txt\");\n+\n+\t\tfinal File alphaDirectory = new File(workTree.getDirectory(), \"alpha\");\n+\t\tfinal File srcDirectory = new File(alphaDirectory, \"src\");\n+\t\tfinal File testDirectory = new File(alphaDirectory, \"test\");\n+\t\tfinal File ressources = new File(testDirectory, \"ressources\");\n+\n+\t\texpectedPaths.add(alphaDirectory);\n+\t\texpectedPaths.add(srcDirectory);\n+\t\texpectedPaths.add(testDirectory);\n+\t\texpectedPaths.add(ressources);\n+\n+\t\tfinal List<String> patternList = new ArrayList<String>(2);\n+\t\tpatternList.add(\"alpha\");\n+\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tpatternList);\n+\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPaths, iterable);\n+\t}\n+\n+\tpublic void testSingleFile() throws Exception {\n+\t\tcreateFile(\"a.txt\");\n+\t\tcreateFile(\"a\", \"a.txt\");\n+\t\tcreateFile(\"a\", \"a\", \"a.txt\");\n+\t\tfinal File expectedFile = createFile(\"a\", \"b\", \"a.txt\");\n+\t\tcreateFile(\"a\", \"b\", \"a.c\");\n+\n+\t\tfinal String pattern = \"a\" + File.separator + \"b\" + File.separator\n+\t\t\t\t+ \"a.txt\";\n+\t\tfinal Iterable<File> iterable = createIterable(workTree.getDirectory(),\n+\t\t\t\tArrays.asList(pattern));\n+\t\tfinal Set<File> expectedPaths = Collections.singleton(expectedFile);\n+\t\tassertIsValidIterable(iterable);\n+\t\tassertIterableReturnsSet(expectedPaths, iterable);\n+\t}\n+\n+\t/**\n+\t * Tests if the specified {@link Iterable} returns the specified set of\n+\t * {@link File}s. The assertion will fail if the {@link Iterable} returns\n+\t * to much, to less files. It will also fail if the {@link Iterable} returns\n+\t * a file twice.\n+\t * \n+\t * @param expectedContent\n+\t *            the expected set of files.\n+\t * @param iterable\n+\t *            the {@link Iterable} to test.\n+\t */\n+\tprivate void assertIterableReturnsSet(Set<File> expectedContent,\n+\t\t\tIterable<File> iterable) {\n+\t\tfinal Set<File> returnedFiles = new HashSet<File>();\n+\t\tfinal List<File> doubleReturnedFiles = new ArrayList<File>();\n+\n+\t\tfinal Iterator<File> iterator = iterable.iterator();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\tfinal File file = iterator.next();\n+\t\t\tif (!returnedFiles.add(file)) {\n+\t\t\t\tdoubleReturnedFiles.add(file);\n+\t\t\t}\n+\t\t}\n+\t\tfinal Set<File> missingFiles = new HashSet<File>();\n+\t\tfor (File file : expectedContent) {\n+\t\t\tif (!returnedFiles.contains(file)) {\n+\t\t\t\tmissingFiles.add(file);\n+\t\t\t}\n+\t\t}\n+\t\tif (!missingFiles.isEmpty()) {\n+\t\t\tfail(String.format(\"missing paths: %s\", missingFiles));\n+\t\t}\n+\n+\t\tfinal Set<File> unexpectedFiles = new HashSet<File>();\n+\t\tfor (File file : returnedFiles) {\n+\t\t\tif (!expectedContent.contains(file)) {\n+\t\t\t\tunexpectedFiles.add(file);\n+\t\t\t}\n+\t\t}\n+\t\tif (!unexpectedFiles.isEmpty()) {\n+\t\t\tfail(String.format(\"unexpected paths: %s\", unexpectedFiles));\n+\t\t}\n+\n+\t\tif (!doubleReturnedFiles.isEmpty()) {\n+\t\t\tfail(String.format(\"multiple times returned paths: %s\",\n+\t\t\t\t\tdoubleReturnedFiles));\n+\t\t}\n+\n+\t}\n+\n+\tprivate static void assertIsValidIterable(Iterable<File> iterable) {\n+\t\tfinal Iterator<File> iterator = iterable.iterator();\n+\t\twhile (iterator.hasNext()) {\n+\t\t\titerator.next();\n+\t\t}\n+\t\ttry {\n+\t\t\titerator.next();\n+\t\t\tfail();\n+\t\t} catch (NoSuchElementException e) {\n+\t\t\t// expected\n+\t\t}\n+\t}\n+\n+\tprivate File createFile(String... path) throws IOException {\n+\t\tFile file = workTree.getDirectory();\n+\t\tfor (int i = 0; i < path.length; i++) {\n+\t\t\tfile = new File(file, path[i]);\n+\t\t\tif (i == path.length - 1) {\n+\t\t\t\tfile.getParentFile().mkdirs();\n+\t\t\t\tfile.createNewFile();\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\treturn file;\n+\t}\n+}\n-- \n1.5.4.3\n"},{"id":"78214","messageId":"484125AB.5080803@web.de","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","fromName":"Florian Köberle","fromEmail":"florianskarten@web.de","sentAt":"2008-05-31T10:17:15Z","receivedAt":"2008-05-31T10:17:15Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Hi\n\nIn send in two updated versions of two patches. I renamed \"pathes\" to \n\"paths\".\n\nThanks Paolo for telling me about this.\n\nBest regards,\nFlorian Koeberle\n"},{"id":"78846","messageId":"200806060222.40654.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:22:40Z","receivedAt":"2008-06-06T00:22:40Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"fredagen den 23 maj 2008 22.34.09 skrev Florian Koeberle:\n> \n> Hi\n> \n> This patch set contains a new fnmatch implementation.\n\nLooks ok, with me. Only minor comments in separate mail.\n\n> Unsupported are colon expressions like \":alpha:\". I didn't expect git-add to support it, but as I just noticed git does.\nMaybe we should anticipate it and throw an exception if one tries the pattern and not treat it as [alph:] .\n\nWell we noted they were broken in Git so (separate thread) so we may as well try something sane. \n\n-- robin\n"},{"id":"78847","messageId":"200806060222.51928.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-6-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 05/23] Added the iterface Rules.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:22:51Z","receivedAt":"2008-06-06T00:22:51Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"\ns/Iterface/Interface/\n\nfredagen den 23 maj 2008 22.34.14 skrev Florian Koeberle:\n> Signed-off-by: Florian Koeberle <florianskarten@web.de>\n> ---\n>  .../src/org/spearce/jgit/treewalk/rules/Rules.java |   99 ++++++++++++++++++++\n>  1 files changed, 99 insertions(+), 0 deletions(-)\n>  create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rules.java\n> \n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rules.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/Rules.java\n> +\tpublic abstract boolean toIgnore(String fileName, boolean fileIsDirectory);\n\nShouldn't this be shouldIgnore instead? toXXXX is a name of a converter as e.g. toString\n\n> +\t\t@Override\n> +\t\tpublic String toString() {\n> +\t\t\treturn \"ignore all rules\";\nProbably better with something like \"Rules[IGNOREALL]\" to distinguish it\nfrom other strings. The bracketed toString is common for method intended\nfor debugging.\n"},{"id":"78852","messageId":"200806060222.57591.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-7-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 06/23] Added the class FileNamePattern.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:22:57Z","receivedAt":"2008-06-06T00:22:57Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"> +\tpublic boolean match(String fileName, boolean fileIsDirectory) {\n> +\t\tif (matchDirectoriesOnly && !fileIsDirectory) {\n> +\t\t\treturn false;\n> +\t\t}\n> +\t\tfileNameMatcher.resetStringToMatch();\n\nPartially discusses before, but here is another aspect. One advantage\nwith bracketless code is that you get an extra blank line for free.\n\n\tif (matchDirectoriesOnly && !fileIsDirectory)\n\t\treturn false;\n\n\tfileNameMatcher.resetStringToMatch();\n\n-- robin\n"},{"id":"78848","messageId":"200806060223.01120.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-10-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 09/23] Added a Rules interface implementation and a factory for it.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:23:00Z","receivedAt":"2008-06-06T00:23:00Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"fredagen den 23 maj 2008 22.34.18 skrev Florian Koeberle:\n> +\t/**\n> +\t * @see Rules#toIgnore(java.lang.String, boolean)\n> +\t */\n> +\tpublic boolean toIgnore(String fileName, boolean fileIsDirectory) {\n\n(Applies to many places)\nDon't make javadoc style comments for overrides. Rather just omit it\nor use a plain comment. Also use the @Override annotation if you\noverride an implementation. We use Java 5, so we may as well use\nall bells and whistles that make sense.\n\nI'm not sure about other IDE's, but Eclipse will automaticall picks up then\njavadoc for the superclass or interface that declare the methos being \noverridden if the overriding method does not hava a javadoc comment.\nThe javadoc tool also does this so I assume any descent IDE\ndoes too (if not it's a bug).\n\n-- robin\n"},{"id":"78853","messageId":"200806060223.07384.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-20-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 19/23] Added WorkTree class which can be constructed over Repository.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:23:07Z","receivedAt":"2008-06-06T00:23:07Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"fredagen den 23 maj 2008 22.34.28 skrev Florian Koeberle:\n> ---\n>  .../src/org/spearce/jgit/lib/Repository.java       |   57 +++++++++++++++++\n>  .../src/org/spearce/jgit/lib/WorkTree.java         |   67 ++++++++++++++++++++\n>  2 files changed, 124 insertions(+), 0 deletions(-)\n>  create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/WorkTree.java\n> \n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n> +\tpublic Commit setupHEADRef(final String remoteBranch, final String branch)\n> +\t\t\tthrows IOException {\n> +\t\tCommit mapCommit = mapCommit(remoteBranch);\n> +\t\tString refName = Constants.HEADS_PREFIX + \"/\" + branch;\n> +\t\tLockFile masterRef = lockRef(refName);\n> +\t\ttry {\n> +\t\t\tmasterRef.write(mapCommit.getCommitId());\n> +\t\t\tmasterRef.commit();\n> +\t\t} finally {\n> +\t\t\tmasterRef.unlock();\n> +\t\t}\n> +\t\twriteSymref(Constants.HEAD, refName);\n> +\t\treturn mapCommit;\n> +\t}\nShouldn't someone be calling this?\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WorkTree.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WorkTree.java\n> +\t/**\n> +\t * Closes the git repository of this project.\n> +\t */\n> +\tpublic void closeRepository() {\n> +\t\trepository.close();\n> +\t}\n\nThis is redundant. Very few callers need it and those can just as well\ncall getRepsitory().close() anyway.\n"},{"id":"78851","messageId":"200806060223.09332.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-21-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 20/23] Added the class NoGitRepositoryFoundException.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:23:09Z","receivedAt":"2008-06-06T00:23:09Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"fredagen den 23 maj 2008 22.34.29 skrev Florian Koeberle:\n> +\tpublic NoGitRepositoryFoundException(final File fileWeSearchedRepositoryFor) {\n> +\t\tsuper(String.format(\"No repository found for file '%s'\",\n> +\t\t\t\tfileWeSearchedRepositoryFor));\n\nThis is any odd patterrn. Usually we use + to concatenate strimgs.\n\n-- robin\n"},{"id":"78850","messageId":"200806060223.11513.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-22-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 21/23] Formatted Repository class.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:23:11Z","receivedAt":"2008-06-06T00:23:11Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"I'm slightly allergic to formatting patches.\n\n-- robin\n"},{"id":"78849","messageId":"200806060223.13052.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"1211574872-23676-24-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 23/23] Added the test class AddCommandIterationTest.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-06T00:23:12Z","receivedAt":"2008-06-06T00:23:12Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/rules/AddCommandIterationTest.java\n> +\t@Override\n> +\tprotected void setUp() throws Exception {\n> +\t\tfinal File projectDirectory = File.createTempFile(\"test\", \"\");\n> +\t\tprojectDirectory.delete();\n> +\t\tprojectDirectory.mkdir();\n> +\t\tprojectDirectory.deleteOnExit();\n> +\t\tthis.workTree = Repository.createWorkTree(projectDirectory);\n> +\t\tthis.factory = new AddRulesFactory();\n> +\t}\n\nI've had some problems with this pattern, especially on Windows. We need\nsome support class, like the RepositoryTestCase to handle the not so nice\nparts of getting tests to run, rerun and cleam up after themselves. Eclipse\nsometims adds an extra twist becuase File may be lefte open between test\nruns, which is the reason RepositoryTestCase uses a new directories every time.\n\nDoes this work at all? delete() requires directories to be empty in order to delete.\n\n-- robin\n"},{"id":"79026","messageId":"20080607084352.GA14120@spearce.org","threadId":"13642","inReplyTo":"1211574872-23676-1-git-send-email-florianskarten@web.de","subject":"Re: [JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-06-07T08:43:52Z","receivedAt":"2008-06-07T08:43:52Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Florian Koeberle <florianskarten@web.de> wrote:\n>  .../org/spearce/jgit/lib/FileNameMatcherTest.java  |  311 +++++++++++++\n>  .../jgit/treewalk/LightFileTreeIteratorTest.java   |  114 +++++\n>  .../treewalk/rules/AddCommandIterationTest.java    |  321 +++++++++++++\n>  .../treewalk/rules/OverallIgnoreRulesTest.java     |  375 +++++++++++++++\n>  .../jgit/errors/InvalidPatternException.java       |   44 ++\n>  .../jgit/errors/NoGitRepositoryFoundException.java |   28 ++\n>  .../errors/PathNotInProjectDirectoryException.java |   25 +\n>  .../src/org/spearce/jgit/lib/Constants.java        |   30 +-\n>  .../src/org/spearce/jgit/lib/FileNameMatcher.java  |  376 +++++++++++++++\n>  .../src/org/spearce/jgit/lib/Repository.java       |  482 +++++++++++++-------\n>  .../src/org/spearce/jgit/lib/WorkTree.java         |   67 +++\n>  .../jgit/treewalk/LightFileTreeIterable.java       |   59 +++\n>  .../jgit/treewalk/LightFileTreeIterator.java       |  112 +++++\n>  .../jgit/treewalk/rules/AddRuleListFactory.java    |   75 +++\n>  .../jgit/treewalk/rules/AddRulesFactory.java       |   90 ++++\n>  .../jgit/treewalk/rules/FileNamePattern.java       |   58 +++\n>  .../jgit/treewalk/rules/FilePathPattern.java       |   76 +++\n>  .../spearce/jgit/treewalk/rules/FilePattern.java   |  107 +++++\n>  .../jgit/treewalk/rules/IgnoreRuleListFactory.java |   94 ++++\n>  .../src/org/spearce/jgit/treewalk/rules/Rule.java  |   61 +++\n>  .../treewalk/rules/RuleListToObjectConverter.java  |  130 ++++++\n>  .../src/org/spearce/jgit/treewalk/rules/Rules.java |   99 ++++\n>  .../jgit/treewalk/rules/RulesImplementation.java   |   73 +++\n\nI finally found time while travelling around on planes this past\nweek to review this series.  Since I didn't have access to my email\nclient I didn't organize my thoughts per-patch very well, if it all.\n\nI agree with all of Robin's comments.  He noticed a few things I\ndidn't, but they all made sense once I read them.\n\nWithout further ado, here are my remarks on this current series:\n\n----\nPlease consider using a cleanup commit to:\n\n- Rename FileNameMatcher.extendStringToMatch to just append().\n  The action used here is generally called \"append\" in Java, see\n  StringBuffer for example.\n\n- Rename FileNameMatcher.resetStringToMatch to just reset().  It\n  is cleaning up the state and the only state it can cleanup is\n  the string we are matching against.\n\n- Rename FileNameMatcher.willExtendResultInNoMatch() to say\n  canAppendMatch() with the negation in the callers of the\n  current willExtendResultInNoMatch() method.  I think its\n  easier to read as \"!canAppendMatch()\".\n\nEcipse can easily handle the refactoring and its probably easier\nto just do at the end of the series rather than fixing every commit\nalong the way.\n\n----\nI'm not sure I see why we have FilePattern.isSameForSubdirectories(),\nor Rule.isSameForSubDirectories().  By the end of the series you do\nnot call either method.  These should be removed from the abstract\ndefinition and from all implementing classes.  Again a cleanup commit\nto remove this would be OK.\n\n----\nClass Rule should not be public; none of its members are public.\n\nFileNameMatcher's Head.getNextHeads and AbstractHead.setNewHeads\nshould not be public either; the interfaces are visible only to\nthis package.\n\nIn general please make method access reflect the access of the\nclass the method is declared within.  If the class is not a public\nclass then the method isn't visible, even if it is marked public,\nso instead mark it package-level.\n\n----\nSince FilePattern is not public none of its members should be public;\nuse default package access for the MATCH_ALWAYS and MATCH_NEVER\nconstants and private access for the static inner classes that\nsupply those two implementations.\n\n----\nIn FileNameMatcher the symbol name invalidWildgetCharacter is used as\na parameter to a number of methods/constructors.  Its name does not\nmean anything to me as I don't know what \"Wildget\" means.  In many\ncases this long name is causing Eclipse to wrap the code poorly.\nRename it to notInWild perhaps?\n\nIn FileNameMatcher.extendStringToMatchByOneCharacter you don't need\nto use an int index into the List<Head> called \"heads\".  Instead\nuse the Java 5 syntax of \"for (final Head head : heads)\" and let\nthe compiler generate the loop.  If the memory allocation of the\nIterator is too costly here then you probably need to rethink your\nstorage anyway.  You could have getNextHeads return you an Head[]\ninstead of List<Head>.  The compiler can loop over the array and\nan array takes up less memory than an ArrayList of the same size.\n\nIn FileNameMatcher.extractGroupPatternWithoutBrackets your string\nliterals for the pattern argument of String.format() are way too\nlong and cause them to overflow the line.  Break the string into\nmultiple literals and use + to append them together.  Any decent\nJava compiler will combine them back into a single string in the\nclass string pool.  Even if the compiler sucks, this is for an\nerror condition only.  Who cares how long the StringBuilder is\ngoing to take at that point, the operation has failed.\n\n----\nDon't create a local variable just to return it.  You do this\nat least in FileNameMatcher.extractGroupPatternWithoutBrackets:\n\n\tfinal String groupPatternWithOutBrackets = patternString.substring(\n\t\tstart + 1, closingBracketIndex);\n\treturn groupPatternWithOutBrackets;\n\nand it looks more complex than is really needed here:\n\n\treturn patternString.substring(start + 1, closingBracketIndex);\n\nThis is also true in createMatcherForSuffix.  You can reduce\nthat entire method to just:\n\n\treturn new FileNameMatcher(new ArrayList<Head>(heads));\n\nwhich is much easier to read than the 3 lines you have to\ncreate the copyOfHeads.\n\n----\nPlease use a for loop where it makes sense.  In the case of\nFileNameMatcher.extractGroupPatternWithoutBrackets you use a\nwhile loop with a variable called \"start\", with a post condition\nto decrement the variable.  That's why we have the for(;;) loop\nconstruct in the language.\n\nBut this entire method is 30 lines of code to say this:\n\n\tfinal int ob = pattern.lastIndexOf('[', closingBracket - 1);\n\tfinal int cb = pattern.lastIndexOf(']', closingBracket - 1);\n\tif (ob < 0 || cb > ob)\n\t\tthrow new InvalidPatternException(\"Unbalanced []\", pattern);\n\treturn pattern.substring(ob + 1, closingBracket);\n\n----\nIn FileNameMatcher the isMatch method is _way_ more complex than\nit needs to be.  Just use:\n\n\tpublic boolean isMatch() {\n\t\treturn heads.contains(LastHead.INSTANCE);\n\t}\n\ncontains works perfectly well.  From what I can tell of the\nimplementation the size of heads should be fairly small, usually\nonly 1 or 2 items at most.  Testing via contains without using a\nbackward traversing ListIterator is just fine here.\n\n----\nPlease don't initialize fields to null.  For example in the\nAbstractHead class of FileNameMatcher you set newHeads = null;\nthe JVM does this for you automatically and that makes your\nown statement redundant.\n\n----\nI'm not sure I see the value in the Head interface within\nFileNameMatcher.  Only two implementations exist; the one for\nAbstractHead and the one for LastHead.  Since LastHead is already\njust a singleton you might as well just have it extend from the\nAbstractHead base class and \"waste\" the couple of words of static\nmemory for an empty head list.\n\n----\nIn FilePathPattern you use \"new Character('/')\".  Instead use the\nflyweight one that comes with the JRE by \"Character.valueOf('/')\".\n\n----\nIn general the implementation still feels overly complex to me.\nLots of interfaces, factories and delegation for what should be a\nrelatively simple thing of pruning names that should be skipped.\n\nIt also seems to be somewhat special cased around git-add sort\nof behavior.  We also need to process ignore lists for merge, to\nmake sure we can safely overwrite something or not if there is an\nuntracked file in the working tree that conflicts with what we are\nmerging the working directory to.\n\n-- \nShawn.\n"},{"id":"79130","messageId":"484C0548.8090309@web.de","threadId":"13642","inReplyTo":"200806060223.09332.robin.rosenberg.lists@dewire.com","subject":"Re: [JGIT PATCH v3 20/23] Added the class NoGitRepositoryFoundException.","fromName":"Florian Köberle","fromEmail":"florianskarten@web.de","sentAt":"2008-06-08T16:14:00Z","receivedAt":"2008-06-08T16:14:00Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"Robin Rosenberg wrote:\n >> +\t\tsuper(String.format(\"No repository found for file '%s'\",\n >> +\t\t\t\tfileWeSearchedRepositoryFor));\n >\n > This is any odd patterrn. Usually we use + to concatenate strimgs.\n\nHi Robin,\n\nI know two good reason why you should use formating functions over \nstring concatenation via the plus sign:\n\n1.) formated strings are better translatable. e.g.\n\"The string '%s' is more then %s characters long\"\nis easier to translate then the three strings:\n\"The string '\"\n\"' is more then \"\n\" characters long\"\n\n2.) Whitespace mistakes are easier to see. e.g.\n(i + \"coins\") and (\"%scoins\", i)\n\nSure you can make the mistake to provide not enough arguments, but \nthat's not so worse:\na.) Some IDEs, like Intellij IDEA warn you if you call a formating \nfunction with to few arguments.\nb.) A exception will be thrown at the time the function is called, if \nthere are not enough arguments. Thus you will notice your mistake very soon.\n\nBest regards,\nFlorian\n"},{"id":"79133","messageId":"484C0ACA.8080702@web.de","threadId":"13642","inReplyTo":"200806060222.40654.robin.rosenberg.lists@dewire.com","subject":"Re: [JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","fromName":"Florian Köberle","fromEmail":"florianskarten@web.de","sentAt":"2008-06-08T16:37:30Z","receivedAt":"2008-06-08T16:37:30Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":">> Unsupported are colon expressions like \":alpha:\". I didn't expect git-add to support it, but as I just noticed git does.\n> Maybe we should anticipate it and throw an exception if one tries the pattern and not treat it as [alph:] .\n> \n> Well we noted they were broken in Git so (separate thread) so we may as well try something sane. \nJust did some tests and noted that the shell and git does not support \nthem. I guess I thought that they work because [:alpha:] matched \"a\".\n\nHi Robin\n\nThe bash shell doesn't support [:alpha:] too:\n$ mkdir test\n$ cd test\n$ touch a\n$ touch b\n$ touch :\n$ ls [:alpha:]\n:  a\n\nThe fnmatch function of the python module fnmatch \n(http://docs.python.org/lib/module-fnmatch.html) does not support \n:alpha: too.\n\nexample:\n$python\n >>> from fnmatch import fnmatch\n >>> fnmatch(\"a\",\"[:alpha:]\")\nFalse\n\nSo I see no reason for displaying a warning.\n\nBest regards,\nFlorian\n"},{"id":"79165","messageId":"200806082305.30035.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"484C0548.8090309@web.de","subject":"Re: [JGIT PATCH v3 20/23] Added the class NoGitRepositoryFoundException.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-08T21:05:26Z","receivedAt":"2008-06-08T21:05:26Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"söndagen den 8 juni 2008 18.14.00 skrev Florian Köberle:\n> Robin Rosenberg wrote:\n>  >> +\t\tsuper(String.format(\"No repository found for file '%s'\",\n>  >> +\t\t\t\tfileWeSearchedRepositoryFor));\n>  >\n>  > This is any odd patterrn. Usually we use + to concatenate strimgs.\n> \n> Hi Robin,\n> \n> I know two good reason why you should use formating functions over \n> string concatenation via the plus sign:\n> \n> 1.) formated strings are better translatable. e.g.\n> \"The string '%s' is more then %s characters long\"\n[..]\n> 2.) Whitespace mistakes are easier to see. e.g.\n> (i + \"coins\") and (\"%scoins\", i)\n> \n> Sure you can make the mistake to provide not enough arguments, but \n> that's not so worse:\n> a.) Some IDEs, like Intellij IDEA warn you if you call a formating \n> function with to few arguments.\n\nI'm so ashamed... I used to like printf in C, but I've hardly used it in Java. I\nprobably will use it more now. Seems Eclipse doesn't check (even GCC\ndoes that).\n\n-- robin\n"},{"id":"79166","messageId":"200806082328.49632.robin.rosenberg.lists@dewire.com","threadId":"13642","inReplyTo":"484C0ACA.8080702@web.de","subject":"Re: [JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-06-08T21:28:49Z","receivedAt":"2008-06-08T21:28:49Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"söndagen den 8 juni 2008 18.37.30 skrev Florian Köberle:\n(please retatain who said what)\n> >> Unsupported are colon expressions like \":alpha:\". I didn't expect git-add to support it, but as I just noticed git does.\n> > Maybe we should anticipate it and throw an exception if one tries the pattern and not treat it as [alph:] .\n> > \n> > Well we noted they were broken in Git so (separate thread) so we may as well try something sane. \n> Just did some tests and noted that the shell and git does not support \n> them. I guess I thought that they work because [:alpha:] matched \"a\".\n> \n> Hi Robin\n> \n> The bash shell doesn't support [:alpha:] too:\n> $ mkdir test\n> $ cd test\n> $ touch a\n> $ touch b\n> $ touch :\n> $ ls [:alpha:]\n> :  a\nOh, it does. [:alpha:] is a character class, like a-z. So you use [[:alpha:]], which is what git as well as bash\nunderstands.\n\n> The fnmatch function of the python module fnmatch \n> (http://docs.python.org/lib/module-fnmatch.html) does not support \n> :alpha: too.\n> \n> example:\n> $python\n>  >>> from fnmatch import fnmatch\n>  >>> fnmatch(\"a\",\"[:alpha:]\")\n> False\nHmm. Odd:\n\n$ python\nPython 2.5.2 (r252:60911, Apr 12 2008, 01:47:55)\n[GCC 4.2.3 (4.2.3-6mnb1)] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> from fnmatch import fnmatch\n>>> fnmatch(\"a\",\"[:alpha:]\")\nTrue\n\nBut then, it's matching the a(s), not the character class.\n\n>>> fnmatch(\"x\",\"[:alpha:]\")\nFalse\n>>> fnmatch(\"x\",\"[[:alpha:]]\")\nFalse\n\n-- robin\n"},{"id":"79245","messageId":"484D6442.7070408@web.de","threadId":"13642","inReplyTo":"200806082328.49632.robin.rosenberg.lists@dewire.com","subject":"Re: [JGIT PATCH v3 0/23] Implementation of a file tree iteration using ignore rules.","fromName":"Florian Köberle","fromEmail":"florianskarten@web.de","sentAt":"2008-06-09T17:11:30Z","receivedAt":"2008-06-09T17:11:30Z","isPatch":true,"sender":{"key":"florianskarten@web.de","avatar":null},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nRobin Rosenberg wrote:\n| Oh, it does. [:alpha:] is a character class, like a-z. So you use\n[[:alpha:]], which is what git as well as bash\n| understands.\nNaturally I will then implement the POSIX character classes as listed at\n(http://en.wikipedia.org/wiki/Regular_expression#POSIX_character_classes)\nfor FileNameMatcher too.\n\n\n|\n|> The fnmatch function of the python module fnmatch\n|> (http://docs.python.org/lib/module-fnmatch.html) does not support\n|> :alpha: too.\n|>\n|> example:\n|> $python\n|>  >>> from fnmatch import fnmatch\n|>  >>> fnmatch(\"a\",\"[:alpha:]\")\n|> False\n| Hmm. Odd:\n[...]\n|>>> fnmatch(\"a\",\"[:alpha:]\")\n| True\nOops.. of course the output was True for me too, but for\nfnmatch(\"b\",\"[:alpha:]\") it wasn't.\n\nBest Regards,\nFlorian Köberle\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org\n\niD8DBQFITWRC59ca4mzhfxMRAjdrAJ9/6VDQOOHdm0WGP/W+l84LiKrOhQCfdkJn\nDEcnz0WTzockGJ+w9S1/4xk=\n=/PpE\n-----END PGP SIGNATURE-----\n"}]}