Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/PathScope.java @ 643:a8ce405da1f5
v1.2 line of dev: update versions, use patch merge code by default
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 19 Jun 2013 16:03:11 +0200 |
parents | 072b5f3ed0c8 |
children |
rev | line source |
---|---|
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
2 * Copyright (c) 2011-2012 TMate Software Ltd |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
19 import static org.tmatesoft.hg.util.Path.CompareResult.*; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
20 |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.ArrayList; |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
23 import org.tmatesoft.hg.util.FileIterator; |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.util.Path; |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
25 import org.tmatesoft.hg.util.Path.CompareResult; |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 /** |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
28 * <ul> |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
29 * <li> Specify folder to get all files in there included, but no subdirs |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
30 * <li> Specify folder to get all files and files in subdirectories included |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
31 * <li> Specify exact set files (with option to accept or not paths leading to them) |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
32 * </ul> |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * @author Artem Tikhomirov |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 * @author TMate Software Ltd. |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 */ |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 public class PathScope implements Path.Matcher { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 private final Path[] files; |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 private final Path[] dirs; |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
39 private final boolean includeNestedDirs; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
40 private final boolean includeParentDirs; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
41 private final boolean includeDirContent; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
42 |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
43 /** |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
44 * See {@link PathScope#PathScope(boolean, boolean, Path...)} |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
45 */ |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
46 public PathScope(boolean recursiveDirs, Path... paths) { |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
47 this(true, recursiveDirs, true, paths); |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
48 } |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
50 /** |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
51 * With <code>matchParentDirs</code>, <code>recursiveDirs</code> and <code>matchDirContent</code> set to <code>false</code>, |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
52 * this scope matches only exact paths specified. |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
53 * <p> |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
54 * With <code>matchParentDirs</code> set to <code>true</code>, parent directories for files and folders listed in |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
55 * the <code>paths</code> would get accepted as well (handy for {@link FileIterator FileIterators}). |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
56 * Note, if supplied path lists a file, parent directory for the file is not matched unless <code>matchParentDirs</code> |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
57 * is <code>true</code>. To match file's immediate parent without matching all other parents up to the root, just add file parent |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
58 * along with the file to <code>paths</code>. |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
59 * <p> |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
60 * With <code>recursiveDirs</code> set to <code>true</code>, subdirectories (with files) of directories listed in <code>paths</code> would |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
61 * be matched as well. Similar to `a/b/**` |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
62 * <p> |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
63 * With <code>matchDirContent</code> set to <code>true</code>, files right under any directory listed in <code>path</code> would be matched. |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
64 * Similar to `a/b/*`. Makes little sense to set to <code>false</code> when <code>recursiceDirs</code> is <code>true</code>, although may still |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
65 * be useful in certain scenarios, e.g. PathScope(false, true, false, "a/") matches files under "a/b/*" and "a/b/c/*", but not files "a/*". |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
66 * |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
67 * @param matchParentDirs <code>true</code> to accept parent dirs of supplied paths |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
68 * @param recursiveDirs <code>true</code> to include subdirectories and files of supplied paths |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
69 * @param includeDirContent |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
70 * @param paths files and folders to match |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
71 */ |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
72 public PathScope(boolean matchParentDirs, boolean recursiveDirs, boolean matchDirContent, Path... paths) { |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 if (paths == null) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 throw new IllegalArgumentException(); |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
76 includeParentDirs = matchParentDirs; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
77 includeNestedDirs = recursiveDirs; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
78 includeDirContent = matchDirContent; |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 ArrayList<Path> f = new ArrayList<Path>(5); |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 ArrayList<Path> d = new ArrayList<Path>(5); |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 for (Path p : paths) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 if (p.isDirectory()) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 d.add(p); |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } else { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 f.add(p); |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 files = f.toArray(new Path[f.size()]); |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 dirs = d.toArray(new Path[d.size()]); |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 public boolean accept(Path path) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 if (path.isDirectory()) { |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
94 // either equals to or a parent of a directory we know about (i.e. configured dir is *nested* in supplied arg). |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
95 // Also, accept arg if it happened to be nested into configured dir (i.e. one of them is *parent* for the arg), |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
96 // and recursiveDirs is true. |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 for (Path d : dirs) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 switch(d.compareWith(path)) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 case Same : return true; |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
100 case ImmediateChild : |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
101 case Nested : return includeParentDirs; // path is parent to one of our locations |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
102 case ImmediateParent : |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
103 case Parent : return includeNestedDirs; // path is nested in one of our locations |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
106 if (!includeParentDirs) { |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
107 return false; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
108 } |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
109 // If one of configured files is nested under the path, and we shall report parents, accept. |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
110 // Note, I don't respect includeDirContent here as with file it's easy to add parent to paths explicitly, if needed. |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
111 // (if includeDirContent == .f and includeParentDirs == .f, directory than owns a scope file won't get reported) |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 for (Path f : files) { |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
113 CompareResult cr = f.compareWith(path); |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
114 if (cr == Nested || cr == ImmediateChild) { |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 return true; |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 } else { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 for (Path f : files) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 if (f.equals(path)) { |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 return true; |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 } |
443
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
124 // if interested in nested/recursive dirs, shall check if supplied file is under any of our configured locations |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
125 if (!includeNestedDirs && !includeDirContent) { |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
126 return false; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
127 } |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
128 for (Path d : dirs) { |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
129 CompareResult cr = d.compareWith(path); |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
130 if (includeNestedDirs && cr == Parent) { |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
131 // file is nested in one of our locations |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
132 return true; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
133 } |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
134 if (includeDirContent && cr == ImmediateParent) { |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
135 // file is right under one of our directories, and includeDirContents is .t |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
136 return true; |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
137 } |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
138 // try another directory |
072b5f3ed0c8
Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
229
diff
changeset
|
139 } |
229
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 return false; |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 } |