Skip to contentSkip to conversation

Add (static) ignore functionality to EGit

RFC PATCH In review Ferry Huberts 6 participants 16 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover Add (static) ignore functionality to EGit

This is the first - early - code that adds ignore functionality to EGit. Currently it reads in all ignore patterns upon workspace startup into an ignore cache. From this cache the ignore state of a resource is evaluated in the same fashion as git does.

The code does not yet react to changes in ignore files but I'm planning to add that soon and I can share a lot of code for that.

I send this code to receive feedback and to give you insight into what I'm doing with it. I'm new both to EGit programming and Eclipse programming so there might be things that could be done more elegantly :-)

A few notes:
- The patches are rebased on the current master (e3440623)
- The order of the patches must be re-arranged, but that is rather easy. The correct order - once finished - would be:
Build up the ignore patterns cache upon workspace startup. Use the ignore patterns cache to determine ignores
Enable the ignore handling of the plugin
Optimise ignore evaluation
Do not set .git as a Team ignore pattern
- The core.excludesfile code is currently untested, the other code seems to be in a good state.
- There are a few FIXMEs in the code with questions and tasks. It's a work in progress and these will disappear.

Ferry Huberts (5):
Build up the ignore patterns cache upon workspace startup. Enable the ignore handling of the plugin Optimise ignore evaluation
Do not set .git as a Team ignore pattern
Use the ignore patterns cache to determine ignores

 org.spearce.egit.core/META-INF/MANIFEST.MF         |    1 +
 org.spearce.egit.core/plugin.xml                   |    6 -
 .../src/org/spearce/egit/core/ignores/DType.java   |   44 ++
 .../src/org/spearce/egit/core/ignores/Exclude.java |  243 +++++++++
 .../spearce/egit/core/ignores/GitIgnoreData.java   |  180 +++++++
 .../org/spearce/egit/core/ignores/IgnoreFile.java  |   82 +++
 .../egit/core/ignores/IgnoreFileOutside.java       |  543 ++++++++++++++++++++
 .../egit/core/ignores/IgnoreProjectCache.java      |  245 +++++++++
 .../egit/core/ignores/IgnoreRepositoryCache.java   |  358 +++++++++++++
 .../org/spearce/egit/core/op/TrackOperation.java   |    7 +-
 .../spearce/egit/core/project/GitProjectData.java  |    8 +
 .../decorators/DecoratableResourceAdapter.java     |   11 +-
 org.spearce.jgit/META-INF/MANIFEST.MF              |    1 +
 13 files changed, 1712 insertions(+), 17 deletions(-)
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/DType.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/Exclude.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/GitIgnoreData.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFile.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFileOutside.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreProjectCache.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreRepositoryCache.java
#1 lore raw

RFC PATCH 1/5 Build up the ignore patterns cache upon workspace startup.

Read in all relevant ignore files: all .gitignore files in the projects, all .gitignore files between the checkout directory and the project directories, the info/exclude ignore files of the repositories, the repository core.excludesfile ignore files and the global core.excludesfile ignore file.

---
 .../src/org/spearce/egit/core/ignores/Exclude.java |  158 ++++++
 .../spearce/egit/core/ignores/GitIgnoreData.java   |  139 +++++
 .../org/spearce/egit/core/ignores/IgnoreFile.java  |   82 +++
 .../egit/core/ignores/IgnoreFileOutside.java       |  543 ++++++++++++++++++++
 .../egit/core/ignores/IgnoreProjectCache.java      |  201 ++++++++
 .../egit/core/ignores/IgnoreRepositoryCache.java   |  308 +++++++++++
 .../spearce/egit/core/project/GitProjectData.java  |    5 +
 7 files changed, 1436 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/Exclude.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/GitIgnoreData.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFile.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFileOutside.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreProjectCache.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreRepositoryCache.java
