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

Revision v2 of 2 in this series.

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

[JGIT PATCH v2 12/24] Added the class GlobalFilePattern

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/GlobalFilePattern.java     |   58 ++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/GlobalFilePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/GlobalFilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/GlobalFilePattern.java
new file mode 100644
index 0000000..ec1f38a
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/GlobalFilePattern.java
@@ -0,0 +1,58 @@
+/*
+ *  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 org.spearce.jgit.lib.FNMatchPattern;
+
+/**
+ * A {@link GlobalFilePattern} defines a pattern for all files in a tree. A
+ * typical example would be "*.txt", which would match at any file or subtree
+ * which ends with ".txt" like "a/b/c.txt" and "a.txt/a.c".
+ * 
+ */
+class GlobalFilePattern implements FilePattern {
+	private final FNMatchPattern fnMatchPattern;
+
+	private final boolean matchDirectoriesOnly;
+
+	GlobalFilePattern(String fnMatchPatternString, boolean matchDirectoriesOnly) {
+		this.fnMatchPattern = new FNMatchPattern(fnMatchPatternString);
+		this.matchDirectoriesOnly = matchDirectoriesOnly;
+	}
+
+	public boolean canMatchAtThisDirectoryLevel() {
+		return true;
+	}
+
+	public FilePattern getPatternForSubDirectory(String directoryName) {
+		if (match(directoryName, true)) {
+			return MATCH_ALWAYS;
+		}
+		return this;
+	}
+
+	public boolean match(String fileName, boolean fileIsDirectory) {
+		if (matchDirectoriesOnly && !fileIsDirectory) {
+			return false;
+		}
+		return fnMatchPattern.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