* [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules.
@ 2008-05-10 13:00 Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 01/22] Start of an implementation of a git like command line tool Florian Koeberle
` (22 more replies)
0 siblings, 23 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git
Hi
here are the patches.
The implementation does a lot of performance optimizations:
1.) Instead of checking all the rules from top to bottom, I simply take the first matching rule beginning from bottom. I actually have intern a list with a inversed order and take then the first matching rule.
2.) Each sub directory has it's own optimized rules.
2.1.) Rules which can never match are removed. e.g. There is no need to check the rule "/a" in the directory b.
2.2.) The list is cut at the first rule which match always. *.txt\n/a for example would result in an internal list "ignore all, ignore *.txt" which is then reduced to "ignore all".
2.3.) Ignore rules which are direcly before an "ignore all" all rule are removed. /a\n*.txt for example would result in an intern "ignore *.txt, ignore all" list which is then reduced to "ignore all",
2.4.) "do not ignore" rules at the bottom of the intern list are removed. This optimization would remove !a from "!a\n/b" as it is in the inversed list at the bottom.
2.5.) When converting the rule list into an instance of the Rules interface, rule lists with only one always matching rule are converted to Rules.IGNORE_NOTHING and Rules.IGNORE_ALL objects. These special objects avoid unessary object construction as they reuse themself for sub directories.
3.) Only rules are evaluated which could match at the current directory level. e.g. You don't need to check the rule /a/b/c for every file in /a, but only for files in the directory /a/b
4.) The Iterator doesn't walk into trees from which it knows that they will never match. It can do so by comparing the rules instance for the directory with the value of Rules.IGNORE_ALL.
Best regards,
Florian Koeberle
^ permalink raw reply [flat|nested] 35+ messages in thread
* [JGIT PATCH 01/22] Start of an implementation of a git like command line tool.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 02/22] Replaced Java 6 API useage with Java 5 equivalent Florian Koeberle
` (21 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Only the "help" command is currenly supported, but it is extendable.
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../src/org/spearce/jgit/pgm/Command.java | 40 +++++++
.../src/org/spearce/jgit/pgm/MainProgram.java | 114 ++++++++++++++++++++
2 files changed, 154 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/pgm/Command.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/Command.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/Command.java
new file mode 100644
index 0000000..cf66b20
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/Command.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.pgm;
+
+import java.io.IOException;
+
+/**
+ * A command have tasks like the "git-add", "git-help" or "git-init" console commands.
+ * Instances of ${link Command} must be immutable.
+ * @author Florian Köberle
+ *
+ */
+public interface Command {
+ /**
+ * Executes the specified Command.
+ * @param args the arguments which you would pass to the console equivalent of the command.
+ * @throws IOException for some undefined reasons.
+ */
+ public void execute(String... args) throws IOException;
+
+ /**
+ *
+ * @return a short description about what the command does. Short means in this context 5 - 10 words.
+ */
+ public String getShortDescription();
+}
\ No newline at end of file
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
new file mode 100644
index 0000000..72b0156
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.pgm;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * A program which works similar like the command git, except that very view
+ * arguments are supported jet.
+ *
+ * @author Florian Köberle
+ *
+ */
+public class MainProgram {
+ private final static Map<String, Command> commandNameToObjectMap;
+
+ static {
+ final Map<String, Command> commands = new HashMap<String, Command>();
+ commands.put("help", HelpCommand.INSTANCE);
+ commandNameToObjectMap = Collections.unmodifiableMap(commands);
+ }
+
+ /**
+ * Executes a command with some arguments. There are commands for creating
+ * git repositories, tracking files, etc.
+ *
+ * @param args
+ * The first argument specifies the command which should be
+ * executed. The other arguments are passed to the command.
+ * @throws IOException
+ * for some reasons.
+ */
+ public static void main(String[] args) throws IOException {
+ try {
+ if (args.length == 0) {
+ throw new WrongCallException("Require one argument!");
+ }
+ final Command command = commandNameToObjectMap.get(args[0]);
+ if (command == null) {
+ throw new WrongCallException("Require one argument!");
+ }
+ final String[] commandArguments = Arrays.copyOfRange(args, 1,
+ args.length);
+ command.execute(commandArguments);
+
+ } catch (WrongCallException e) {
+ System.err.println(e.getMessage());
+ System.err.println();
+ HelpCommand.INSTANCE.execute();
+ System.exit(1);
+ }
+ }
+
+ private static class WrongCallException extends Exception {
+ private static final long serialVersionUID = 3643362832429311084L;
+
+ WrongCallException(String message) {
+ super(message);
+ }
+ }
+
+ private static class HelpCommand implements Command {
+ /**
+ * Use this instance instead of creating a new ${link HelpCommand}. You
+ * don't need to create an instance of this class as it is immutable and
+ * not configurable.
+ */
+ public static HelpCommand INSTANCE = new HelpCommand();
+
+ public void execute(String... args) throws IOException {
+ System.out
+ .println("Call this program with the following arguments:");
+ System.out
+ .println("commandName commandArgument0 commandArgument1 ...");
+ System.out.println();
+ System.out
+ .println("Currently the following commands are supported:");
+ final SortedMap<String, Command> sortedCommandMap = new TreeMap<String, Command>(
+ MainProgram.commandNameToObjectMap);
+ for (Map.Entry<String, Command> commandEntry : sortedCommandMap
+ .entrySet()) {
+ final String commandName = commandEntry.getKey();
+ final String commandDescription = commandEntry.getValue()
+ .getShortDescription();
+ System.out.printf("%#10s - %s%n", commandName,
+ commandDescription);
+ }
+ }
+
+ public String getShortDescription() {
+ return "Displays some text about how to use this program.";
+ }
+ }
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 02/22] Replaced Java 6 API useage with Java 5 equivalent.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 01/22] Start of an implementation of a git like command line tool Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 03/22] Added a class Project which represents a project directory and it's repository Florian Koeberle
` (20 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../src/org/spearce/jgit/pgm/MainProgram.java | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
index 72b0156..69cd96f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
@@ -17,7 +17,6 @@
package org.spearce.jgit.pgm;
import java.io.IOException;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -59,8 +58,11 @@ public class MainProgram {
if (command == null) {
throw new WrongCallException("Require one argument!");
}
- final String[] commandArguments = Arrays.copyOfRange(args, 1,
- args.length);
+
+ final String[] commandArguments = new String[args.length - 1];
+ System.arraycopy(args, 1, commandArguments, 0,
+ commandArguments.length);
+
command.execute(commandArguments);
} catch (WrongCallException e) {
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 03/22] Added a class Project which represents a project directory and it's repository.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 01/22] Start of an implementation of a git like command line tool Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 02/22] Replaced Java 6 API useage with Java 5 equivalent Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:45 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 04/22] Added a "init" command to the git like command line tool Florian Koeberle
` (19 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../src/org/spearce/jgit/lib/GitPathConstants.java | 28 +++++++++
.../src/org/spearce/jgit/lib/Project.java | 63 ++++++++++++++++++++
.../src/org/spearce/jgit/lib/ProjectFactory.java | 57 ++++++++++++++++++
3 files changed, 148 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/GitPathConstants.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/ProjectFactory.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/GitPathConstants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/GitPathConstants.java
new file mode 100644
index 0000000..3d99d33
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/GitPathConstants.java
@@ -0,0 +1,28 @@
+package org.spearce.jgit.lib;
+
+/**
+ * Collection of constants related to the git repository directory layout.
+ *
+ */
+public class GitPathConstants {
+ /**
+ * The name of the repository directory in the project directory.
+ */
+ public static final String REPOSITORY_DIRECTORY_NAME = ".git";
+
+ /**
+ * Contains the name of the objects directory in the repository directory.
+ */
+ public static final String OBJECTS_DIRECTORY_NAME = "objects";
+
+ /**
+ * Contains the name of the refs directory in the repository directory.
+ */
+ public static final String REFS_DIRECTORY_NAME = "refs";
+
+ /**
+ * Contains the name of the HEAD file in the repository directory.
+ */
+ public static final String HEAD_FILE_NAME = "HEAD";
+
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
new file mode 100644
index 0000000..6e72486
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib;
+
+import java.io.File;
+
+/**
+ * Represents a project controlled by git. Use {@link ProjectFactory} in order to create an object of this class.
+ * @author Florian Köberle
+ *
+ */
+public class Project {
+ private final File directory;
+
+ private final Repository repository;
+
+ /**
+ * This constructor should be only used by the class {@link ProjectFactory}.
+ * @param directory defines the value of the directory field.
+ * @param repository defines the value of the repository field.
+ */
+ Project(File directory, Repository repository) {
+ this.directory = directory;
+ this.repository = repository;
+ }
+
+ /**
+ *
+ * @return the directory which contains the files of the project. Usually this directory contain a .git directory with the repository.
+ */
+ public File getDirectory() {
+ return directory;
+ }
+
+ /**
+ * @return the {@link Repository} object of the project.
+ */
+ public Repository getRepository() {
+ return repository;
+ }
+
+ /**
+ * Closes the git repository of this project.
+ */
+ public void closeRepository() {
+ repository.close();
+ }
+
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ProjectFactory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ProjectFactory.java
new file mode 100644
index 0000000..b4e5660
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ProjectFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib;
+
+import java.io.File;
+import java.io.IOException;
+import static org.spearce.jgit.lib.GitPathConstants.REPOSITORY_DIRECTORY_NAME;
+
+/**
+ * Creates a new {@link Project} and initialize a repository for it.
+ *
+ * @author Florian Köberle
+ *
+ */
+public class ProjectFactory {
+
+ /**
+ * @param projectDirectory
+ * the directory with the project files.
+ * @return a new project with a new and open repository.
+ * @throws IOException
+ * thrown by {@link Repository#create()}
+ */
+ public Project createProject(File projectDirectory) throws IOException {
+ final File gitDirectory = new File(projectDirectory, REPOSITORY_DIRECTORY_NAME);
+ if (gitDirectory.exists()) {
+ throw new IllegalArgumentException(
+ "Repository exists in given project directory.");
+ }
+ final Repository repository = new Repository(gitDirectory);
+ try {
+ repository.create();
+ return new Project(projectDirectory, repository);
+ } catch (RuntimeException e) {
+ repository.close();
+ throw e;
+ } catch (IOException e) {
+ repository.close();
+ throw e;
+ }
+ }
+
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 04/22] Added a "init" command to the git like command line tool.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (2 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 03/22] Added a class Project which represents a project directory and it's repository Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 05/22] Added ProjectSeeker class Florian Koeberle
` (18 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../src/org/spearce/jgit/pgm/InitCommand.java | 71 ++++++++++++++++++++
.../src/org/spearce/jgit/pgm/MainProgram.java | 1 +
2 files changed, 72 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/pgm/InitCommand.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/InitCommand.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/InitCommand.java
new file mode 100644
index 0000000..4bc7ca8
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/InitCommand.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.pgm;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.spearce.jgit.lib.Project;
+import org.spearce.jgit.lib.ProjectFactory;
+
+import static java.lang.String.format;
+
+/**
+ * This class is immutable. It's {@link #execute} method is used to create git
+ * repositories.
+ *
+ * @author Florian Köberle
+ *
+ */
+public class InitCommand implements Command {
+ /**
+ * Use this instance instead of creating a new ${link InitCommand}. You
+ * don't need to create an instance of this class as it is immutable and not
+ * configurable.
+ */
+ public static InitCommand INSTANCE = new InitCommand();
+
+ public void execute(String... args) throws IOException {
+ final String currentDirectoryPathString = System
+ .getProperty("user.dir");
+ if (currentDirectoryPathString == null) {
+ throw new IOException("Unable to get current working directory");
+ }
+ final File currentDirectoryPath = new File(currentDirectoryPathString);
+ if (!currentDirectoryPath.isDirectory()) {
+ final String message = format(
+ "No directory found at \"%s\". It was the current working directory at program start.",
+ currentDirectoryPathString);
+ throw new IOException(message);
+ }
+ final ProjectFactory projectFactory = new ProjectFactory();
+
+ final Project project = projectFactory
+ .createProject(currentDirectoryPath);
+ try {
+ System.out.printf("Created a git repository at: %s%n", project
+ .getRepository().getDirectory());
+ } finally {
+ project.closeRepository();
+ }
+
+ }
+
+ public String getShortDescription() {
+ return "Creates an empty git repository.";
+ }
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
index 69cd96f..7601f31 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
@@ -35,6 +35,7 @@ public class MainProgram {
static {
final Map<String, Command> commands = new HashMap<String, Command>();
+ commands.put("init", InitCommand.INSTANCE);
commands.put("help", HelpCommand.INSTANCE);
commandNameToObjectMap = Collections.unmodifiableMap(commands);
}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 05/22] Added ProjectSeeker class.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (3 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 04/22] Added a "init" command to the git like command line tool Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:45 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 06/22] Added the interface FilePattern Florian Koeberle
` (17 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../src/org/spearce/jgit/lib/Project.java | 5 +-
.../src/org/spearce/jgit/lib/ProjectSeeker.java | 118 ++++++++++++++++++++
2 files changed, 122 insertions(+), 1 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/ProjectSeeker.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
index 6e72486..f6b6a17 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
@@ -19,7 +19,10 @@ package org.spearce.jgit.lib;
import java.io.File;
/**
- * Represents a project controlled by git. Use {@link ProjectFactory} in order to create an object of this class.
+ * Represents a project controlled by git. Use {@link ProjectFactory} in order to create an object of this class. If you
+ * don't want to create a new repository, but need a new {@link Project}
+ * instance then use {@link ProjectSeeker}.
+ *
* @author Florian Köberle
*
*/
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ProjectSeeker.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ProjectSeeker.java
new file mode 100644
index 0000000..3aa5284
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ProjectSeeker.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib;
+
+import java.io.File;
+import java.io.IOException;
+import static org.spearce.jgit.lib.GitPathConstants.OBJECTS_DIRECTORY_NAME;
+import static org.spearce.jgit.lib.GitPathConstants.REPOSITORY_DIRECTORY_NAME;
+import static org.spearce.jgit.lib.GitPathConstants.REFS_DIRECTORY_NAME;
+import static org.spearce.jgit.lib.GitPathConstants.HEAD_FILE_NAME;
+
+/**
+ * Use this class to create instances of {@link Project}.
+ *
+ * @author Florian Köberle
+ *
+ */
+public class ProjectSeeker {
+
+ /**
+ * Find the git repository for the current working directory.
+ *
+ * @return a {@link Repository}.
+ * @throws IOException
+ * if the system property user.dir isn't set or if it is
+ * invalid.
+ */
+ public Project findProject() throws IOException {
+ final String workingDirectoryPath = System.getProperty("user.dir");
+ if (workingDirectoryPath == null) {
+ throw new IOException("unable to get working directory");
+ }
+ final File workingDirectoryFile = new File(workingDirectoryPath);
+ if (!workingDirectoryFile.exists()) {
+ throw new IOException("Working directory path is invalid");
+ }
+ return findProject(workingDirectoryFile);
+ }
+
+ /**
+ * Checks if a path is a valid git repository. Works similar like the method
+ * is_git_directory from the original setup.c file.
+ *
+ * @param directory
+ * the path which should be checked.
+ * @return true if the path is a valid git repository.
+ */
+ private boolean isRepository(File directory) {
+ if (!directory.isDirectory()) {
+ return false;
+ }
+
+ final File objectDirectory = new File(directory, OBJECTS_DIRECTORY_NAME);
+ if (!objectDirectory.isDirectory()) {
+ return false;
+ }
+
+ final File refsDirectory = new File(directory, REFS_DIRECTORY_NAME);
+ if (!refsDirectory.isDirectory()) {
+ return false;
+ }
+
+ final File head = new File(directory, HEAD_FILE_NAME);
+ if (!hasValidateHeadRef(head)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Checks for example if a path is a valid HEAD file. Should do the same
+ * like validate_headref from path.c.
+ *
+ * @param path
+ * is the path of the HEAD file.
+ * @return true if it has a valid head reference.
+ */
+ private static final boolean hasValidateHeadRef(File path) {
+ return true; // TODO stub. view int validate_headref(const char
+ // *path) at path.c
+ }
+
+ private Project findProject(File directory) throws IOException {
+ File currentDirectory = directory.getAbsoluteFile();
+ while (true) {
+ final File commonGitDirectory = new File(directory,
+ REPOSITORY_DIRECTORY_NAME);
+ if (isRepository(commonGitDirectory)) {
+ return new Project(currentDirectory, new Repository(
+ commonGitDirectory));
+ }
+
+ if (isRepository(currentDirectory)) {
+ return new Project(null, new Repository(currentDirectory));
+ }
+ currentDirectory = currentDirectory.getParentFile();
+ if (currentDirectory == null) {
+ throw new IOException("Can't find git repository");
+ }
+ }
+
+ }
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 06/22] Added the interface FilePattern.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (4 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 05/22] Added ProjectSeeker class Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 07/22] Added the class Rule Florian Koeberle
` (16 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/lib/fileiteration/FilePattern.java | 107 ++++++++++++++++++++
1 files changed, 107 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FilePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FilePattern.java
new file mode 100644
index 0000000..01edbd4
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FilePattern.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+/**
+ * A {@link FilePattern} can be used to check if files in a directory matches a
+ * pattern. It provides with the {@link #getPatternForSubDirectory(String)}
+ * method {@link FilePattern}s for sub directories.
+ *
+ * Implementations of this interface should be immutable.
+ *
+ * @author Florian Koeberle
+ *
+ */
+interface FilePattern {
+ /**
+ * This pattern instance matches always.
+ */
+ public static final FilePattern MATCH_ALWAYS = new FilePattern() {
+
+ public FilePattern getPatternForSubDirectory(String directoryName) {
+ return MATCH_ALWAYS;
+ }
+
+ public boolean match(String fileName, boolean fileIsDirectory) {
+ return true;
+ }
+
+ public boolean canMatchAtThisDirectoryLevel() {
+ return true;
+ }
+
+ public boolean isSameForSubDirectories() {
+ return true;
+ }
+ };
+
+ /**
+ * This pattern instance matches never.
+ */
+ public static final FilePattern MATCH_NEVER = new FilePattern() {
+
+ public FilePattern getPatternForSubDirectory(String directoryName) {
+ return MATCH_NEVER;
+ }
+
+ public boolean match(String fileName, boolean fileIsDirectory) {
+ return false;
+ }
+
+ public boolean canMatchAtThisDirectoryLevel() {
+ return false;
+ }
+
+ public boolean isSameForSubDirectories() {
+ return true;
+ }
+ };
+
+ /**
+ * @param fileName
+ * the name of the file or directory
+ * @param fileIsDirectory
+ * determines if the file is a directory.
+ * @return true if the pattern matches.
+ */
+ boolean match(String fileName, boolean fileIsDirectory);
+
+ /**
+ *
+ * @param directoryName
+ * the name of a subdirectory.
+ * @return a pattern which can be used to match files in sub directories. A
+ * user may check if the returned value is {@link #MATCH_NEVER} in
+ * order to do some performance optimizations.
+ *
+ */
+ FilePattern getPatternForSubDirectory(String directoryName);
+
+ /**
+ * This method can be used to generate an smaller list of rules, which can
+ * match.
+ *
+ * @return true if {@link #match(String, boolean)} returns always false.
+ */
+ boolean canMatchAtThisDirectoryLevel();
+
+ /**
+ * @return true if {@link #getPatternForSubDirectory(String)} returns true
+ * for every value.
+ */
+ boolean isSameForSubDirectories();
+}
\ No newline at end of file
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 07/22] Added the class Rule.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (5 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 06/22] Added the interface FilePattern Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 08/22] Added the iterface Rules Florian Koeberle
` (15 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../org/spearce/jgit/lib/fileiteration/Rule.java | 58 ++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rule.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rule.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rule.java
new file mode 100644
index 0000000..733bb6a
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rule.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+/**
+ * A Rule defines what to do with a files which match a specified
+ * {@link FilePattern}.
+ */
+class Rule {
+ private boolean ignoreAtMatch;
+
+ private FilePattern pattern;
+
+ Rule(boolean ignoreAtMatch, FilePattern pattern) {
+ this.ignoreAtMatch = ignoreAtMatch;
+ this.pattern = pattern;
+ }
+
+ FilePattern getPattern() {
+ return pattern;
+ }
+
+ boolean isIgnoreAtMatch() {
+ return ignoreAtMatch;
+ }
+
+ Rule getRuleForSubDirectory(String directoryName) {
+ final FilePattern subPattern = pattern
+ .getPatternForSubDirectory(directoryName);
+ if (subPattern == pattern) {
+ return this;
+ }
+ return new Rule(ignoreAtMatch, subPattern);
+ }
+
+ boolean canMatchAtThisDirectoryLevel() {
+ return pattern.canMatchAtThisDirectoryLevel();
+ }
+
+ boolean isSameForSubDirectories() {
+ return pattern.isSameForSubDirectories();
+ }
+
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 08/22] Added the iterface Rules.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (6 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 07/22] Added the class Rule Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:46 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 09/22] Added the class FileTreeIterator and a test for it Florian Koeberle
` (14 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../org/spearce/jgit/lib/fileiteration/Rules.java | 101 ++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rules.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rules.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rules.java
new file mode 100644
index 0000000..1334a22
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/Rules.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+/**
+ * A {@link Rules} instances defines ignore or do not ignore rules for files in
+ * a directory. It can't directly be used to match files in sub directories, but
+ * provides a method {@link #getRulesForSubDirectory}.
+ *
+ * @author Florian Köberle
+ *
+ */
+public interface Rules {
+
+ /**
+ * Provides the instance of {@link IgnoreAllRules}.
+ */
+ public static final Rules IGNORE_ALL = new IgnoreAllRules();
+
+ /**
+ * Provides the instance of {@link IgnoreNothingRules}.
+ */
+ public static final Rules IGNORE_NOTHING = new IgnoreNothingRules();
+
+ /**
+ * @param fileName
+ * the name of the file or directory.
+ * @param fileIsDirectory
+ * should be true if the file is a directory.
+ * @return true if the file or directory should be ignored.
+ */
+ public abstract boolean toIgnore(String fileName, boolean fileIsDirectory);
+
+ /**
+ * @param directoryName
+ * the sub directory for which you want an {@link Rules}
+ * instance.
+ * @return an {@link Rules} instance, which can be used to check files in
+ * the specified sub directory.
+ */
+ public abstract Rules getRulesForSubDirectory(String directoryName);
+
+ /**
+ * This implementation ignores everything.
+ */
+ public static final class IgnoreAllRules implements Rules {
+ private IgnoreAllRules() {
+ // declared to make the constructor private
+ }
+
+ public Rules getRulesForSubDirectory(String directoryName) {
+ return this;
+ }
+
+ public boolean toIgnore(String fileName, boolean fileIsDirectory) {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "ignore all rules";
+ }
+ }
+
+ /**
+ * This implementation ignores nothing.
+ */
+ public static final class IgnoreNothingRules implements Rules {
+ private IgnoreNothingRules() {
+ // declared to make the constructor private
+ }
+
+ public Rules getRulesForSubDirectory(String directoryName) {
+ return this;
+ }
+
+ public boolean toIgnore(String fileName, boolean fileIsDirectory) {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "ignore nothing rules";
+ }
+ }
+
+}
\ No newline at end of file
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 09/22] Added the class FileTreeIterator and a test for it.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (7 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 08/22] Added the iterface Rules Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 10/22] Added class FileTreeIterable Florian Koeberle
` (13 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../lib/fileiteration/FileTreeIteratorTest.java | 112 ++++++++++++++++++++
.../jgit/lib/fileiteration/FileTreeIterator.java | 110 +++++++++++++++++++
2 files changed, 222 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileTreeIteratorTest.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterator.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileTreeIteratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileTreeIteratorTest.java
new file mode 100644
index 0000000..a7384d3
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileTreeIteratorTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+public class FileTreeIteratorTest extends TestCase {
+ private String DIRECTORY_A_NAME = "a";
+
+ private String DIRECTORY_AB_NAME = "b";
+
+ private File projectDirectory;
+
+ private File fileB;
+
+ private File directoryA;
+
+ private File directoryAB;
+
+ private File fileABA;
+
+ private File directoryAC;
+
+ private File fileACA;
+
+ private File fileACB;
+
+ @Override
+ protected void setUp() throws Exception {
+ this.projectDirectory = File.createTempFile("FileTreeIteratorTest", "");
+ projectDirectory.delete();
+ projectDirectory.mkdir();
+ projectDirectory.deleteOnExit();
+
+ this.directoryA = new File(projectDirectory, DIRECTORY_A_NAME);
+ directoryA.mkdir();
+
+ this.directoryAB = new File(directoryA, DIRECTORY_AB_NAME);
+ directoryAB.mkdir();
+
+ this.fileABA = new File(directoryAB, "a.y");
+ fileABA.createNewFile();
+
+ this.directoryAC = new File(directoryA, "c");
+ this.directoryAC.mkdir();
+
+ this.fileACA = new File(directoryAC, "a.x");
+ fileACA.createNewFile();
+
+ this.fileACB = new File(directoryAC, "b.y");
+ fileACB.createNewFile();
+
+ this.fileB = new File(projectDirectory, "b.x");
+ fileB.createNewFile();
+ }
+
+ public void testFileTreeIterator() {
+ final Iterator<File> iterator = new FileTreeIterator(projectDirectory,
+ Rules.IGNORE_NOTHING, false);
+ final Set<File> actualPathes = new HashSet<File>();
+ while (iterator.hasNext()) {
+ final File next = iterator.next();
+ assertFalse(actualPathes.contains(next));
+ actualPathes.add(next);
+ }
+
+ final Set<File> expectedPathes = new HashSet<File>();
+ expectedPathes.add(directoryA);
+ expectedPathes.add(fileB);
+ expectedPathes.add(directoryAB);
+ expectedPathes.add(fileABA);
+ expectedPathes.add(directoryAC);
+ expectedPathes.add(fileACA);
+ expectedPathes.add(fileACB);
+ assertEquals(expectedPathes, actualPathes);
+
+ }
+
+ public void testFileTreeIteratorWithIgnoreAllRules() {
+ final Iterator<File> iterator = new FileTreeIterator(projectDirectory,
+ Rules.IGNORE_ALL, false);
+ final Set<File> actualPathes = new HashSet<File>();
+ while (iterator.hasNext()) {
+ final File next = iterator.next();
+ assertFalse(actualPathes.contains(next));
+ actualPathes.add(next);
+ }
+
+ assertEquals(0, actualPathes.size());
+
+ }
+
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterator.java
new file mode 100644
index 0000000..5e76739
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterator.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.io.File;
+import java.util.EmptyStackException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Stack;
+
+class FileTreeIterator implements Iterator<File> {
+ private final Stack<File> remainingPathes;
+
+ private final Stack<Directory> remainingDirectories;
+
+ /**
+ * Creates a new Iterator which allows to iterate over the content of the
+ * specified rootDirectory. The rootDirectory itself is never included.
+ *
+ * @param rootDirectory
+ * the directory tree to iterate over.
+ * @param ignoreRules
+ * defines which paths are included and which aren't.
+ * @param includeRootDirectory
+ * the iterator will return the rootDirectory if this is flag is
+ * true.
+ */
+ FileTreeIterator(File rootDirectory, Rules ignoreRules,
+ boolean includeRootDirectory) {
+ remainingPathes = new Stack<File>();
+ if (includeRootDirectory) {
+ remainingPathes.add(rootDirectory);
+ }
+ remainingDirectories = new Stack<Directory>();
+ remainingDirectories.add(new Directory(rootDirectory, ignoreRules));
+ }
+
+ public boolean hasNext() {
+ findMorePathesIfNessesary();
+ return !remainingPathes.empty();
+ }
+
+ void findMorePathesIfNessesary() {
+ if (remainingPathes.isEmpty()) {
+ findMorePathes();
+ }
+ }
+
+ void findMorePathes() {
+ while (!remainingDirectories.isEmpty() && remainingPathes.isEmpty()) {
+ final Directory directory = remainingDirectories.pop();
+ final File[] pathes = directory.path.listFiles();
+ for (File path : pathes) {
+ final boolean fileIsDirectory = path.isDirectory();
+ if (fileIsDirectory) {
+ final Rules subDirectoryIgnoreRules = directory.ignoreRules
+ .getRulesForSubDirectory(path.getName());
+ if (subDirectoryIgnoreRules != Rules.IGNORE_ALL) {
+ final Directory subDirectory = new Directory(path,
+ subDirectoryIgnoreRules);
+ remainingDirectories.add(subDirectory);
+ }
+ }
+ if (!directory.ignoreRules.toIgnore(path.getName(),
+ fileIsDirectory)) {
+ remainingPathes.add(path);
+ }
+ }
+ }
+ }
+
+ public File next() {
+ findMorePathesIfNessesary();
+ try {
+ return remainingPathes.pop();
+ } catch (EmptyStackException e) {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private class Directory {
+ final File path;
+
+ final Rules ignoreRules;
+
+ Directory(File path, Rules ignoreRules) {
+ this.path = path;
+ this.ignoreRules = ignoreRules;
+ }
+ }
+
+}
\ No newline at end of file
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 10/22] Added class FileTreeIterable.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (8 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 09/22] Added the class FileTreeIterator and a test for it Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 11/22] Added the class StarPattern Florian Koeberle
` (12 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/lib/fileiteration/FileTreeIterable.java | 48 ++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterable.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterable.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterable.java
new file mode 100644
index 0000000..6922162
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileTreeIterable.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.io.File;
+import java.util.Iterator;
+
+/**
+ * Use this class to iterate over some by rules determined files in a project
+ * directory.
+ *
+ * @author Florian Köberle
+ *
+ */
+class FileTreeIterable implements Iterable<File> {
+ private final File projectDirectory;
+
+ private final Rules ignoreRules;
+
+ private final boolean includeRootDirectory;
+
+ FileTreeIterable(File projectDirectory, Rules ignoreRules,
+ boolean includeRootDirectory) {
+ this.projectDirectory = projectDirectory;
+ this.ignoreRules = ignoreRules;
+ this.includeRootDirectory = includeRootDirectory;
+ }
+
+ public Iterator<File> iterator() {
+ return new FileTreeIterator(projectDirectory, ignoreRules,
+ includeRootDirectory);
+ }
+
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 11/22] Added the class StarPattern.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (9 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 10/22] Added class FileTreeIterable Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 12/22] Added the class GlobalFilePattern Florian Koeberle
` (11 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/lib/fileiteration/StarPattern.java | 50 ++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/StarPattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/StarPattern.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/StarPattern.java
new file mode 100644
index 0000000..bd773ef
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/StarPattern.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.util.regex.Pattern;
+
+class StarPattern {
+
+ private final Pattern regexPattern;
+
+ private final String stringPattern;
+
+ StarPattern(String starPattern) {
+ if (starPattern.contains("*")) {
+ String regularExpression = starPattern;
+ regularExpression = regularExpression.replace(".", "[.]");
+ regularExpression = regularExpression.replace("*", ".*");
+ this.regexPattern = Pattern.compile(regularExpression);
+ this.stringPattern = null;
+ } else {
+ this.regexPattern = null;
+ this.stringPattern = starPattern;
+ }
+
+ }
+
+ boolean matches(String stringToMatch) {
+ if (regexPattern != null) {
+ return regexPattern.matcher(stringToMatch).matches();
+ } else if (stringPattern != null) {
+ return stringPattern.equals(stringToMatch);
+ }
+ throw new IllegalStateException("Oops, this should never happen.");
+ }
+
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 12/22] Added the class GlobalFilePattern
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (10 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 11/22] Added the class StarPattern Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 13/22] Added the class ComplexFilePattern Florian Koeberle
` (10 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/lib/fileiteration/GlobalFilePattern.java | 50 ++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/GlobalFilePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/GlobalFilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/GlobalFilePattern.java
new file mode 100644
index 0000000..92b133f
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/GlobalFilePattern.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+class GlobalFilePattern implements FilePattern {
+ private final StarPattern starPattern;
+
+ private final boolean matchDirectoriesOnly;
+
+ GlobalFilePattern(String starPatternString, boolean matchDirectoriesOnly) {
+ this.starPattern = new StarPattern(starPatternString);
+ 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 starPattern.matches(fileName);
+ }
+
+ public boolean isSameForSubDirectories() {
+ return false;
+ }
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 13/22] Added the class ComplexFilePattern.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (11 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 12/22] Added the class GlobalFilePattern Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 14/22] Added the class IgnoreRuleListFactory Florian Koeberle
` (9 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/lib/fileiteration/ComplexFilePattern.java | 89 ++++++++++++++++++++
1 files changed, 89 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/ComplexFilePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/ComplexFilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/ComplexFilePattern.java
new file mode 100644
index 0000000..e658d45
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/ComplexFilePattern.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.util.List;
+import java.util.ArrayList;
+
+class ComplexFilePattern implements FilePattern {
+ /**
+ * Can contain String and
+ */
+ private final List<StarPattern> usedPatternList;
+
+ private final boolean matchDirectoriesOnly;
+
+ private final int offset;
+
+ private ComplexFilePattern(List<StarPattern> List,
+ boolean matchDirectoriesOnly, int offset) {
+ this.usedPatternList = List;
+ this.matchDirectoriesOnly = matchDirectoriesOnly;
+ this.offset = offset;
+ }
+
+ ComplexFilePattern(List<String> patternStrings, boolean matchDirectoriesOnly) {
+ this.usedPatternList = new ArrayList<StarPattern>(patternStrings.size());
+ for (String patternString : patternStrings) {
+ this.usedPatternList.add(new StarPattern(patternString));
+ }
+ this.offset = 0;
+ this.matchDirectoriesOnly = matchDirectoriesOnly;
+ }
+
+ int getActualPathSize() {
+ return usedPatternList.size() - offset;
+ }
+
+ private StarPattern 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.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 14/22] Added the class IgnoreRuleListFactory.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (12 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 13/22] Added the class ComplexFilePattern Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 15/22] Added a Rules interface implementation and a factory for it Florian Koeberle
` (8 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../lib/fileiteration/IgnoreRuleListFactory.java | 106 ++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/IgnoreRuleListFactory.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/IgnoreRuleListFactory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/IgnoreRuleListFactory.java
new file mode 100644
index 0000000..aaf3aae
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/IgnoreRuleListFactory.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.StringTokenizer;
+
+/**
+ * This class can be used to create lists of {@link Rule} objects from lines of
+ * .gitignore like files.
+ *
+ * @author Florian Köberle
+ *
+ */
+class IgnoreRuleListFactory {
+
+ List<Rule> createIgnoreRuleList(Iterable<String> lineIterable) {
+ LinkedList<Rule> rules = new LinkedList<Rule>();
+ for (String line : lineIterable) {
+ final String trimmedLine = line.trim();
+ if (trimmedLine.startsWith("#")) {
+ continue;
+ }
+ if (trimmedLine.length() == 0) {
+ continue;
+ }
+ rules.add(0, createRule(trimmedLine));
+ }
+ return rules;
+ }
+
+ List<Rule> createIgnoreRuleList(List<File> files)
+ throws FileNotFoundException {
+ final List<String> lines = new ArrayList<String>();
+ for (File file : files) {
+ Scanner scanner = new Scanner(file);
+ try {
+ while (scanner.hasNextLine()) {
+ lines.add(scanner.nextLine());
+ }
+ } finally {
+ scanner.close();
+ }
+ }
+ return createIgnoreRuleList(lines);
+ }
+
+ private Rule createRule(String trimmedLine) {
+ final boolean exclude;
+ String patternString;
+ if (trimmedLine.startsWith("!")) {
+ exclude = false;
+ patternString = trimmedLine.substring(1);
+ } else {
+ exclude = true;
+ patternString = trimmedLine;
+ }
+
+ final boolean matchDirectoriesOnly;
+ if (patternString.endsWith("/")) {
+ matchDirectoriesOnly = true;
+ patternString = patternString.substring(0,
+ patternString.length() - 1);
+ } else {
+ matchDirectoriesOnly = false;
+ }
+
+ final FilePattern pattern;
+ if (patternString.contains("/")) {
+ if (patternString.startsWith("/")) {
+ patternString = patternString.substring(1);
+ }
+ final StringTokenizer stringTokenizer = new StringTokenizer(
+ patternString, "/");
+ final List<String> patternList = new ArrayList<String>();
+ while (stringTokenizer.hasMoreTokens()) {
+ final String token = stringTokenizer.nextToken();
+ patternList.add(token);
+ }
+ pattern = new ComplexFilePattern(patternList, matchDirectoriesOnly);
+ } else {
+ pattern = new GlobalFilePattern(patternString, matchDirectoriesOnly);
+ }
+ return new Rule(exclude, pattern);
+ }
+
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 15/22] Added a Rules interface implementation and a factory for it.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (13 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 14/22] Added the class IgnoreRuleListFactory Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 16/22] Added test class OverallIgnoreRulestest Florian Koeberle
` (7 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../fileiteration/RuleListToObjectConverter.java | 113 ++++++++++++++++++++
.../lib/fileiteration/RulesImplementation.java | 87 +++++++++++++++
2 files changed, 200 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RuleListToObjectConverter.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RulesImplementation.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RuleListToObjectConverter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RuleListToObjectConverter.java
new file mode 100644
index 0000000..533a35b
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RuleListToObjectConverter.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+class RuleListToObjectConverter {
+ protected Rules createIgnoreRules(Iterator<Rule> ruleIterator) {
+ final List<Rule> rules = getNessesaryRulesFromIterator(ruleIterator);
+ removeUnnecessaryDoNotIgnoreRulesAtTheEndOfTheList(rules);
+ removeUnnecessaryIgnoreRulesNearTheEndOfTheList(rules);
+
+ if (rules.size() == 1) {
+ final Rule rule = rules.get(0);
+ if (rule.getPattern() == FilePattern.MATCH_ALWAYS) {
+ if (rule.isIgnoreAtMatch()) {
+ return Rules.IGNORE_ALL;
+ } else {
+ return Rules.IGNORE_NOTHING;
+ }
+ }
+ } else if (rules.isEmpty()) {
+ return Rules.IGNORE_NOTHING;
+ }
+ return new RulesImplementation(rules, this);
+ }
+
+ private List<Rule> getNessesaryRulesFromIterator(Iterator<Rule> ruleIterator) {
+ final List<Rule> rules = new ArrayList<Rule>();
+ while (ruleIterator.hasNext()) {
+ final Rule subRule = ruleIterator.next();
+ if (subRule.getPattern() == FilePattern.MATCH_NEVER) {
+ continue;
+ }
+ rules.add(subRule);
+ // There is no need for rules after a rule witch match always,
+ // as such a rule would never be the first rule which matches.
+ if (subRule.getPattern() == FilePattern.MATCH_ALWAYS) {
+ break;
+ }
+ }
+ return rules;
+ }
+
+ /**
+ * Expects that
+ * {@link #removeUnnecessaryDoNotIgnoreRulesAtTheEndOfTheList(List)} has
+ * been executed first.
+ *
+ * @param rules
+ * rule list to reduce.
+ */
+ private void removeUnnecessaryIgnoreRulesNearTheEndOfTheList(
+ final List<Rule> rules) {
+ // Why the following optimization makes only sense for the end of the
+ // list:
+ // If there is a "ignore all"- rule,
+ // then it is located at the end of the list
+ // See how the list is filled to prove this statement.
+ if (rules.size() >= 2) {
+ final Rule lastRule = rules.get(rules.size() - 1);
+ assert lastRule.isIgnoreAtMatch() : "Expected that no 'not ignore'-rule is at the end of the list any more";
+ final boolean ignoreAllAtEnd = lastRule.getPattern().equals(
+ FilePattern.MATCH_ALWAYS);
+ if (ignoreAllAtEnd) {
+ while (rules.size() >= 2) {
+ final int ruleBeforeLastIndex = rules.size() - 2;
+ final Rule ruleBeforeLast = rules.get(ruleBeforeLastIndex);
+ if (ruleBeforeLast.isIgnoreAtMatch()) {
+ rules.remove(ruleBeforeLastIndex);
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ private void removeUnnecessaryDoNotIgnoreRulesAtTheEndOfTheList(
+ final List<Rule> rules) {
+ // Why it is save to remove "don't ignore rules" at the end of the list
+ // if there is no "ignore rule" below a "don't ignore rule" then
+ // the path which haven't match jet will never be ignored:
+ // -> if another "don't ignore rule" match then the patch will not be
+ // ignored
+ // -> if no "don't ignore rule" match then the path will not be ignored.
+ while (!rules.isEmpty()) {
+ final int indexOfLastRule = rules.size() - 1;
+ final Rule lastRule = rules.get(indexOfLastRule);
+ if (lastRule.isIgnoreAtMatch()) {
+ break;
+ } else {
+ rules.remove(indexOfLastRule);
+ }
+ }
+ }
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RulesImplementation.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RulesImplementation.java
new file mode 100644
index 0000000..b7bf963
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/RulesImplementation.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+class RulesImplementation implements Rules {
+ /**
+ * Complete list of rules. Note that order is: determining rule first.
+ */
+ private final List<Rule> rulesForTree;
+
+ /**
+ * {@link Rule} objects which return true at a call of
+ * {@link Rule#canMatchAtThisDirectoryLevel}.
+ */
+ private final List<Rule> rulesForThisLevel;
+
+ /**
+ * Factory used to create {@link Rules} for sub directories.
+ */
+ private RuleListToObjectConverter factory;
+
+ RulesImplementation(List<Rule> rules, RuleListToObjectConverter factory) {
+ this.rulesForTree = rules;
+ this.factory = factory;
+ this.rulesForThisLevel = new ArrayList<Rule>();
+ for (Rule rule : rules) {
+ if (rule.canMatchAtThisDirectoryLevel()) {
+ this.rulesForThisLevel.add(rule);
+ }
+ }
+ }
+
+ /**
+ * @see org.spearce.jgit.lib.fileiteration.Rules#toIgnore(java.lang.String,
+ * boolean)
+ */
+ public boolean toIgnore(String fileName, boolean fileIsDirectory) {
+ for (Rule rule : rulesForThisLevel) {
+ if (rule.getPattern().match(fileName, fileIsDirectory)) {
+ return rule.isIgnoreAtMatch();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @see org.spearce.jgit.lib.fileiteration.Rules#getRulesForSubDirectory(java.lang.String)
+ */
+ public Rules getRulesForSubDirectory(final String directoryName) {
+ final Iterator<Rule> subRuleIterator = new Iterator<Rule>() {
+ final Iterator<Rule> ruleIterator = rulesForTree.iterator();
+
+ public boolean hasNext() {
+ return ruleIterator.hasNext();
+ }
+
+ public Rule next() {
+ return ruleIterator.next()
+ .getRuleForSubDirectory(directoryName);
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ return factory.createIgnoreRules(subRuleIterator);
+ }
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 16/22] Added test class OverallIgnoreRulestest.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (14 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 15/22] Added a Rules interface implementation and a factory for it Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 17/22] Added the class TreeFilePattern Florian Koeberle
` (6 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../lib/fileiteration/OverallIgnoreRulesTest.java | 373 ++++++++++++++++++++
1 files changed, 373 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/OverallIgnoreRulesTest.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/OverallIgnoreRulesTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/OverallIgnoreRulesTest.java
new file mode 100644
index 0000000..feb15d7
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/OverallIgnoreRulesTest.java
@@ -0,0 +1,373 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.spearce.jgit.lib.fileiteration.Rules;
+
+import junit.framework.TestCase;
+
+public class OverallIgnoreRulesTest extends TestCase {
+ private IgnoreRulesFactory factory;
+
+ @Override
+ protected void setUp() throws Exception {
+ factory = new IgnoreRulesFactory();
+ }
+
+ public void testSimpleGlobalPattern() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("ab");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertTrue(ignoreRules.toIgnore("ab", false));
+ assertTrue(ignoreRules.toIgnore("ab", true));
+ assertFalse(ignoreRules.toIgnore("abc", false));
+ assertFalse(ignoreRules.toIgnore("abc", true));
+ }
+
+ public void testGlobalPatternWithOneStar() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("a*c");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+
+ assertTrue(ignoreRules.toIgnore("ac", false));
+ assertTrue(ignoreRules.toIgnore("ac", true));
+
+ assertTrue(ignoreRules.toIgnore("abc", false));
+ assertTrue(ignoreRules.toIgnore("abc", true));
+
+ assertTrue(ignoreRules.toIgnore("abbc", false));
+ assertTrue(ignoreRules.toIgnore("abbc", true));
+
+ assertTrue(ignoreRules.toIgnore("aabc", false));
+ assertTrue(ignoreRules.toIgnore("aabc", true));
+
+ assertFalse(ignoreRules.toIgnore("cab", false));
+ assertFalse(ignoreRules.toIgnore("cab", true));
+ }
+
+ public void testGlobalPatternWithTwoStars() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("a*c*e");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+
+ assertTrue(ignoreRules.toIgnore("ace", false));
+ assertTrue(ignoreRules.toIgnore("ace", true));
+
+ assertTrue(ignoreRules.toIgnore("abcde", false));
+ assertTrue(ignoreRules.toIgnore("abcde", true));
+
+ assertTrue(ignoreRules.toIgnore("aHellocWorlde", false));
+ assertTrue(ignoreRules.toIgnore("aHellocWorlde", true));
+
+ assertFalse(ignoreRules.toIgnore("ae", false));
+ assertFalse(ignoreRules.toIgnore("ae", true));
+ }
+
+ public void testGlobalPatternWithDots() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("*.tar.gz");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+
+ assertTrue(ignoreRules.toIgnore("test.tar.gz", false));
+ assertTrue(ignoreRules.toIgnore("test.tar.gz", true));
+
+ assertTrue(ignoreRules.toIgnore(".tar.gz", false));
+ assertTrue(ignoreRules.toIgnore(".tar.gz", true));
+
+ assertFalse(ignoreRules.toIgnore("test", false));
+ assertFalse(ignoreRules.toIgnore("test", true));
+
+ // test that "." isn't handled as "any character"
+ assertFalse(ignoreRules.toIgnore(".tarogz", false));
+ assertFalse(ignoreRules.toIgnore(".tarogz", true));
+ }
+
+ public void testGlobalPatternDirectoryOnlyRule() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("a/");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+
+ assertTrue(ignoreRules.toIgnore("a", true));
+ assertFalse(ignoreRules.toIgnore("a", false));
+
+ final Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory("a");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesA);
+
+ final Rules ignoreRulesB = ignoreRules.getRulesForSubDirectory("b");
+ assertTrue(ignoreRulesB.toIgnore("a", true));
+ assertFalse(ignoreRulesB.toIgnore("a", false));
+
+ final Rules ignoreRulesBA = ignoreRulesB.getRulesForSubDirectory("a");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesBA);
+
+ }
+
+ public void testSimpleFilePathPattern() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("a/b/c");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertFalse(ignoreRules.toIgnore("a", true));
+ assertFalse(ignoreRules.toIgnore("a", false));
+ assertFalse(ignoreRules.toIgnore("b", true));
+ assertFalse(ignoreRules.toIgnore("b", false));
+ assertFalse(ignoreRules.toIgnore("c", true));
+ assertFalse(ignoreRules.toIgnore("c", false));
+
+ final Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory("a");
+ assertFalse(ignoreRulesA.toIgnore("a", true));
+ assertFalse(ignoreRulesA.toIgnore("a", false));
+ assertFalse(ignoreRulesA.toIgnore("b", true));
+ assertFalse(ignoreRulesA.toIgnore("b", false));
+ assertFalse(ignoreRulesA.toIgnore("c", true));
+ assertFalse(ignoreRulesA.toIgnore("c", false));
+
+ final Rules ignoreRulesAB = ignoreRulesA.getRulesForSubDirectory("b");
+ assertFalse(ignoreRulesAB.toIgnore("a", true));
+ assertFalse(ignoreRulesAB.toIgnore("a", false));
+ assertFalse(ignoreRulesAB.toIgnore("b", true));
+ assertFalse(ignoreRulesAB.toIgnore("b", false));
+ assertTrue(ignoreRulesAB.toIgnore("c", true));
+ assertTrue(ignoreRulesAB.toIgnore("c", false));
+
+ final Rules ignoreRulesABA = ignoreRulesAB.getRulesForSubDirectory("a");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesABA);
+
+ final Rules ignoreRulesABB = ignoreRulesAB.getRulesForSubDirectory("b");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesABB);
+
+ final Rules ignoreRulesABC = ignoreRulesAB.getRulesForSubDirectory("c");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesABC);
+ }
+
+ public void testFilePathPatternDirectoryOnlyRule() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("a/b/c/");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertFalse(ignoreRules.toIgnore("a", true));
+ assertFalse(ignoreRules.toIgnore("a", false));
+ assertFalse(ignoreRules.toIgnore("b", true));
+ assertFalse(ignoreRules.toIgnore("b", false));
+ assertFalse(ignoreRules.toIgnore("c", true));
+ assertFalse(ignoreRules.toIgnore("c", false));
+
+ final Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory("a");
+ assertFalse(ignoreRulesA.toIgnore("a", true));
+ assertFalse(ignoreRulesA.toIgnore("a", false));
+ assertFalse(ignoreRulesA.toIgnore("b", true));
+ assertFalse(ignoreRulesA.toIgnore("b", false));
+ assertFalse(ignoreRulesA.toIgnore("c", true));
+ assertFalse(ignoreRulesA.toIgnore("c", false));
+
+ final Rules ignoreRulesAB = ignoreRulesA.getRulesForSubDirectory("b");
+ assertFalse(ignoreRulesAB.toIgnore("a", true));
+ assertFalse(ignoreRulesAB.toIgnore("a", false));
+ assertFalse(ignoreRulesAB.toIgnore("b", true));
+ assertFalse(ignoreRulesAB.toIgnore("b", false));
+ assertTrue(ignoreRulesAB.toIgnore("c", true));
+ assertFalse(ignoreRulesAB.toIgnore("c", false));
+
+ final Rules ignoreRulesABA = ignoreRulesAB.getRulesForSubDirectory("a");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesABA);
+
+ final Rules ignoreRulesABB = ignoreRulesAB.getRulesForSubDirectory("b");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesABB);
+
+ final Rules ignoreRulesABC = ignoreRulesAB.getRulesForSubDirectory("c");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesABC);
+ }
+
+ public void testShortPathPattern() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("/alpha");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertTrue(ignoreRules.toIgnore("alpha", true));
+ assertTrue(ignoreRules.toIgnore("alpha", false));
+
+ final Rules ignoreRulesAlpha = ignoreRules
+ .getRulesForSubDirectory("alpha");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesAlpha);
+
+ final Rules ignoreRulesBeta = ignoreRules
+ .getRulesForSubDirectory("beta");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesBeta);
+ }
+
+ public void testShortDirectoryPathPattern() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("/alpha/");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertTrue(ignoreRules.toIgnore("alpha", true));
+ assertFalse(ignoreRules.toIgnore("alpha", false));
+
+ final Rules ignoreRulesAlpha = ignoreRules
+ .getRulesForSubDirectory("alpha");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesAlpha);
+
+ final Rules ignoreRulesBeta = ignoreRules
+ .getRulesForSubDirectory("beta");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesBeta);
+ }
+
+ public void testShortPathPatternWithStar() {
+ List<String> lines = new ArrayList<String>();
+ lines.add("/.*");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+
+ assertTrue(ignoreRules.toIgnore(".test", true));
+ assertTrue(ignoreRules.toIgnore(".test", false));
+
+ assertFalse(ignoreRules.toIgnore("test", true));
+ assertFalse(ignoreRules.toIgnore("test", false));
+
+ final Rules ignoreRulesDotTest = ignoreRules
+ .getRulesForSubDirectory(".test");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesDotTest);
+
+ final Rules ignoreRulesTest = ignoreRules
+ .getRulesForSubDirectory("test");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesTest);
+ }
+
+ public void testPathPatternWith2Times2Stars() {
+ final List<String> lines = new ArrayList<String>();
+ lines.add("he*wor*d/*.*");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+
+ assertFalse(ignoreRules.toIgnore("hello", true));
+ assertFalse(ignoreRules.toIgnore("hello", false));
+ final Rules ignoreRulesHello = ignoreRules
+ .getRulesForSubDirectory("hello");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesHello);
+
+ assertFalse(ignoreRules.toIgnore("helloworld", true));
+ assertFalse(ignoreRules.toIgnore("helloworld", false));
+ final Rules ignoreRulesHelloWorld = ignoreRules
+ .getRulesForSubDirectory("helloworld");
+ assertNotSame(Rules.IGNORE_NOTHING, ignoreRulesHelloWorld);
+
+ assertTrue(ignoreRulesHelloWorld.toIgnore("test.txt", true));
+ assertTrue(ignoreRulesHelloWorld.toIgnore("test.txt", false));
+
+ assertFalse(ignoreRulesHelloWorld.toIgnore("test", true));
+ assertFalse(ignoreRulesHelloWorld.toIgnore("test", false));
+
+ final Rules ignoreRulesTestTxt = ignoreRulesHelloWorld
+ .getRulesForSubDirectory("test.txt");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesTestTxt);
+
+ final Rules ignoreRulesTest = ignoreRulesHelloWorld
+ .getRulesForSubDirectory("test");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesTest);
+ }
+
+ public void testEmptyIgnoreList() {
+ final List<String> lines = Collections.emptyList();
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertSame(Rules.IGNORE_NOTHING, ignoreRules);
+ }
+
+ public void testOnlyOneNegatedIgnore() {
+ final List<String> lines = new ArrayList<String>();
+ lines.add("!a");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertSame(Rules.IGNORE_NOTHING, ignoreRules);
+ }
+
+ public void testOnlyThreeNegatedIgnores() {
+ final List<String> lines = new ArrayList<String>();
+ lines.add("!a");
+ lines.add("!a/b/c");
+ lines.add("!b*");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertSame(Rules.IGNORE_NOTHING, ignoreRules);
+ }
+
+ public void testNegatedIgnoreCase1() {
+ final List<String> lines = new ArrayList<String>();
+ lines.add("/a");
+ lines.add("!b");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ final Rules ignoreRulesA = ignoreRules.getRulesForSubDirectory("a");
+ final Rules ignoreRulesAB = ignoreRulesA.getRulesForSubDirectory("b");
+ final Rules ignoreRulesB = ignoreRules.getRulesForSubDirectory("b");
+ final Rules ignoreRulesC = ignoreRules.getRulesForSubDirectory("c");
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesB);
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesAB);
+ assertSame(Rules.IGNORE_NOTHING, ignoreRulesC);
+ assertTrue(ignoreRules.toIgnore("a", true));
+ assertTrue(ignoreRules.toIgnore("a", false));
+ assertTrue(ignoreRulesA.toIgnore("c", true));
+ assertTrue(ignoreRulesA.toIgnore("c", false));
+ }
+
+ public void testExceptionOfException() {
+ final List<String> lines = new ArrayList<String>();
+ lines.add("*.*");
+ lines.add("!*.c");
+ lines.add("a.c");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertTrue(ignoreRules.toIgnore("b.txt", false));
+ assertTrue(ignoreRules.toIgnore("b.txt", true));
+ assertTrue(ignoreRules.toIgnore("a.c", false));
+ assertTrue(ignoreRules.toIgnore("a.c", true));
+ assertFalse(ignoreRules.toIgnore("b.c", false));
+ assertFalse(ignoreRules.toIgnore("b.c", true));
+ }
+
+ public void testComplexCase() {
+ final List<String> lines = new ArrayList<String>();
+ lines.add("*");
+ lines.add("!/alpha/src");
+ lines.add("*~");
+ final Rules ignoreRules = factory.createIgnoreRulesFromLines(lines);
+ assertTrue(ignoreRules.toIgnore("beta", true));
+ assertTrue(ignoreRules.toIgnore("alpha", true));
+ final Rules ignoreRulesAlpha = ignoreRules
+ .getRulesForSubDirectory("alpha");
+ final Rules ignoreRulesAlphaBin = ignoreRulesAlpha
+ .getRulesForSubDirectory("bin");
+ final Rules ignoreRulesAlphaSrc = ignoreRulesAlpha
+ .getRulesForSubDirectory("src");
+ assertSame(Rules.IGNORE_ALL, ignoreRulesAlphaBin);
+ assertFalse(ignoreRulesAlphaSrc.toIgnore("com", true));
+ assertFalse(ignoreRulesAlphaSrc.toIgnore("b.java", false));
+ assertTrue(ignoreRulesAlphaSrc.toIgnore("b.java~", true));
+ }
+
+ private class IgnoreRulesFactory {
+ private RuleListToObjectConverter converter = new RuleListToObjectConverter();
+
+ private IgnoreRuleListFactory listFactory = new IgnoreRuleListFactory();
+
+ /**
+ * @param ignoreFileLines
+ * the lines of a ignore file like .gitignore.
+ * @return a immutable IgnoreRules object.
+ */
+ public Rules createIgnoreRulesFromLines(Iterable<String> ignoreFileLines) {
+ final List<Rule> rules = listFactory
+ .createIgnoreRuleList(ignoreFileLines);
+ return converter.createIgnoreRules(rules.iterator());
+ }
+
+ }
+
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 17/22] Added the class TreeFilePattern.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (15 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 16/22] Added test class OverallIgnoreRulestest Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 18/22] Added InvalidPatternException and PathNotInProjectDirectoryException Florian Koeberle
` (5 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/lib/fileiteration/TreeFilePattern.java | 77 ++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/TreeFilePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/TreeFilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/TreeFilePattern.java
new file mode 100644
index 0000000..371c632
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/TreeFilePattern.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.util.List;
+
+/**
+ * Represents a pattern like "documents/*.txt" which matches all *.txt files in
+ * the tree documents.
+ *
+ * @author Florian Köberle
+ *
+ */
+class TreeFilePattern implements FilePattern {
+
+ private final List<String> path;
+
+ private final int offset;
+
+ private final GlobalFilePattern globalFilePattern;
+
+ public boolean canMatchAtThisDirectoryLevel() {
+ return false;
+ }
+
+ TreeFilePattern(List<String> path, GlobalFilePattern globalFilePattern) {
+ this.path = path;
+ this.offset = 0;
+ this.globalFilePattern = globalFilePattern;
+ }
+
+ private TreeFilePattern(List<String> path, int offset,
+ GlobalFilePattern globalFilePattern) {
+ this.path = path;
+ this.offset = offset;
+ this.globalFilePattern = globalFilePattern;
+ }
+
+ public FilePattern getPatternForSubDirectory(String directoryName) {
+ try {
+ if (!path.get(offset).equals(directoryName)) {
+ return FilePattern.MATCH_NEVER;
+ }
+ } catch (IndexOutOfBoundsException e) {
+ throw new IllegalStateException(
+ "The offset of this class doesn't refer to a valid position in path");
+ }
+ if (offset == path.size() - 1) {
+ return globalFilePattern;
+ } else {
+ return new TreeFilePattern(path, offset + 1, globalFilePattern);
+ }
+ }
+
+ public boolean isSameForSubDirectories() {
+ return false;
+ }
+
+ public boolean match(String fileName, boolean fileIsDirectory) {
+ return false;
+ }
+
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 18/22] Added InvalidPatternException and PathNotInProjectDirectoryException
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (16 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 17/22] Added the class TreeFilePattern Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 19/22] Added the class AddRuleListFactory Florian Koeberle
` (4 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/errors/InvalidPatternException.java | 48 ++++++++++++++++++++
.../errors/PathNotInProjectDirectoryException.java | 28 +++++++++++
2 files changed, 76 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java
new file mode 100644
index 0000000..8cd2a31
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.errors;
+
+/**
+ * Thrown when a pattern passed in an argument was wrong.
+ *
+ * @author Florian Koeberle
+ *
+ */
+public class InvalidPatternException extends Exception {
+ private static final long serialVersionUID = -606889225458579931L;
+
+ private final String pattern;
+
+ /**
+ * @param message
+ * explains what was wrong with the pattern.
+ * @param pattern
+ * the invalid pattern.
+ */
+ public InvalidPatternException(String message, String pattern) {
+ super(message);
+ this.pattern = pattern;
+ }
+
+ /**
+ * @return the invalid pattern.
+ */
+ public String getPattern() {
+ return pattern;
+ }
+
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java
new file mode 100644
index 0000000..1b7b903
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/PathNotInProjectDirectoryException.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.errors;
+
+/**
+ * Thrown when a path wasn't in the project directory, but expected to be.
+ *
+ * @author Florian Köberle
+ *
+ */
+public class PathNotInProjectDirectoryException extends
+ IllegalArgumentException {
+ private static final long serialVersionUID = 1650325142579844202L;
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 19/22] Added the class AddRuleListFactory.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (17 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 18/22] Added InvalidPatternException and PathNotInProjectDirectoryException Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 20/22] Added class FileIterableFactoryForAddCommand Florian Koeberle
` (3 subsequent siblings)
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/lib/fileiteration/AddRuleListFactory.java | 128 ++++++++++++++++++++
1 files changed, 128 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/AddRuleListFactory.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/AddRuleListFactory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/AddRuleListFactory.java
new file mode 100644
index 0000000..9d2f942
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/AddRuleListFactory.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.spearce.jgit.errors.InvalidPatternException;
+import org.spearce.jgit.errors.PathNotInProjectDirectoryException;
+
+class AddRuleListFactory {
+ /*
+ * The add command of git 1.5.2.5 behaves a little bit stange: "git add
+ * a/\*z" adds the file "a/b/xyz" but "git add a/x\*" does not.
+ *
+ * The first is parsed as pattern "*z" for whole directory tree "a". The
+ * second is parsed as an path.
+ *
+ */
+
+ private static List<String> getRelativePath(File projectDirectory, File file)
+ throws PathNotInProjectDirectoryException, IOException {
+ File currentFile = file.getCanonicalFile();
+ final LinkedList<String> relativePath = new LinkedList<String>();
+ while (!currentFile.equals(projectDirectory)) {
+ relativePath.addFirst(currentFile.getName());
+ currentFile = currentFile.getParentFile();
+ if (currentFile == null) {
+ throw new PathNotInProjectDirectoryException();
+ }
+ }
+ return relativePath;
+ }
+
+ List<Rule> createRuleList(File projectDirectory, File workingDirectory,
+ List<String> filePatternsOfAddCommand)
+ throws InvalidPatternException, PathNotInProjectDirectoryException,
+ IOException {
+
+ final List<String> pathPrefix = getRelativePath(projectDirectory,
+ workingDirectory);
+
+ final List<Rule> ruleList = new ArrayList<Rule>(
+ filePatternsOfAddCommand.size());
+ for (String pattern : filePatternsOfAddCommand) {
+ final boolean matchDirectoriesOnly;
+ if (pattern.endsWith(File.separator)) {
+ pattern = pattern.substring(0, pattern.length() - 1);
+ matchDirectoriesOnly = true;
+ } else {
+ matchDirectoriesOnly = false;
+ }
+
+ final String[] relativePath = pattern.split("[" + File.separator
+ + "]");
+ final List<String> path = new ArrayList<String>();
+ path.addAll(pathPrefix);
+ path.addAll(Arrays.asList(relativePath));
+ assert (!path.isEmpty());
+
+ final FilePattern filePattern = createFilePattern(pattern,
+ matchDirectoriesOnly, path);
+ final Rule rule = new Rule(false, filePattern);
+ ruleList.add(rule);
+
+ }
+ return ruleList;
+ }
+
+ private static FilePattern createFilePattern(String pattern,
+ boolean matchDirectoriesOnly, List<String> path)
+ throws InvalidPatternException {
+ /*
+ * I did several tests with the git-add command, and it seems that it
+ * handles a pattern as a fileGlob, if it has only one star at the
+ * beginning of the latest part of the path. Otherwise it handle it as
+ * file pattern.
+ */
+
+ final String lastPathElement = path.get(path.size() - 1);
+ final boolean isFileGlob = lastPathElement.startsWith("*");
+ final FilePattern filePattern;
+ if (isFileGlob) {
+ filePattern = createGlobalOrTreeFilePattern(matchDirectoriesOnly,
+ path, lastPathElement);
+ } else {
+ for (String pathElement : path) {
+ if (pathElement.contains("*")) {
+ throw new InvalidPatternException(
+ "Stars are not allowed here", pattern);
+ }
+ }
+ filePattern = new ComplexFilePattern(path, matchDirectoriesOnly);
+ }
+ return filePattern;
+ }
+
+ private static FilePattern createGlobalOrTreeFilePattern(
+ final boolean matchDirectoriesOnly, final List<String> path,
+ final String lastPathElement) {
+ final GlobalFilePattern globalFilePatternForTree = new GlobalFilePattern(
+ lastPathElement, matchDirectoriesOnly);
+ final List<String> targetTree = path.subList(0, path.size() - 1);
+ if (targetTree.isEmpty()) {
+ return globalFilePatternForTree;
+ } else {
+ return new TreeFilePattern(targetTree, globalFilePatternForTree);
+ }
+ }
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 20/22] Added class FileIterableFactoryForAddCommand.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (18 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 19/22] Added the class AddRuleListFactory Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 21/22] Added test class FileIterableFactoryForAddCommandTest Florian Koeberle
` (2 subsequent siblings)
22 siblings, 0 replies; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../FileIterableFactoryForAddCommand.java | 118 ++++++++++++++++++++
1 files changed, 118 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommand.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommand.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommand.java
new file mode 100644
index 0000000..4674a87
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommand.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.spearce.jgit.errors.InvalidPatternException;
+import org.spearce.jgit.errors.PathNotInProjectDirectoryException;
+import org.spearce.jgit.lib.GitPathConstants;
+import org.spearce.jgit.lib.Project;
+
+/**
+ * This class is designed to serve the needs of someone who want to implement a
+ * git-add command and needs to determine the files to add.
+ *
+ * @author Florian Köberle
+ *
+ */
+public class FileIterableFactoryForAddCommand {
+ private final RuleListToObjectConverter converter = new RuleListToObjectConverter();
+
+ private final IgnoreRuleListFactory ignoreRuleListFactory = new IgnoreRuleListFactory();
+
+ private final AddRuleListFactory addRuleListFactory = new AddRuleListFactory();
+
+ /**
+ * @param project
+ * a git project.
+ * @param projectSubDirectory
+ * a directory in the projectDirectory.
+ * @param filePatternsOfAddCommand
+ * determines the files to iterate over.
+ * @return an {@link Iterable} which can be used to iterate over all
+ * matching files in the project directory which are not ignored by
+ * some ignore rules.
+ * @throws InvalidPatternException
+ * @throws IOException
+ * for some reasons.
+ * @throws PathNotInProjectDirectoryException
+ * if projectSubDirectory isn't a subdirectory of the project
+ * directory.
+ */
+ public Iterable<File> createFileTreeIterable(Project project,
+ File projectSubDirectory, List<String> filePatternsOfAddCommand)
+ throws InvalidPatternException, PathNotInProjectDirectoryException,
+ IOException {
+ final File gitDirectory = project.getRepository().getDirectory();
+ final Rules rules = createRules(project.getDirectory(), gitDirectory,
+ projectSubDirectory, filePatternsOfAddCommand);
+ return new FileTreeIterable(project.getDirectory(), rules, false);
+ }
+
+ private Rules createRules(File projectDirectory, File gitDirectory,
+ File workingDirectory, List<String> filePatternsOfAddCommand)
+ throws InvalidPatternException, PathNotInProjectDirectoryException,
+ IOException {
+ final Rule gitDirectoryIgnoreRule = createGitDirectoryIgnoreRule();
+ final List<Rule> ignoreRuleListFromFiles = createExcludeRules(
+ projectDirectory, gitDirectory);
+ final List<Rule> includeRules = addRuleListFactory.createRuleList(
+ projectDirectory, workingDirectory, filePatternsOfAddCommand);
+ final List<Rule> ruleList = new ArrayList<Rule>();
+
+ ruleList.add(gitDirectoryIgnoreRule);
+ ruleList.addAll(ignoreRuleListFromFiles);
+ ruleList.addAll(includeRules);
+ ruleList.add(new Rule(true, FilePattern.MATCH_ALWAYS));
+
+ return converter.createIgnoreRules(ruleList.iterator());
+ }
+
+ private List<Rule> createExcludeRules(File projectDirectory,
+ File gitDirectory) {
+ final List<File> possibleIgnoreFiles = new ArrayList<File>(2);
+ possibleIgnoreFiles.add(new File(projectDirectory, ".gitignore"));
+ possibleIgnoreFiles.add(new File(new File(gitDirectory, "info"),
+ "exclude"));
+
+ final List<File> ignoreFiles = new ArrayList<File>();
+ for (File possibleIgnoreFile : possibleIgnoreFiles) {
+ if (possibleIgnoreFile.isFile()) {
+ ignoreFiles.add(possibleIgnoreFile);
+ }
+ }
+
+ try {
+ return ignoreRuleListFactory.createIgnoreRuleList(ignoreFiles);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException("unexpected removal of ignore files", e);
+ }
+ }
+
+ private Rule createGitDirectoryIgnoreRule() {
+ final FilePattern gitDirectoryPattern = new ComplexFilePattern(Arrays
+ .asList(GitPathConstants.REPOSITORY_DIRECTORY_NAME), true);
+ final Rule gitDirectoryIgnoreRule = new Rule(true, gitDirectoryPattern);
+ return gitDirectoryIgnoreRule;
+ }
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 21/22] Added test class FileIterableFactoryForAddCommandTest.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (19 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 20/22] Added class FileIterableFactoryForAddCommand Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 22/22] Added a "add" command to the git like command line tool Florian Koeberle
2008-05-10 20:45 ` [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Robin Rosenberg
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../FileIterableFactoryForAddCommandTest.java | 310 ++++++++++++++++++++
1 files changed, 310 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommandTest.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommandTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommandTest.java
new file mode 100644
index 0000000..d3c78f4
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/fileiteration/FileIterableFactoryForAddCommandTest.java
@@ -0,0 +1,310 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.lib.fileiteration;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.spearce.jgit.lib.Project;
+import org.spearce.jgit.lib.ProjectFactory;
+
+public class FileIterableFactoryForAddCommandTest extends TestCase {
+
+ private Project project;
+
+ private FileIterableFactoryForAddCommand factory;
+
+ @Override
+ protected void setUp() throws Exception {
+ final ProjectFactory projectFactory = new ProjectFactory();
+ final File projectDirectory = File.createTempFile("test", "");
+ projectDirectory.delete();
+ projectDirectory.mkdir();
+ projectDirectory.deleteOnExit();
+ this.project = projectFactory.createProject(projectDirectory);
+ this.factory = new FileIterableFactoryForAddCommand();
+ }
+
+ public void testNoPattern() throws Exception {
+ createFile("a.txt");
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ project.getDirectory(), Collections.<String> emptyList());
+ final Set<File> expectedPathes = Collections.emptySet();
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedPathes, iterable);
+ }
+
+ public void testTreePattern1() throws Exception {
+ final Set<File> expectedFiles = new HashSet<File>();
+ createFile("a.txt");
+ expectedFiles.add(createFile("a", "a.txt"));
+ expectedFiles.add(createFile("a", "a", "a.txt"));
+ expectedFiles.add(createFile("a", "b", "a.txt"));
+ createFile("a", "b", "a.c");
+
+ final File directoryA = new File(project.getDirectory(), "a");
+
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ directoryA, Arrays.asList("*.txt"));
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedFiles, iterable);
+ }
+
+ public void testTreePattern2() throws Exception {
+ final Set<File> expectedFiles = new HashSet<File>();
+ createFile("a.txt");
+ expectedFiles.add(createFile("a", "a.txt"));
+ expectedFiles.add(createFile("a", "a", "a.txt"));
+ expectedFiles.add(createFile("a", "b", "a.txt"));
+ createFile("a", "b", "a.c");
+
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ project.getDirectory(), Arrays.asList("a" + File.separator
+ + "*.txt"));
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedFiles, iterable);
+ }
+
+ public void testSelectCompleteSubdirectory() throws Exception {
+ final Set<File> expectedPathes = new HashSet<File>();
+ final File directoryA = new File(project.getDirectory(), "a");
+ final File directoryAA = new File(directoryA, "a");
+ final File directoryAB = new File(directoryA, "b");
+ createFile("a.txt");
+ expectedPathes.add(directoryA);
+ expectedPathes.add(directoryAA);
+ expectedPathes.add(createFile("a", "a.txt"));
+ expectedPathes.add(createFile("a", "a", "a.txt"));
+ expectedPathes.add(directoryAB);
+ expectedPathes.add(createFile("a", "b", "a.txt"));
+ expectedPathes.add(createFile("a", "b", "a.c"));
+
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ project.getDirectory(), Arrays.asList("a"));
+
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedPathes, iterable);
+ }
+
+ public void testSelectTwoSubdirectories() throws Exception {
+ final Set<File> expectedPathes = new HashSet<File>();
+ final File directoryA = new File(project.getDirectory(), "a");
+ final File directoryAA = new File(directoryA, "a");
+ final File directoryAB = new File(directoryA, "b");
+ createFile("a.txt");
+ createFile("a", "a.txt");
+ expectedPathes.add(directoryAA);
+ expectedPathes.add(createFile("a", "a", "a.txt"));
+ expectedPathes.add(directoryAB);
+ expectedPathes.add(createFile("a", "b", "a.txt"));
+ expectedPathes.add(createFile("a", "b", "a.c"));
+
+ final List<String> patternList = new ArrayList<String>(2);
+ patternList.add("a" + File.separator + "a");
+ patternList.add("a" + File.separator + "b");
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ project.getDirectory(), patternList);
+
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedPathes, iterable);
+ }
+
+ public void testTwoDifferentSelects() throws Exception {
+ final Set<File> expectedPathes = new HashSet<File>();
+ final File directoryA = new File(project.getDirectory(), "a");
+ final File directoryAA = new File(directoryA, "a");
+ createFile("a.txt");
+ createFile("a", "a.txt");
+ expectedPathes.add(directoryAA);
+ expectedPathes.add(createFile("a", "a", "a.txt"));
+ expectedPathes.add(createFile("a", "b", "a.txt"));
+ expectedPathes.add(createFile("a", "b", "c", "a.txt"));
+ createFile("a", "b", "a.c");
+
+ final List<String> patternList = new ArrayList<String>(2);
+ patternList.add("a" + File.separator + "a");
+ patternList.add("a" + File.separator + "b" + File.separator + "*.txt");
+
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ project.getDirectory(), patternList);
+
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedPathes, iterable);
+ }
+
+ public void testRealisticExample() throws Exception {
+ final Set<File> expectedPathes = new HashSet<File>();
+
+ // write the .gitignore file
+ final File dotGitIgnoreFile = createFile(".gitignore");
+ final PrintWriter dotGitIgnoreFilePrinter = new PrintWriter(
+ dotGitIgnoreFile);
+ try {
+ dotGitIgnoreFilePrinter.println("/alpha/config.xml");
+ dotGitIgnoreFilePrinter.println("*.class");
+ dotGitIgnoreFilePrinter.println("!/alpha/test/ressources/");
+ dotGitIgnoreFilePrinter.println("*~");
+ } finally {
+ dotGitIgnoreFilePrinter.close();
+ }
+
+ // write the .git/info/exclude file
+ final File repositoryDirectory = project.getRepository().getDirectory();
+ final File infoDirectory = new File(repositoryDirectory, "info");
+ infoDirectory.mkdir();
+ final File infoExcludeFile = new File(infoDirectory, "exclude");
+ final PrintWriter infoExcludeFilePrinter = new PrintWriter(
+ infoExcludeFile);
+ try {
+ infoExcludeFilePrinter.println("/alpha/test/ressources/mytest.txt");
+ } finally {
+ infoExcludeFilePrinter.close();
+ }
+
+ createFile("alpha", "config.xml");
+ expectedPathes.add(createFile("alpha", "src", "Main.java"));
+ createFile("alpha", "src", "Main.class");
+ expectedPathes.add(createFile("alpha", "test", "ressources",
+ "Example.class"));
+ expectedPathes.add(createFile("alpha", "test", "ressources",
+ "input.txt"));
+ createFile("alpha", "test", "ressources", "input.txt~");
+ createFile("alpha", "test", "ressources", "mytest.txt");
+
+ final File alphaDirectory = new File(project.getDirectory(), "alpha");
+ final File srcDirectory = new File(alphaDirectory, "src");
+ final File testDirectory = new File(alphaDirectory, "test");
+ final File ressources = new File(testDirectory, "ressources");
+
+ expectedPathes.add(alphaDirectory);
+ expectedPathes.add(srcDirectory);
+ expectedPathes.add(testDirectory);
+ expectedPathes.add(ressources);
+
+ final List<String> patternList = new ArrayList<String>(2);
+ patternList.add("alpha");
+
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ project.getDirectory(), patternList);
+
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedPathes, iterable);
+ }
+
+ public void testSingleFile() throws Exception {
+ createFile("a.txt");
+ createFile("a", "a.txt");
+ createFile("a", "a", "a.txt");
+ final File expectedFile = createFile("a", "b", "a.txt");
+ createFile("a", "b", "a.c");
+
+ final String pattern = "a" + File.separator + "b" + File.separator
+ + "a.txt";
+ final Iterable<File> iterable = factory.createFileTreeIterable(project,
+ project.getDirectory(), Arrays.asList(pattern));
+ final Set<File> expectedPathes = Collections.singleton(expectedFile);
+ assertIsValidIterable(iterable);
+ assertIterableReturnsSet(expectedPathes, iterable);
+ }
+
+ /**
+ * Tests if the specified {@link Iterable} returns the specified set of
+ * {@link File}s. The assertion will fail if the {@link Iterable} returns
+ * to much, to less files. It will also fail if the {@link Iterable} returns
+ * a file twice.
+ *
+ * @param expectedContent
+ * the expected set of files.
+ * @param iterable
+ * the {@link Iterable} to test.
+ */
+ private void assertIterableReturnsSet(Set<File> expectedContent,
+ Iterable<File> iterable) {
+ final Set<File> returnedFiles = new HashSet<File>();
+ final List<File> doubleReturnedFiles = new ArrayList<File>();
+
+ final Iterator<File> iterator = iterable.iterator();
+ while (iterator.hasNext()) {
+ final File file = iterator.next();
+ if (!returnedFiles.add(file)) {
+ doubleReturnedFiles.add(file);
+ }
+ }
+ final Set<File> missingFiles = new HashSet<File>();
+ for (File file : expectedContent) {
+ if (!returnedFiles.contains(file)) {
+ missingFiles.add(file);
+ }
+ }
+ if (!missingFiles.isEmpty()) {
+ fail(String.format("missing pathes: %s", missingFiles));
+ }
+
+ final Set<File> unexpectedFiles = new HashSet<File>();
+ for (File file : returnedFiles) {
+ if (!expectedContent.contains(file)) {
+ unexpectedFiles.add(file);
+ }
+ }
+ if (!unexpectedFiles.isEmpty()) {
+ fail(String.format("unexpected pathes: %s", unexpectedFiles));
+ }
+
+ if (!doubleReturnedFiles.isEmpty()) {
+ fail(String.format("multiple times returned pathes: %s",
+ doubleReturnedFiles));
+ }
+
+ }
+
+ private static void assertIsValidIterable(Iterable<File> iterable) {
+ final Iterator<File> iterator = iterable.iterator();
+ while (iterator.hasNext()) {
+ iterator.next();
+ }
+ try {
+ iterator.next();
+ fail();
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+ }
+
+ private File createFile(String... path) throws IOException {
+ File file = project.getDirectory();
+ for (int i = 0; i < path.length; i++) {
+ file = new File(file, path[i]);
+ if (i == path.length - 1) {
+ file.getParentFile().mkdirs();
+ file.createNewFile();
+ break;
+ }
+ }
+ return file;
+ }
+}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [JGIT PATCH 22/22] Added a "add" command to the git like command line tool.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (20 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 21/22] Added test class FileIterableFactoryForAddCommandTest Florian Koeberle
@ 2008-05-10 13:00 ` Florian Koeberle
2008-05-10 20:54 ` Robin Rosenberg
2008-05-10 20:45 ` [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Robin Rosenberg
22 siblings, 1 reply; 35+ messages in thread
From: Florian Koeberle @ 2008-05-10 13:00 UTC (permalink / raw)
To: git; +Cc: Florian Koeberle
---
.../src/org/spearce/jgit/pgm/AddCommand.java | 96 ++++++++++++++++++++
.../src/org/spearce/jgit/pgm/MainProgram.java | 1 +
2 files changed, 97 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/pgm/AddCommand.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/AddCommand.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/AddCommand.java
new file mode 100644
index 0000000..f8d86b1
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/AddCommand.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2008 Florian Kö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.pgm;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.spearce.jgit.errors.InvalidPatternException;
+import org.spearce.jgit.lib.GitIndex;
+import org.spearce.jgit.lib.Project;
+import org.spearce.jgit.lib.ProjectSeeker;
+import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.lib.GitIndex.Entry;
+import org.spearce.jgit.lib.fileiteration.FileIterableFactoryForAddCommand;
+
+/**
+ * This class is immutable. It's {@link #execute} method is used to add files to
+ * the index.
+ *
+ * @author Florian Köberle
+ *
+ */
+public class AddCommand implements Command {
+ /**
+ * Use this instance instead of creating a new ${link AddCommand}. You don't
+ * need to create an instance of this class as it is immutable and not
+ * configurable.
+ */
+ public static AddCommand INSTANCE = new AddCommand();
+
+ /**
+ * Adds the specified files to the index.
+ *
+ * @param args
+ * can contain "*.Suffix" patterns, files and directories.
+ */
+ public void execute(String... args) throws IOException {
+ final ProjectSeeker projectFactory = new ProjectSeeker();
+ final Project project = projectFactory.findProject();
+ final Repository repository = project.getRepository();
+ try {
+ final GitIndex gitIndex = repository.getIndex();
+ final File projectDirectory = project.getDirectory();
+ final String workingDirectoryString = System
+ .getProperty("user.dir");
+ if (workingDirectoryString == null) {
+ throw new UnableToDetermineWorkingDirectory();
+ }
+ final File workingDirectory = new File(workingDirectoryString);
+ final FileIterableFactoryForAddCommand iterableFactory = new FileIterableFactoryForAddCommand();
+ final Iterable<File> fileIterable = iterableFactory
+ .createFileTreeIterable(project, workingDirectory, Arrays
+ .asList(args));
+ for (File path : fileIterable) {
+ if (path.isFile()) {
+ Entry entry = gitIndex.add(projectDirectory, path);
+ entry.setAssumeValid(false);
+
+ }
+ }
+ gitIndex.write();
+ } catch (UnableToDetermineWorkingDirectory e) {
+ System.err.println("Unable to determine working directory");
+ System.exit(1);
+ } catch (InvalidPatternException e) {
+ System.err.printf("The pattern '%s' is invalid: %s",
+ e.getMessage(), e.getPattern());
+ System.exit(1);
+ } finally {
+ repository.close();
+ }
+ }
+
+ public String getShortDescription() {
+ return "Adds one or more files to the index.";
+ }
+
+ private static class UnableToDetermineWorkingDirectory extends Exception {
+ private static final long serialVersionUID = -4229647819515644868L;
+ }
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
index 7601f31..78aaccd 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/MainProgram.java
@@ -35,6 +35,7 @@ public class MainProgram {
static {
final Map<String, Command> commands = new HashMap<String, Command>();
+ commands.put("add", AddCommand.INSTANCE);
commands.put("init", InitCommand.INSTANCE);
commands.put("help", HelpCommand.INSTANCE);
commandNameToObjectMap = Collections.unmodifiableMap(commands);
--
1.5.2.5
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules.
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
` (21 preceding siblings ...)
2008-05-10 13:00 ` [JGIT PATCH 22/22] Added a "add" command to the git like command line tool Florian Koeberle
@ 2008-05-10 20:45 ` Robin Rosenberg
2008-05-11 0:16 ` Shawn O. Pearce
22 siblings, 1 reply; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:45 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
lördagen den 10 maj 2008 15.00.18 skrev Florian Koeberle:
> Hi
>
Welcome to the project Florian!
> here are the patches.
>
> The implementation does a lot of performance optimizations:
All good, but it would be nice to have some of these comments in the javadocs too. I can
sign Shawns comments and add a few on my own, not trying to be too picky and requiring
you to think of everyhing I don't. We always play rough with newcomers :)
See the rest of my replies.
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 03/22] Added a class Project which represents a project directory and it's repository.
2008-05-10 13:00 ` [JGIT PATCH 03/22] Added a class Project which represents a project directory and it's repository Florian Koeberle
@ 2008-05-10 20:45 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:45 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
lördagen den 10 maj 2008 15.00.21 skrev Florian Koeberle:
> Signed-off-by: Florian Koeberle <florianskarten@web.de>
> +public class GitPathConstants {
> + /**
> + * The name of the repository directory in the project directory.
> + */
> + public static final String REPOSITORY_DIRECTORY_NAME = ".git";
> +
> + /**
> + * Contains the name of the objects directory in the repository directory.
> + */
> + public static final String OBJECTS_DIRECTORY_NAME = "objects";
> +
> + /**
> + * Contains the name of the refs directory in the repository directory.
> + */
> + public static final String REFS_DIRECTORY_NAME = "refs";
> +
> + /**
> + * Contains the name of the HEAD file in the repository directory.
> + */
> + public static final String HEAD_FILE_NAME = "HEAD";
> +
> +}
Some of these we have as constansts in the Constants class. We should use them
and put the new ones there too. I think we have a few literals of our own that should
go there tool. Don't be afraid of proposing changes to other people's code. We don't
territories.
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
> new file mode 100644
> index 0000000..6e72486
> --- /dev/null
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Project.java
This term is also used by Eclipse and has a different meaning. Could we
use something else, maybe WorkTree?
> +public class ProjectFactory {
Let Repository be the factory.
> + } catch (RuntimeException e) {
> + repository.close();
> + throw e;
> + } catch (IOException e) {
> + repository.close();
> + throw e;
> + }
Why not finally() handling all Exceptions?
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 05/22] Added ProjectSeeker class.
2008-05-10 13:00 ` [JGIT PATCH 05/22] Added ProjectSeeker class Florian Koeberle
@ 2008-05-10 20:45 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:45 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
> +/**
> + * Use this class to create instances of {@link Project}.
> + *
> + * @author Florian Köberle
> + *
> + */
> +public class ProjectSeeker {
Let Repository do this.
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 08/22] Added the iterface Rules.
2008-05-10 13:00 ` [JGIT PATCH 08/22] Added the iterface Rules Florian Koeberle
@ 2008-05-10 20:46 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:46 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 484 bytes --]
Typo in commit message
> + * @author Florian Köberle
We do not use this javadoc field.
> \ No newline at end of file
Minor comment. Avoid this. Easy to forget so we do often. Weeding out trailing
whitespace is also nice as that tend to make diff smaller. Attached a script
that be used to ammend a commit so any new or changed lines do not have
trailing whitespace. Not fixing this won't be a showstopper as you do not
have a lot of these things anyway.
-- robin
[-- Attachment #2: washammend --]
[-- Type: application/x-shellscript, Size: 640 bytes --]
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 11/22] Added the class StarPattern.
2008-05-10 13:00 ` [JGIT PATCH 11/22] Added the class StarPattern Florian Koeberle
@ 2008-05-10 20:53 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:53 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
Agree with Shawn that we really should have fnmatch, but then calling
it StarPattern at least signals it isn't the real wildcard. I'd like to see a few more lines of javadoc at the class level here (and the othere paterns) even though it is not a public class. We must think about our reputation on Ohloh (http://www.ohloh.net/projects/6895) :)
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 13/22] Added the class ComplexFilePattern.
2008-05-10 13:00 ` [JGIT PATCH 13/22] Added the class ComplexFilePattern Florian Koeberle
@ 2008-05-10 20:53 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:53 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
lördagen den 10 maj 2008 15.00.31 skrev Florian Koeberle:
> +class ComplexFilePattern implements FilePattern {
> + /**
> + * Can contain String and
> + */
Could you elaborate on this?
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 14/22] Added the class IgnoreRuleListFactory.
2008-05-10 13:00 ` [JGIT PATCH 14/22] Added the class IgnoreRuleListFactory Florian Koeberle
@ 2008-05-10 20:53 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:53 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
> +class IgnoreRuleListFactory {
I was just going to suggest this too goes to Repository too... may wait until we
put the pattern to more use. We also need to combine this via som hook with
the Eclise Team settings for ignoreable stuff. So, for now, no change.
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 18/22] Added InvalidPatternException and PathNotInProjectDirectoryException
2008-05-10 13:00 ` [JGIT PATCH 18/22] Added InvalidPatternException and PathNotInProjectDirectoryException Florian Koeberle
@ 2008-05-10 20:53 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:53 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
> +++ b/org.spearce.jgit/src/org/spearce/jgit/errors/InvalidPatternException.java
> +public class InvalidPatternException extends Exception {
> + private static final long serialVersionUID = -606889225458579931L;
We have ignored these so far. The nice thing about not declaring them is
that if we start depending on the we get to see incompatibilities earlier.
Declaring them makes diagnosing incompatibilties harder.
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 19/22] Added the class AddRuleListFactory.
2008-05-10 13:00 ` [JGIT PATCH 19/22] Added the class AddRuleListFactory Florian Koeberle
@ 2008-05-10 20:53 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:53 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
lördagen den 10 maj 2008 15.00.37 skrev Florian Koeberle:
> +class AddRuleListFactory {
> + /*
> + * The add command of git 1.5.2.5 behaves a little bit stange: "git add
> + * a/\*z" adds the file "a/b/xyz" but "git add a/x\*" does not.
> + *
> + * The first is parsed as pattern "*z" for whole directory tree "a". The
> + * second is parsed as an path.
> + *
What do *you* do?
> + */
> +
> + private static List<String> getRelativePath(File projectDirectory, File file)
> + throws PathNotInProjectDirectoryException, IOException {
> + File currentFile = file.getCanonicalFile();
> + final LinkedList<String> relativePath = new LinkedList<String>();
> + while (!currentFile.equals(projectDirectory)) {
> + relativePath.addFirst(currentFile.getName());
> + currentFile = currentFile.getParentFile();
> + if (currentFile == null) {
> + throw new PathNotInProjectDirectoryException();
> + }
> + }
> + return relativePath;
> + }
Would be nice to have this logic in a utility class.
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 21/22] Added test class FileIterableFactoryForAddCommandTest.
2008-05-10 13:00 ` [JGIT PATCH 21/22] Added test class FileIterableFactoryForAddCommandTest Florian Koeberle
@ 2008-05-10 20:53 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:53 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
> +public class FileIterableFactoryForAddCommandTest extends TestCase {
We have RepositoryTestcase that we use for unit tests that require a test repository.
Consider using it. If not usable, why not? Maybe we can fix that. It includes logic
to clean on "next" and handle some messy problems of cleaning up and avoiding
problems when re-running failed tests under Windows (read "locked files and directories");
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 22/22] Added a "add" command to the git like command line tool.
2008-05-10 13:00 ` [JGIT PATCH 22/22] Added a "add" command to the git like command line tool Florian Koeberle
@ 2008-05-10 20:54 ` Robin Rosenberg
0 siblings, 0 replies; 35+ messages in thread
From: Robin Rosenberg @ 2008-05-10 20:54 UTC (permalink / raw)
To: Florian Koeberle; +Cc: git
> +/**
> + * This class is immutable. It's {@link #execute} method is used to add files to
> + * the index.
Change the order of the sentences so the first sentence is the summary.
-- robin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules.
2008-05-10 20:45 ` [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Robin Rosenberg
@ 2008-05-11 0:16 ` Shawn O. Pearce
0 siblings, 0 replies; 35+ messages in thread
From: Shawn O. Pearce @ 2008-05-11 0:16 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: Florian Koeberle, git
Robin Rosenberg <robin.rosenberg.lists@dewire.com> wrote:
> lördagen den 10 maj 2008 15.00.18 skrev Florian Koeberle:
> >
> Welcome to the project Florian!
>
> > here are the patches.
> >
> > The implementation does a lot of performance optimizations:
>
> [...], not trying to be too picky and requiring
> you to think of everyhing I don't. We always play rough with newcomers :)
Not just newcomers, we play rough with everyone! :-)
Personally, I love this environment. Because of how tough everyone
is on each other's patches I've learned more in the past few years
here working on Git than I have learned in 4x that amount of time
working elsewhere.
--
Shawn.
^ permalink raw reply [flat|nested] 35+ messages in thread
end of thread, other threads:[~2008-05-11 0:17 UTC | newest]
Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-10 13:00 [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 01/22] Start of an implementation of a git like command line tool Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 02/22] Replaced Java 6 API useage with Java 5 equivalent Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 03/22] Added a class Project which represents a project directory and it's repository Florian Koeberle
2008-05-10 20:45 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 04/22] Added a "init" command to the git like command line tool Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 05/22] Added ProjectSeeker class Florian Koeberle
2008-05-10 20:45 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 06/22] Added the interface FilePattern Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 07/22] Added the class Rule Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 08/22] Added the iterface Rules Florian Koeberle
2008-05-10 20:46 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 09/22] Added the class FileTreeIterator and a test for it Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 10/22] Added class FileTreeIterable Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 11/22] Added the class StarPattern Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 12/22] Added the class GlobalFilePattern Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 13/22] Added the class ComplexFilePattern Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 14/22] Added the class IgnoreRuleListFactory Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 15/22] Added a Rules interface implementation and a factory for it Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 16/22] Added test class OverallIgnoreRulestest Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 17/22] Added the class TreeFilePattern Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 18/22] Added InvalidPatternException and PathNotInProjectDirectoryException Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 19/22] Added the class AddRuleListFactory Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 20/22] Added class FileIterableFactoryForAddCommand Florian Koeberle
2008-05-10 13:00 ` [JGIT PATCH 21/22] Added test class FileIterableFactoryForAddCommandTest Florian Koeberle
2008-05-10 20:53 ` Robin Rosenberg
2008-05-10 13:00 ` [JGIT PATCH 22/22] Added a "add" command to the git like command line tool Florian Koeberle
2008-05-10 20:54 ` Robin Rosenberg
2008-05-10 20:45 ` [JGIT PATCH 0/m] Implementation of a file tree iteration using ignore rules Robin Rosenberg
2008-05-11 0:16 ` Shawn O. Pearce
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).