org.spearce.egit.core/src/org/spearce/egit/core/ignores/Exclude.java new file +158 -0
new file mode 100644
index 0000000..c4c48e9
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (C) 2009, Ferry Huberts <[email protected]>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+package org.spearce.egit.core.ignores;
+
+import java.util.regex.Pattern;
+
+/**
+ * This class describes an ignore pattern in the same way as git does, with some
+ * extra information to support Eclipse specific functionality.
+ * 
+ * The git definition can be found in the source file dir.h, within the
+ * exclude_list structure definition. The code can be found in the source file
+ * dir.c:excluded_1
+ */
+class Exclude {
+	/** the pattern to match */
+	private String pattern = null;
+
+	/**
+	 * the directory in which the pattern is anchored, relative to the checkout
+	 * directory and with a trailing slash (except when in the checkout
+	 * directory, in which case it will be an empty string). Slashes are in Unix
+	 * format: forward slashes
+	 */
+	private String base = null;
+
+	/**
+	 * true when the resource must be excluded when matched, false in case of a
+	 * negative pattern: when it must be included
+	 */
+	private boolean to_exclude = true;
+
+	/** true when the resource must be a directory */
+	private boolean mustBeDir = false;
+
+	/** true when the pattern does not contain directories */
+	private boolean noDir = false;
+
+	/** true when the resource must end with pattern.substring(1) */
+	private boolean endsWith = false;
+
+	/** true when the pattern has no wildcards */
+	private boolean noWildcard = false;
+
+	/*
+	 * Extra Information
+	 */
+
+	/**
+	 * the full path name of the ignore file. Stored so that a user can ask
+	 * 'which pattern in which ignore file makes this resource be ignored?'
+	 */
+	private String ignoreFileAbsolutePath = null;
+
+	/**
+	 * the line number of the pattern in the ignore file. Stored for the same
+	 * reason as the ignoreFileFullPath field
+	 */
+	private int lineNumber = 0;
+
+	/**
+	 * Constructor. See the git source file dir.c, method add_exclude
+	 * 
+	 * @param pattern
+	 *            the pattern to match
+	 * @param base
+	 *            the directory in which the pattern is anchored, relative to
+	 *            the checkout directory and with a trailing slash (except when
+	 *            in the checkout directory, in which case it will be an empty
+	 *            string). Slashes are in Unix format: forward slashes
+	 * @param ignoreFileAbsolutePath
+	 *            the full path name of the ignore file. Stored so that a user
+	 *            can ask 'which pattern in which ignore file makes this
+	 *            resource be ignored?'
+	 * @param lineNumber
+	 *            the line number of the pattern in the ignore file. Stored for
+	 *            the same reason as the ignoreFileFullPath field
+	 */
+	Exclude(final String pattern, final String base,
+			final String ignoreFileAbsolutePath, final int lineNumber) {
+		this.pattern = pattern;
+		this.base = base;
+
+		this.to_exclude = !this.pattern.startsWith("!");
+		if (!this.to_exclude) {
+			this.pattern = this.pattern.substring(1);
+		}
+
+		this.mustBeDir = this.pattern.endsWith("/");
+		if (this.mustBeDir) {
+			this.pattern = this.pattern.substring(0, this.pattern.length() - 1);
+		}
+		this.noDir = !this.pattern.contains("/");
+		this.noWildcard = no_wildcard(this.pattern);
+		this.endsWith = ((this.pattern.charAt(0) == '*') && no_wildcard(this.pattern
+				.substring(1)));
+
+		this.ignoreFileAbsolutePath = ignoreFileAbsolutePath;
+		this.lineNumber = lineNumber;
+	}
+
+	/*
+	 * Private Methods
+	 */
+
+	private static Pattern wildcardPattern = Pattern
+			.compile("^.*[\\*\\?\\[\\{].*$");
+
+	/* dir.c::no_wildcard */
+	private boolean no_wildcard(final String string) {
+		return !wildcardPattern.matcher(string).matches();
+	}
+
+	/*
+	 * Getters / Setters
+	 */
+
+	public String getIgnoreFileAbsolutePath() {
+		return ignoreFileAbsolutePath;
+	}
+
+	public int getLineNumber() {
+		return lineNumber;
+	}
+
+	/**
+	 * @return the base
+	 */
+	public String getBase() {
+		return base;
+	}
+
+	/**
+	 * @return the noDir
+	 */
+	public boolean isNoDir() {
+		return noDir;
+	}
+
+	/**
+	 * @return the endsWith
+	 */
+	public boolean isEndsWith() {
+		return endsWith;
+	}
+
+	/**
+	 * @return the noWildcard
+	 */
+	public boolean isNoWildcard() {
+		return noWildcard;
+	}
+}
\ No newline at end of file
org.spearce.egit.core/src/org/spearce/egit/core/ignores/GitIgnoreData.java new file +139 -0

