View Javadoc
1   /*
2    * Copyright (C) 2010, Google Inc.
3    * Copyright (C) 2010, Marc Strapetz <marc.strapetz@syntevo.com> and others
4    *
5    * This program and the accompanying materials are made available under the
6    * terms of the Eclipse Distribution License v. 1.0 which is available at
7    * https://www.eclipse.org/org/documents/edl-v10.php.
8    *
9    * SPDX-License-Identifier: BSD-3-Clause
10   */
11  
12  package org.eclipse.jgit.treewalk.filter;
13  
14  import org.eclipse.jgit.dircache.DirCacheEntry;
15  import org.eclipse.jgit.dircache.DirCacheIterator;
16  import org.eclipse.jgit.treewalk.TreeWalk;
17  
18  /**
19   * To be used in combination with a DirCacheIterator: includes only tree entries
20   * for which 'skipWorkTree' flag is not set.
21   */
22  public class SkipWorkTreeFilter extends TreeFilter {
23  
24  	/** Index of DirCacheIterator to work on. */
25  	private final int treeIdx;
26  
27  	/**
28  	 * Create a filter to work on the specified DirCacheIterator.
29  	 *
30  	 * @param treeIdx
31  	 *            index of DirCacheIterator to work on. If the index does not
32  	 *            refer to a DirCacheIterator, the filter will include all
33  	 *            entries.
34  	 */
35  	public SkipWorkTreeFilter(int treeIdx) {
36  		this.treeIdx = treeIdx;
37  	}
38  
39  	/** {@inheritDoc} */
40  	@Override
41  	public boolean include(TreeWalk walker) {
42  		DirCacheIterator i = walker.getTree(treeIdx, DirCacheIterator.class);
43  		if (i == null)
44  			return true;
45  
46  		DirCacheEntry e = i.getDirCacheEntry();
47  		return e == null || !e.isSkipWorkTree();
48  	}
49  
50  	/** {@inheritDoc} */
51  	@Override
52  	public boolean shouldBeRecursive() {
53  		return false;
54  	}
55  
56  	/** {@inheritDoc} */
57  	@Override
58  	public TreeFilter clone() {
59  		return this;
60  	}
61  
62  	/** {@inheritDoc} */
63  	@SuppressWarnings("nls")
64  	@Override
65  	public String toString() {
66  		return "SkipWorkTree(" + treeIdx + ")";
67  	}
68  }