summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2014-10-17 09:58:39 +0200
committerStefan Lay <stefan.lay@sap.com>2014-11-03 04:32:03 -0500
commit95172dea173425697814e3ba0b4eb823301bf7d0 (patch)
treeae756d314fcc9962402ca2a20896e59b64347007 /org.eclipse.jgit
parent2f5a08798eb29e8141c452c0dc2622bc8fe90dd0 (diff)
downloadjgit-95172dea173425697814e3ba0b4eb823301bf7d0.tar.gz
jgit-95172dea173425697814e3ba0b4eb823301bf7d0.zip
Support for Submodule configuration submodule.<name>.ignore
For each submodule native git allows to configure which modifications to submodules should be ignored by the status command. It is possible to ignore "none", "all", "dirty", "untracked" [1]. This configuration is now supported by IndexDiff. The StatusCommand offers the possibility to specify this mode. [1] http://git-scm.com/docs/gitmodules Change-Id: Ifd81d574a680f9b4152945ba70f8ec4af4f452c9
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java118
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java44
4 files changed, 167 insertions, 12 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java
index dee0a31b91..fe2d848e54 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java
@@ -53,6 +53,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.IndexDiff;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
@@ -72,6 +73,8 @@ public class StatusCommand extends GitCommand<Status> {
private List<String> paths = null;
private ProgressMonitor progressMonitor = null;
+ private IgnoreSubmoduleMode ignoreSubmoduleMode = null;
+
/**
* @param repo
*/
@@ -80,6 +83,15 @@ public class StatusCommand extends GitCommand<Status> {
}
/**
+ * @param mode
+ * @return {@code this}
+ */
+ public StatusCommand setIgnoreSubmodules(IgnoreSubmoduleMode mode) {
+ ignoreSubmoduleMode = mode;
+ return this;
+ }
+
+ /**
* Show only the status of files which match the given paths. The path must
* either name a file or a directory exactly. All paths are always relative
* to the repository root. If a directory is specified all files recursively
@@ -127,6 +139,8 @@ public class StatusCommand extends GitCommand<Status> {
try {
IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);
+ if (ignoreSubmoduleMode != null)
+ diff.setIgnoreSubmoduleMode(ignoreSubmoduleMode);
if (paths != null)
diff.setFilter(PathFilterGroup.createFromStrings(paths));
if (progressMonitor == null)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
index 61b05c8b48..7361e29ed4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
@@ -208,6 +208,9 @@ public class ConfigConstants {
/** The "update" key */
public static final String CONFIG_KEY_UPDATE = "update";
+ /** The "update" key */
+ public static final String CONFIG_KEY_IGNORE = "ignore";
+
/** The "compression" key */
public static final String CONFIG_KEY_COMPRESSION = "compression";
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index 8eb0333550..684b18af9b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -58,13 +58,17 @@ import java.util.Set;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator;
+import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StopWalkException;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.submodule.SubmoduleWalk;
+import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
+import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
@@ -268,6 +272,10 @@ public class IndexDiff {
private IndexDiffFilter indexDiffFilter;
+ private Map<String, IndexDiff> submoduleIndexDiffs = new HashMap<String, IndexDiff>();
+
+ private IgnoreSubmoduleMode ignoreSubmoduleMode = null;
+
/**
* Construct an IndexDiff
*
@@ -281,13 +289,7 @@ public class IndexDiff {
*/
public IndexDiff(Repository repository, String revstr,
WorkingTreeIterator workingTreeIterator) throws IOException {
- this.repository = repository;
- ObjectId objectId = repository.resolve(revstr);
- if (objectId != null)
- tree = new RevWalk(repository).parseTree(objectId);
- else
- tree = null;
- this.initialWorkingTreeIterator = workingTreeIterator;
+ this(repository, repository.resolve(revstr), workingTreeIterator);
}
/**
@@ -311,6 +313,40 @@ public class IndexDiff {
}
/**
+ * @param mode
+ * defines how modifications in submodules are treated
+ */
+ public void setIgnoreSubmoduleMode(IgnoreSubmoduleMode mode) {
+ this.ignoreSubmoduleMode = mode;
+ }
+
+ /**
+ * A factory to producing WorkingTreeIterators
+ */
+ public interface WorkingTreeIteratorFactory {
+ /**
+ * @param repo
+ * @return a WorkingTreeIterator for repo
+ */
+ public WorkingTreeIterator getWorkingTreeIterator(Repository repo);
+ }
+
+ private WorkingTreeIteratorFactory wTreeIt = new WorkingTreeIteratorFactory() {
+ public WorkingTreeIterator getWorkingTreeIterator(Repository repo) {
+ return new FileTreeIterator(repo);
+ }
+ };
+
+ /**
+ * Allows higher layers to set the factory for WorkingTreeIterators.
+ *
+ * @param wTreeIt
+ */
+ public void setWorkingTreeItFactory(WorkingTreeIteratorFactory wTreeIt) {
+ this.wTreeIt = wTreeIt;
+ }
+
+ /**
* Sets a filter. Can be used e.g. for restricting the tree walk to a set of
* files.
*
@@ -413,18 +449,25 @@ public class IndexDiff {
|| treeIterator.getEntryRawMode()
!= dirCacheIterator.getEntryRawMode()) {
// in repo, in index, content diff => changed
- changed.add(treeWalk.getPathString());
+ if (!isEntryGitLink(treeIterator)
+ || !isEntryGitLink(dirCacheIterator)
+ || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
+ changed.add(treeWalk.getPathString());
}
} else {
// in repo, not in index => removed
- removed.add(treeWalk.getPathString());
+ if (!isEntryGitLink(treeIterator)
+ || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
+ removed.add(treeWalk.getPathString());
if (workingTreeIterator != null)
untracked.add(treeWalk.getPathString());
}
} else {
if (dirCacheIterator != null) {
// not in repo, in index => added
- added.add(treeWalk.getPathString());
+ if (!isEntryGitLink(dirCacheIterator)
+ || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
+ added.add(treeWalk.getPathString());
} else {
// not in repo, not in index => untracked
if (workingTreeIterator != null
@@ -437,13 +480,59 @@ public class IndexDiff {
if (dirCacheIterator != null) {
if (workingTreeIterator == null) {
// in index, not in workdir => missing
- missing.add(treeWalk.getPathString());
+ if (!isEntryGitLink(dirCacheIterator)
+ || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
+ missing.add(treeWalk.getPathString());
} else {
if (workingTreeIterator.isModified(
dirCacheIterator.getDirCacheEntry(), true,
treeWalk.getObjectReader())) {
// in index, in workdir, content differs => modified
- modified.add(treeWalk.getPathString());
+ if (!isEntryGitLink(dirCacheIterator) || !isEntryGitLink(workingTreeIterator)
+ || (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL && ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
+ modified.add(treeWalk.getPathString());
+ }
+ }
+ }
+ }
+
+ if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) {
+ IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode;
+ SubmoduleWalk smw = SubmoduleWalk.forIndex(repository);
+ while (smw.next()) {
+ try {
+ if (localIgnoreSubmoduleMode == null)
+ localIgnoreSubmoduleMode = smw.getModulesIgnore();
+ if (IgnoreSubmoduleMode.ALL
+ .equals(localIgnoreSubmoduleMode))
+ continue;
+ } catch (ConfigInvalidException e) {
+ throw new IOException(
+ "Found invalid ignore param for submodule "
+ + smw.getPath());
+ }
+ Repository subRepo = smw.getRepository();
+ ObjectId subHead = subRepo.resolve("HEAD");
+ if (subHead != null && !subHead.equals(smw.getObjectId()))
+ modified.add(smw.getPath());
+ else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
+ IndexDiff smid = submoduleIndexDiffs.get(smw.getPath());
+ if (smid == null) {
+ smid = new IndexDiff(subRepo, smw.getObjectId(),
+ wTreeIt.getWorkingTreeIterator(subRepo));
+ submoduleIndexDiffs.put(smw.getPath(), smid);
+ }
+ if (smid.diff()) {
+ if (ignoreSubmoduleMode == IgnoreSubmoduleMode.UNTRACKED
+ && smid.getAdded().isEmpty()
+ && smid.getChanged().isEmpty()
+ && smid.getConflicting().isEmpty()
+ && smid.getMissing().isEmpty()
+ && smid.getModified().isEmpty()
+ && smid.getRemoved().isEmpty()) {
+ continue;
+ }
+ modified.add(smw.getPath());
}
}
}
@@ -462,6 +551,11 @@ public class IndexDiff {
return true;
}
+ private boolean isEntryGitLink(AbstractTreeIterator ti) {
+ return ((ti != null) && (ti.getEntryRawMode() == FileMode.GITLINK
+ .getBits()));
+ }
+
private void addConflict(String path, int stage) {
StageState existingStageStates = conflicts.get(path);
byte stageMask = 0;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
index c31ffd1f7d..30eca741f3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
@@ -79,6 +79,31 @@ import org.eclipse.jgit.util.FS;
public class SubmoduleWalk {
/**
+ * The values for the config param submodule.<name>.ignore
+ */
+ public enum IgnoreSubmoduleMode {
+ /**
+ * Ignore all modifications to submodules
+ */
+ ALL,
+
+ /**
+ * Ignore changes to the working tree of a submodule
+ */
+ DIRTY,
+
+ /**
+ * Ignore changes to untracked files in the working tree of a submodule
+ */
+ UNTRACKED,
+
+ /**
+ * Ignore nothing. That's the default
+ */
+ NONE;
+ }
+
+ /**
* Create a generator to walk over the submodule entries currently in the
* index
*
@@ -600,6 +625,25 @@ public class SubmoduleWalk {
}
/**
+ * Get the configured ignore field for the current entry. This will be the
+ * value from the .gitmodules file in the current repository's working tree.
+ *
+ * @return ignore value
+ * @throws ConfigInvalidException
+ * @throws IOException
+ */
+ public IgnoreSubmoduleMode getModulesIgnore() throws IOException,
+ ConfigInvalidException {
+ lazyLoadModulesConfig();
+ String name = modulesConfig.getString(
+ ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
+ ConfigConstants.CONFIG_KEY_IGNORE);
+ if (name == null)
+ return null;
+ return IgnoreSubmoduleMode.valueOf(name.trim().toUpperCase());
+ }
+
+ /**
* Get repository for current submodule entry
*
* @return repository or null if non-existent