summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/.settings/.api_filters7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java32
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FilteredRevCommit.java115
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/Paths.java35
5 files changed, 59 insertions, 136 deletions
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index 8aa84f3ac1..4af7adc72b 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -83,4 +83,11 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/jgit/util/Paths.java" type="org.eclipse.jgit.util.Paths">
+ <filter id="337768515">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.util.Paths"/>
+ </message_arguments>
+ </filter>
+ </resource>
</component>
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java
index 69272b7547..36ca97d694 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java
@@ -25,6 +25,7 @@ import org.eclipse.jgit.events.WorkingTreeModifiedEvent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.Paths;
/**
* Remove untracked files from the working tree
@@ -91,15 +92,16 @@ public class CleanCommand extends GitCommand<Set<String>> {
Set<String> notIgnoredDirs = filterIgnorePaths(untrackedDirs,
status.getIgnoredNotInIndex(), false);
- for (String file : notIgnoredFiles)
+ for (String file : notIgnoredFiles) {
if (paths.isEmpty() || paths.contains(file)) {
files = cleanPath(file, files);
}
-
- for (String dir : notIgnoredDirs)
+ }
+ for (String dir : notIgnoredDirs) {
if (paths.isEmpty() || paths.contains(dir)) {
files = cleanPath(dir, files);
}
+ }
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
} finally {
@@ -142,14 +144,14 @@ public class CleanCommand extends GitCommand<Set<String>> {
FileUtils.delete(curFile, FileUtils.RECURSIVE
| FileUtils.SKIP_MISSING);
}
- inFiles.add(path + "/"); //$NON-NLS-1$
+ inFiles.add(path + '/');
}
} else {
if (!dryRun) {
FileUtils.delete(curFile,
FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
}
- inFiles.add(path + "/"); //$NON-NLS-1$
+ inFiles.add(path + '/');
}
}
} else {
@@ -166,14 +168,16 @@ public class CleanCommand extends GitCommand<Set<String>> {
Set<String> ignoredNotInIndex, boolean exact) {
if (ignore) {
Set<String> filtered = new TreeSet<>(inputPaths);
- for (String path : inputPaths)
- for (String ignored : ignoredNotInIndex)
+ for (String path : inputPaths) {
+ for (String ignored : ignoredNotInIndex) {
if ((exact && path.equals(ignored))
- || (!exact && path.startsWith(ignored))) {
+ || (!exact
+ && Paths.isEqualOrPrefix(ignored, path))) {
filtered.remove(path);
break;
}
-
+ }
+ }
return filtered;
}
return inputPaths;
@@ -182,14 +186,14 @@ public class CleanCommand extends GitCommand<Set<String>> {
private Set<String> filterFolders(Set<String> untracked,
Set<String> untrackedFolders) {
Set<String> filtered = new TreeSet<>(untracked);
- for (String file : untracked)
- for (String folder : untrackedFolders)
- if (file.startsWith(folder)) {
+ for (String file : untracked) {
+ for (String folder : untrackedFolders) {
+ if (Paths.isEqualOrPrefix(folder, file)) {
filtered.remove(file);
break;
}
-
-
+ }
+ }
return filtered;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FilteredRevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FilteredRevCommit.java
deleted file mode 100644
index be6e57fd5f..0000000000
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FilteredRevCommit.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2022, Google LLC.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Distribution License v. 1.0 which is available at
- * https://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-package org.eclipse.jgit.revwalk;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-/** A filtered commit reference that overrides its parent in the DAG. */
-public class FilteredRevCommit extends RevCommit {
- private RevCommit[] overriddenParents;
-
- /**
- * Create a new commit reference for the given id.
- *
- * @param id
- * object name for the commit.
- */
- public FilteredRevCommit(ObjectId id) {
- this(id, NO_PARENTS);
- }
-
- /**
- * Create a new commit reference wrapping an underlying commit reference.
- *
- * @param commit
- * commit that is being wrapped
- */
- public FilteredRevCommit(RevCommit commit) {
- this(commit, NO_PARENTS);
- }
-
- /**
- * Create a new commit reference wrapping an underlying commit reference.
- *
- * @param commit
- * commit that is being wrapped
- * @param parents
- * overridden parents for the commit
- */
- public FilteredRevCommit(RevCommit commit, RevCommit... parents) {
- this(commit.getId(), parents);
- }
-
- /**
- * Create a new commit reference wrapping an underlying commit reference.
- *
- * @param id
- * object name for the commit.
- * @param parents
- * overridden parents for the commit
- */
- public FilteredRevCommit(ObjectId id, RevCommit... parents) {
- super(id);
- this.overriddenParents = parents;
- }
-
- /**
- * Update parents on the commit
- *
- * @param overriddenParents
- * parents to be overwritten
- */
- public void setParents(RevCommit... overriddenParents) {
- this.overriddenParents = overriddenParents;
- }
-
- /**
- * Get the number of parent commits listed in this commit.
- *
- * @return number of parents; always a positive value but can be 0 if it has
- * no parents.
- */
- @Override
- public int getParentCount() {
- return overriddenParents.length;
- }
-
- /**
- * Get the nth parent from this commit's parent list.
- *
- * @param nth
- * parent index to obtain. Must be in the range 0 through
- * {@link #getParentCount()}-1.
- * @return the specified parent.
- * @throws java.lang.ArrayIndexOutOfBoundsException
- * an invalid parent index was specified.
- */
- @Override
- public RevCommit getParent(int nth) {
- return overriddenParents[nth];
- }
-
- /**
- * Obtain an array of all parents (<b>NOTE - THIS IS NOT A COPY</b>).
- *
- * <p>
- * This method is exposed only to provide very fast, efficient access to
- * this commit's parent list. Applications relying on this list should be
- * very careful to ensure they do not modify its contents during their use
- * of it.
- *
- * @return the array of parents.
- */
- @Override
- public RevCommit[] getParents() {
- return overriddenParents;
- }
-}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java
index 3318a97a3f..2c88bb872e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java
@@ -79,9 +79,9 @@ class RewriteGenerator extends Generator {
final RevCommit newp = rewrite(oldp);
if (firstParent) {
if (newp == null) {
- c = new FilteredRevCommit(c.getId());
+ c.parents = RevCommit.NO_PARENTS;
} else {
- c = new FilteredRevCommit(c.getId(), newp);
+ c.parents = new RevCommit[] { newp };
}
return c;
}
@@ -91,7 +91,7 @@ class RewriteGenerator extends Generator {
}
}
if (rewrote) {
- c = new FilteredRevCommit(c.getId(), cleanup(pList));
+ c.parents = cleanup(pList);
}
return c;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/Paths.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/Paths.java
index 5a39f95b2b..ae13ef7f3c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/Paths.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/Paths.java
@@ -18,7 +18,8 @@ import static org.eclipse.jgit.lib.FileMode.TYPE_TREE;
*
* @since 4.2
*/
-public class Paths {
+public final class Paths {
+
/**
* Remove trailing {@code '/'} if present.
*
@@ -43,6 +44,33 @@ public class Paths {
}
/**
+ * Determines whether a git path {@code folder} is a prefix of another git
+ * path {@code path}, or the same as {@code path}. An empty {@code folder}
+ * is <em>not</em> not considered a prefix and matches only if {@code path}
+ * is also empty.
+ *
+ * @param folder
+ * a git path for a directory, without trailing slash
+ * @param path
+ * a git path
+ * @return {@code true} if {@code folder} is a directory prefix of
+ * {@code path}, or is equal to {@code path}, {@code false}
+ * otherwise
+ * @since 6.3
+ */
+ public static boolean isEqualOrPrefix(String folder, String path) {
+ if (folder.isEmpty()) {
+ return path.isEmpty();
+ }
+ boolean isPrefix = path.startsWith(folder);
+ if (isPrefix) {
+ int length = folder.length();
+ return path.length() == length || path.charAt(length) == '/';
+ }
+ return false;
+ }
+
+ /**
* Compare two paths according to Git path sort ordering rules.
*
* @param aPath
@@ -63,9 +91,8 @@ public class Paths {
* @param bMode
* mode of the second file. Trees are sorted as though
* {@code bPath[bEnd] == '/'}, even if bEnd does not exist.
- * @return &lt;0 if {@code aPath} sorts before {@code bPath};
- * 0 if the paths are the same;
- * &gt;0 if {@code aPath} sorts after {@code bPath}.
+ * @return &lt;0 if {@code aPath} sorts before {@code bPath}; 0 if the paths
+ * are the same; &gt;0 if {@code aPath} sorts after {@code bPath}.
*/
public static int compare(byte[] aPath, int aPos, int aEnd, int aMode,
byte[] bPath, int bPos, int bEnd, int bMode) {