Thread (46 messages) flat view 46 messages, 5 authors, 2016-06-15
STALE3712d

Revision v2 of 2 in this series.

Revisions (2)
  1. v2 current
  2. v3 [diff vs current]

[JGIT PATCH v2 13/24] Added the class ComplexFilePattern.

From: Florian Koeberle <hidden>
Date: 2016-06-15 22:44:36
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Florian Koeberle <redacted>
---
 .../jgit/treewalk/rules/ComplexFilePattern.java    |   97 ++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/ComplexFilePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/ComplexFilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/ComplexFilePattern.java
new file mode 100644
index 0000000..7c2aba0
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/ComplexFilePattern.java
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (C) 2008 Florian berle
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public
+ *  License, version 2, as published by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+ */
+package org.spearce.jgit.treewalk.rules;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.spearce.jgit.lib.FNMatchPattern;
+
+/**
+ * A {@link ComplexFilePattern} defines for some components of a file path
+ * fnmatch like patterns. For example could such a pattern be that the first
+ * directory must start with an a and that the second directory must end with
+ * and b. In the example the pathes axx/xxb/hello.txt and ayy/yyb would match,
+ * but axx would not match.
+ * 
+ */
+class ComplexFilePattern implements FilePattern {
+	private final List<FNMatchPattern> usedPatternList;
+
+	private final boolean matchDirectoriesOnly;
+
+	private final int offset;
+
+	private ComplexFilePattern(List<FNMatchPattern> List,
+			boolean matchDirectoriesOnly, int offset) {
+		this.usedPatternList = List;
+		this.matchDirectoriesOnly = matchDirectoriesOnly;
+		this.offset = offset;
+	}
+
+	ComplexFilePattern(List<String> patternStrings, boolean matchDirectoriesOnly) {
+		this.usedPatternList = new ArrayList<FNMatchPattern>(patternStrings
+				.size());
+		for (String patternString : patternStrings) {
+			this.usedPatternList.add(new FNMatchPattern(patternString));
+		}
+		this.offset = 0;
+		this.matchDirectoriesOnly = matchDirectoriesOnly;
+	}
+
+	int getActualPathSize() {
+		return usedPatternList.size() - offset;
+	}
+
+	private FNMatchPattern getPatternOfCurrentLevel() {
+		return usedPatternList.get(offset);
+	}
+
+	public boolean canMatchAtThisDirectoryLevel() {
+		return getActualPathSize() == 1;
+	}
+
+	public FilePattern getPatternForSubDirectory(String directoryName) {
+
+		if (getActualPathSize() > 1) {
+			if (getPatternOfCurrentLevel().matches(directoryName)) {
+				return new ComplexFilePattern(usedPatternList,
+						matchDirectoriesOnly, offset + 1);
+			} else {
+				return FilePattern.MATCH_NEVER;
+			}
+		}
+		assert (getActualPathSize() == 1);
+		if (match(directoryName, true)) {
+			return FilePattern.MATCH_ALWAYS;
+		} else {
+			return FilePattern.MATCH_NEVER;
+		}
+	}
+
+	public boolean match(String fileName, boolean fileIsDirectory) {
+		if (!fileIsDirectory && matchDirectoriesOnly) {
+			return false;
+		}
+		return getPatternOfCurrentLevel().matches(fileName);
+	}
+
+	public boolean isSameForSubDirectories() {
+		return false;
+	}
+
+}
-- 
1.5.4.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help