139 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFile.java new file +82 -0

82 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFileOutside.java new file +543 -0

544 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreProjectCache.java new file +201 -0

202 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreRepositoryCache.java new file +308 -0

309 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +5 -0
index 31d5483..414bd83 100644
@@ -40,6 +40,7 @@
 import org.spearce.egit.core.CoreText;
 import org.spearce.egit.core.GitCorePreferences;
 import org.spearce.egit.core.GitProvider;
+import org.spearce.egit.core.ignores.GitIgnoreData;
 import org.spearce.jgit.lib.Repository;
 import org.spearce.jgit.lib.WindowCache;
 import org.spearce.jgit.lib.WindowCacheConfig;
@@ -64,9 +65,11 @@ public void resourceChanged(final IResourceChangeEvent event) {
 			switch (event.getType()) {
 			case IResourceChangeEvent.PRE_CLOSE:
 				uncache((IProject) event.getResource());
+				GitIgnoreData.uncacheProject(event.getResource());
 				break;
 			case IResourceChangeEvent.PRE_DELETE:
 				delete((IProject) event.getResource());
+				GitIgnoreData.uncacheProject(event.getResource());
 				break;
 			default:
 				break;
@@ -84,6 +87,7 @@ public void resourceChanged(final IResourceChangeEvent event) {
 	 */
 	public static void attachToWorkspace(final boolean includeChange) {
 		trace("attachToWorkspace - addResourceChangeListener");
+		GitIgnoreData.importWorkspaceIgnores();
 		ResourcesPlugin.getWorkspace().addResourceChangeListener(
 				rcl,
 				(includeChange ? IResourceChangeEvent.POST_CHANGE : 0)
@@ -97,6 +101,7 @@ public static void attachToWorkspace(final boolean includeChange) {
 	public static void detachFromWorkspace() {
 		trace("detachFromWorkspace - removeResourceChangeListener");
 		ResourcesPlugin.getWorkspace().removeResourceChangeListener(rcl);
+		GitIgnoreData.clear();
 	}
 
 	/**
Signature · 1 line
1.6.0.6
#2 lore raw

RFC PATCH 2/5 Enable the ignore handling of the plugin

---
 org.spearce.egit.core/META-INF/MANIFEST.MF         |    1 +
 .../org/spearce/egit/core/op/TrackOperation.java   |    6 +++---
 .../decorators/DecoratableResourceAdapter.java     |    4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)
org.spearce.egit.core/META-INF/MANIFEST.MF +1 -0
index 20df15f..546ea72 100644
@@ -13,6 +13,7 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.core.filesystem,
  org.eclipse.ui
 Export-Package: org.spearce.egit.core,
+ org.spearce.egit.core.ignores;x-friends:="org.spearce.egit.ui",
  org.spearce.egit.core.internal.storage;x-friends:="org.spearce.egit.ui",
  org.spearce.egit.core.internal.util;x-friends:="org.spearce.egit.ui",
  org.spearce.egit.core.op,
org.spearce.egit.core/src/org/spearce/egit/core/op/TrackOperation.java +3 -3
index 29b4344..4a4b93c 100644
@@ -24,9 +24,9 @@
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.team.core.Team;
 import org.spearce.egit.core.Activator;
 import org.spearce.egit.core.CoreText;
+import org.spearce.egit.core.ignores.GitIgnoreData;
 import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.jgit.lib.GitIndex;
 import org.spearce.jgit.lib.GitIndex.Entry;
@@ -96,12 +96,12 @@ public boolean visit(IResource resource) throws CoreException {
 									// by explicitly selecting and invoking track on it.
 									if (resource.getType() == IResource.FILE) {
 										Entry entry = index.getEntry(repoPath);
-										if (!Team.isIgnoredHint(resource) || entry != null && entry.isAssumedValid()) {
+										if (!GitIgnoreData.isIgnored(resource) || ((entry != null) && entry.isAssumedValid())) {
 											entry = index.add(rm.getWorkDir(), new File(rm.getWorkDir(), repoPath));
 											entry.setAssumeValid(false);
 										}
 									}
-									if (Team.isIgnoredHint(resource))
+									if (GitIgnoreData.isIgnored(resource))
 										return false;
 
 								} catch (IOException e) {
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/DecoratableResourceAdapter.java +2 -2
index 5c68d5b..4c740d5 100644
@@ -22,10 +22,10 @@
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.team.core.Team;
 import org.spearce.egit.core.AdaptableFileTreeIterator;
 import org.spearce.egit.core.ContainerTreeIterator;
 import org.spearce.egit.core.ContainerTreeIterator.ResourceEntry;
+import org.spearce.egit.core.ignores.GitIgnoreData;
 import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.egit.ui.Activator;
 import org.spearce.egit.ui.UIPreferences;
@@ -363,7 +363,7 @@ private static boolean timestampMatches(DirCacheEntry indexEntry,
 
 	private static boolean isIgnored(IResource resource) {
 		// TODO: Also read ignores from .git/info/excludes et al.
-		return Team.isIgnoredHint(resource);
+		return GitIgnoreData.isIgnored(resource);
 	}
 
 	public String getName() {
Signature · 1 line
1.6.0.6
#3 lore raw

RFC PATCH 3/5 Optimise ignore evaluation

Do not call GitIgnoreData.isIgnored(resource) multiple times when not needed.

---
 .../org/spearce/egit/core/op/TrackOperation.java   |    5 +++--
 .../decorators/DecoratableResourceAdapter.java     |    9 ++-------
 2 files changed, 5 insertions(+), 9 deletions(-)
org.spearce.egit.core/src/org/spearce/egit/core/op/TrackOperation.java +3 -2
index 4a4b93c..a64c1dd 100644
@@ -94,14 +94,15 @@ public boolean visit(IResource resource) throws CoreException {
 									// first. If a resource within a ignored folder is marked
 									// we ignore it here, i.e. there is no way to unmark it expect
 									// by explicitly selecting and invoking track on it.
+									boolean ignored = GitIgnoreData.isIgnored(resource);
 									if (resource.getType() == IResource.FILE) {
 										Entry entry = index.getEntry(repoPath);
-										if (!GitIgnoreData.isIgnored(resource) || ((entry != null) && entry.isAssumedValid())) {
+										if (!ignored || ((entry != null) && entry.isAssumedValid())) {
 											entry = index.add(rm.getWorkDir(), new File(rm.getWorkDir(), repoPath));
 											entry.setAssumeValid(false);
 										}
 									}
-									if (GitIgnoreData.isIgnored(resource))
+									if (ignored)
 										return false;
 
 								} catch (IOException e) {
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/DecoratableResourceAdapter.java +2 -7
index 4c740d5..7b48fd8 100644
@@ -118,7 +118,7 @@ private void extractResourceProperties(TreeWalk treeWalk) {
 		if (resourceEntry == null)
 			return;
 
-		if (isIgnored(resourceEntry.getResource())) {
+		if (GitIgnoreData.isIgnored(resourceEntry.getResource())) {
 			ignored = true;
 			return;
 		}
@@ -261,7 +261,7 @@ public boolean shouldBeRecursive() {
 
 	private void extractContainerProperties(TreeWalk treeWalk) throws IOException {
 
-		if (isIgnored(resource)) {
+		if (GitIgnoreData.isIgnored(resource)) {
 			ignored = true;
 			return;
 		}
@@ -361,11 +361,6 @@ private static boolean timestampMatches(DirCacheEntry indexEntry,
 		}
 	}
 
-	private static boolean isIgnored(IResource resource) {
-		// TODO: Also read ignores from .git/info/excludes et al.
-		return GitIgnoreData.isIgnored(resource);
-	}
-
 	public String getName() {
 		return resource.getName();
 	}
Signature · 1 line
1.6.0.6
#4 lore raw

RFC PATCH 4/5 Do not set .git as a Team ignore pattern

The .git ignore pattern is only valid in the context that it matches a .git directory that is actually a repository.

---
 org.spearce.egit.core/plugin.xml |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
org.spearce.egit.core/plugin.xml +0 -6
index 77ecebf..ff24ac7 100644
@@ -11,10 +11,4 @@
 		id="org.spearce.egit.core.GitProvider">
 	</repository>
   </extension>
-  <extension
-        point="org.eclipse.team.core.ignore">
-     <ignore
-           enabled="true"
-           pattern=".git"/>
-  </extension>   
 </plugin>
Signature · 1 line
1.6.0.6
#5 lore raw

RFC PATCH 5/5 Use the ignore patterns cache to determine ignores

---
 .../src/org/spearce/egit/core/ignores/DType.java   |   44 ++++++
 .../src/org/spearce/egit/core/ignores/Exclude.java |  143 ++++++++++++++++----
 .../spearce/egit/core/ignores/GitIgnoreData.java   |   43 ++++++-
 .../egit/core/ignores/IgnoreProjectCache.java      |   44 ++++++
 .../egit/core/ignores/IgnoreRepositoryCache.java   |   68 ++++++++--
 .../spearce/egit/core/project/GitProjectData.java  |    3 +
 org.spearce.jgit/META-INF/MANIFEST.MF              |    1 +
 7 files changed, 307 insertions(+), 39 deletions(-)
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/DType.java
org.spearce.egit.core/src/org/spearce/egit/core/ignores/DType.java new file +44 -0
new file mode 100644
index 0000000..5661dca
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (C) 2009, Ferry Huberts <[email protected]>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+package org.spearce.egit.core.ignores;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * This class describes a file type in the same way as git does.
+ * 
+ * The git definition can be found in the source file cache.h. The code can be
+ * found in the source file dir.c:get_dtype
+ */
+enum DType {
+	DT_UNKNOWN, DT_DIR, DT_REG, DT_LINK;
+
+	/*
+	 * Interface Methods
+	 */
+
+	static DType get(final IResource resource) {
+		if (resource == null) {
+			return DT_UNKNOWN;
+		}
+		if (resource instanceof IFile) {
+			return DT_REG;
+		}
+		if ((resource instanceof IFolder) || (resource instanceof IProject)) {
+			return DT_DIR;
+		}
+		if (resource.isLinked()) {
+			return DT_LINK;
+		}
+
+		return DT_UNKNOWN;
+	}
+}
\ No newline at end of file
org.spearce.egit.core/src/org/spearce/egit/core/ignores/Exclude.java +114 -29

167 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ignores/GitIgnoreData.java +42 -1

59 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreProjectCache.java +44 -0

55 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreRepositoryCache.java +59 -9

93 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +3 -0
index 414bd83..09766b6 100644
@@ -63,6 +63,9 @@
 		@SuppressWarnings("synthetic-access")
 		public void resourceChanged(final IResourceChangeEvent event) {
 			switch (event.getType()) {
+			case IResourceChangeEvent.POST_CHANGE:
+				// GitIgnoreData.processChangesForIgnores(event);
+				break;
 			case IResourceChangeEvent.PRE_CLOSE:
 				uncache((IProject) event.getResource());
 				GitIgnoreData.uncacheProject(event.getResource());
org.spearce.jgit/META-INF/MANIFEST.MF +1 -0
index 3344c3c..e5f6478 100644
@@ -7,6 +7,7 @@ Bundle-Localization: plugin
 Bundle-Vendor: %provider_name
 Export-Package: org.spearce.jgit.dircache,
  org.spearce.jgit.errors;uses:="org.spearce.jgit.lib",
+ org.spearce.jgit.fnmatch,
  org.spearce.jgit.lib,
  org.spearce.jgit.revplot,
  org.spearce.jgit.revwalk,
Signature · 1 line
1.6.0.6
#7 lore raw
Quoted 4 lines · Robin Rosenberg

A quick reply (I might come up with more later): Ignore support should be mostly in jgit, with only extensions into egit.

-- robin

I discussed this with shawn and proposed to first implement it in egit and when we have it right then move it into jgit. I think shawn agreed with that.

Ferry

#8 lore raw
Quoted 7 lines · Ferry Huberts (Pelagic)
Quoted 3 lines · Robin Rosenberg

A quick reply (I might come up with more later): Ignore support should be mostly in jgit, with only extensions into egit.

I discussed this with shawn and proposed to first implement it in egit and when we have it right then move it into jgit. I think shawn agreed with that.

I may have agreed with it. My memory isn't *that* good. :-)

In general principal I agree with Robin, Git specific handling should be in JGit as much as possible so we can reuse the logic in more applications than just EGit.

But it may have been easier to get a first working prototype by doing the code in EGit, and later pulling some of it down into JGit as we identity what isn't EGit specific.

The problem with that is the dual licenses; code in EGit can't be pulled down to JGit without relicensing it under the BSD. Only the original author of the code can do that. So if you contribute ignore support to EGit under the EPL which is better placed in JGit, Robin or myself can't pull it down ourselves, we'd have to rewrite it.

But even rewriting may be difficult, as the rewrite may be too close to the original (same language, same surrounding code, likely going to produce a similar result).

Signature · 1 line
Shawn.
#9 lore raw
In reply to Ferry Huberts
Quoted 55 lines · Ferry Huberts

This is the first - early - code that adds ignore functionality to EGit. Currently it reads in all ignore patterns upon workspace startup into an ignore cache. From this cache the ignore state of a resource is evaluated in the same fashion as git does.

The code does not yet react to changes in ignore files but I'm planning to add that soon and I can share a lot of code for that.

I send this code to receive feedback and to give you insight into what I'm doing with it. I'm new both to EGit programming and Eclipse programming so there might be things that could be done more elegantly :-)

A few notes:
- The patches are rebased on the current master (e3440623)
- The order of the patches must be re-arranged, but that is rather easy. The correct order - once finished - would be:
Build up the ignore patterns cache upon workspace startup. Use the ignore patterns cache to determine ignores
Enable the ignore handling of the plugin
Optimise ignore evaluation
Do not set .git as a Team ignore pattern
- The core.excludesfile code is currently untested, the other code seems to be in a good state.
- There are a few FIXMEs in the code with questions and tasks. It's a work in progress and these will disappear.

Ferry Huberts (5):
Build up the ignore patterns cache upon workspace startup. Enable the ignore handling of the plugin Optimise ignore evaluation
Do not set .git as a Team ignore pattern
Use the ignore patterns cache to determine ignores

 org.spearce.egit.core/META-INF/MANIFEST.MF         |    1 +
 org.spearce.egit.core/plugin.xml                   |    6 -
 .../src/org/spearce/egit/core/ignores/DType.java   |   44 ++
 .../src/org/spearce/egit/core/ignores/Exclude.java |  243 +++++++++
 .../spearce/egit/core/ignores/GitIgnoreData.java   |  180 +++++++
 .../org/spearce/egit/core/ignores/IgnoreFile.java  |   82 +++
 .../egit/core/ignores/IgnoreFileOutside.java       |  543 ++++++++++++++++++++
 .../egit/core/ignores/IgnoreProjectCache.java      |  245 +++++++++
 .../egit/core/ignores/IgnoreRepositoryCache.java   |  358 +++++++++++++
 .../org/spearce/egit/core/op/TrackOperation.java   |    7 +-
 .../spearce/egit/core/project/GitProjectData.java  |    8 +
 .../decorators/DecoratableResourceAdapter.java     |   11 +-
 org.spearce.jgit/META-INF/MANIFEST.MF              |    1 +
 13 files changed, 1712 insertions(+), 17 deletions(-)
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/DType.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/Exclude.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/GitIgnoreData.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFile.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreFileOutside.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreProjectCache.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/ignores/IgnoreRepositoryCache.java
Quoted 8 lines

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Eclipse supplies a repository-independent ignore file list as part of the repository-type independent Team support. A first step, which would provide useful functionality would be to populate your cache with this list and enable it's use in the Egit plugin. This would accomplish the goal of enabling EGit to use ignore lists in an immediately useful way with minimal effort. As a second stage you can add support for picking up Git specific files and updating them from Eclipse.

I think you will run into problems if you try to create a workspace wide cache. It is quite possible that one workspace could have projects that target different Git repositories. This means that your cache would need to look at all projects in the workspace and potentially take into account Eclipse working sets and other such complications. You also will need to deal with projects being added and deleted from the Eclipse workspace.

I think a better approach might be to go for lazy cache construction where the cache is built only when actually needed by a user operation. The cache would then be built only for a specific Git repository. JGit should be responsible for assembling a merged list from the various Git files. It should also be responsible for the actual updating of the various Git ignore files. Since I believe that the Eclipse repository-independent ignore file list should be the lowest priority in the merged list, it will be necessary to pass the Eclipse list to JGit as a parameter whenever a merged list is required.

In general, you should look to do Git specific things in JGit and do Eclipse things in Eclipse. That way JGit continues to acquire the functionality to support any IDE and EGit is kept as simple as possible.

HTH

Jonathan Gossage

#10 lore raw

måndag 30 mars 2009 02:40:59 skrev Jonathan Gossage <[email protected]>:

Quoted 2 lines

Ferry Huberts wrote:
Eclipse supplies a repository-independent ignore file list as part of the repository-type independent Team support. A first step, which would provide useful functionality would be to populate your cache with this list and enable it's use in the Egit plugin. This would accomplish the goal of enabling EGit to use ignore lists in an immediately useful way with minimal effort. As a second stage you can add support for picking up Git specific files and updating them from Eclipse.

The current EGit obeys the Eclipse ignore rules already, so no there is no need to hurry just for that feature.

-- robin

#11 lore raw
In reply to Ferry Huberts
Quoted 11 lines · Ferry Huberts

This is the first - early - code that adds ignore functionality to EGit. Currently it reads in all ignore patterns upon workspace startup into an ignore cache. From this cache the ignore state of a resource is evaluated in the same fashion as git does.

The code does not yet react to changes in ignore files but I'm planning to add that soon and I can share a lot of code for that.

I send this code to receive feedback and to give you insight into what I'm doing with it. I'm new both to EGit programming and Eclipse programming so there might be things that could be done more elegantly :-)

Ok, I finally got a chance to review this series.

We really want as much of the Git specific logic as we can in JGit under the BSD license. This has already been raised elsewhere in this thread.

JGit and EGit are holding the line on Java 5 support; that means that String.isEmpty() must be spelled as String.length() == 0 (isEmpty was added in Java 6).

Style nit: Don't put /* Constructors */, /* Methods */ or
/ * Public Methods */ comments in code, e.g. IgnoreProjectCache l.52-54 or GitIgnoreData l.58-61.

Style nit: Don't assign fields to their default values.

E.g. Exclude.java l.25,33,42,.. these are being set to the same value that the JRE sets the field to if the field is not explicitly initialized. We find it much easier to read code when the defaults are assumed.

Style nit: Don't use "this." to refer to members.

Your IDE should highlight field references differently than parameters, and a parameter should never shadow a field name, thus "this." is unnecessary and makes the code much more verbose to read. E.g. see Exclude.java 's constructor on l.87-108; I can't see the forest (the code) due to all the trees (this.) appearing.

IgnoreFileOutside: Ugh, our own implementation of IFile ?

I'm worried about the long-term stability of the IFile API. Is it really frozen enough that we can implement it ourselves? Of course, this may be moot if much of the code was moved back to JGit.

IgnoreRepositoryCache: Why not put this into RepositoryMapping?

Instead of caching it inside a static HashMap of GitIgnoreData, wouldn't it be better to put it into RepositoryMapping? The TrackOperation for example already has the RepositoryMapping handle in scope, saving a few lookup operations, and avoiding needing to manage this new additional static HashMap against leaks.

I kind of wanted to tie exclude processing (and attribute processing) into a TreeWalk, so that we can do an n-way merge against trees and working directories by tossing all of their AbstractTreeIterators into a single walk, possibly apply a path filter, and let the walk handle the per-directory ignore rules as it goes.

Most of your code seems to be built around the Eclipse IResource model, and the idea that it gets called for a single file path at a time, which may make it less efficient when we put it into a TreeWalk and apply the notion of entering and exiting a subdirectory.

OK, that's about all I have for now. Its reasonable, but still an early series.

Signature · 1 line
Shawn.
#12 lore raw
Quoted 13 lines · Shawn O. Pearce
Quoted 11 lines · Ferry Huberts

This is the first - early - code that adds ignore functionality to EGit. Currently it reads in all ignore patterns upon workspace startup into an ignore cache. From this cache the ignore state of a resource is evaluated in the same fashion as git does.

The code does not yet react to changes in ignore files but I'm planning to add that soon and I can share a lot of code for that.

I send this code to receive feedback and to give you insight into what I'm doing with it. I'm new both to EGit programming and Eclipse programming so there might be things that could be done more elegantly :-)

Quoted 7 lines

Ok, I finally got a chance to review this series.

We really want as much of the Git specific logic as we can in JGit under the BSD license. This has already been raised elsewhere in this thread.

ack.

Quoted 3 lines

JGit and EGit are holding the line on Java 5 support; that means that String.isEmpty() must be spelled as String.length() == 0 (isEmpty was added in Java 6).

ok

Quoted 5 lines

Style nit: Don't put /* Constructors */, /* Methods */ or
/ * Public Methods */ comments in code, e.g. IgnoreProjectCache l.52-54 or GitIgnoreData l.58-61.

ok

Quoted 7 lines

Style nit: Don't assign fields to their default values.

E.g. Exclude.java l.25,33,42,.. these are being set to the same value that the JRE sets the field to if the field is not explicitly initialized. We find it much easier to read code when the defaults are assumed.

ok

Quoted 8 lines

Style nit: Don't use "this." to refer to members.

Your IDE should highlight field references differently than parameters, and a parameter should never shadow a field name, thus "this." is unnecessary and makes the code much more verbose to read. E.g. see Exclude.java 's constructor on l.87-108; I can't see the forest (the code) due to all the trees (this.) appearing.

ok

Quoted 7 lines

IgnoreFileOutside: Ugh, our own implementation of IFile ?

I'm worried about the long-term stability of the IFile API. Is it really frozen enough that we can implement it ourselves? Of course, this may be moot if much of the code was moved back to JGit.

when we convert the code to be in jgit we will not use this api. this will disappear.

Quoted 8 lines

IgnoreRepositoryCache: Why not put this into RepositoryMapping?

Instead of caching it inside a static HashMap of GitIgnoreData, wouldn't it be better to put it into RepositoryMapping? The TrackOperation for example already has the RepositoryMapping handle in scope, saving a few lookup operations, and avoiding needing to manage this new additional static HashMap against leaks.

ok

Quoted 7 lines

I kind of wanted to tie exclude processing (and attribute processing) into a TreeWalk, so that we can do an n-way merge against trees and working directories by tossing all of their AbstractTreeIterators into a single walk, possibly apply a path filter, and let the walk handle the per-directory ignore rules as it goes.

ok. but I need much more input than that from you on how to go about moving the code into jgit. If you have ideas on what the rough architecture should be of the ignore processing in jgit then please let me know, I don't know that code at all and also don't know the approach you'd like to take there with its architecture.

I've been thinking on and off about how to free the ignore processing from eclipse specific apis ever since the egit/jgit issue came up. I think it's not that hard to do, depending on the approach you'd like to take.

you talk about TreeWalk. but what is it's prupose, in what context is it called? etc. You can probably much faster explain that to me than I can find out from the code (the egit code is much easier to place in context than the jgit code I think)

Quoted 5 lines

Most of your code seems to be built around the Eclipse IResource model, and the idea that it gets called for a single file path at a time, which may make it less efficient when we put it into a TreeWalk and apply the notion of entering and exiting a subdirectory.

the way it works now is more efficient than git itself (most of the time), since we have a cache of the ignore patterns. I compared traces of git itself and the plugin against eachother.

Quoted 4 lines

OK, that's about all I have for now. Its reasonable, but still an early series.

yep.
please let's discuss moving it into jgit asap. so that I can complete the feature.

BTW
In the meantime I've also added ignore preferences to the plugin on which the user can specify whether the Eclipse Team Ignored Resources should be taken into account. It defaults to yes. When set to no the ignore processing complies strict to git behaviour.

looking forward to your input!

Ferry

#13 lore raw
In reply to Shawn O. Pearce
Quoted 3 lines · Shawn O. Pearce

JGit and EGit are holding the line on Java 5 support; that means that String.isEmpty() must be spelled as String.length() == 0 (isEmpty was added in Java 6).

just looked in the project settings for org.spearce.egit.core and it has java 1.5 style specified _and_ eclipse does not give me a warning on the *.isEmpty() calls. Am i missing something here?

#14 lore raw
Quoted 8 lines · Ferry Huberts (Pelagic)
Quoted 3 lines · Shawn O. Pearce

JGit and EGit are holding the line on Java 5 support; that means that String.isEmpty() must be spelled as String.length() == 0 (isEmpty was added in Java 6).

just looked in the project settings for org.spearce.egit.core and it has java 1.5 style specified _and_ eclipse does not give me a warning on the *.isEmpty() calls. Am i missing something here?

Your workspace default JRE must be set to a Java 6. Switch it to Java 5 in the workspace settings.

Signature · 1 line
Shawn.