diff options
author | Andrey Loskutov | 2015-08-01 15:52:24 +0000 |
---|---|---|
committer | Andrey Loskutov | 2015-08-01 15:52:24 +0000 |
commit | 821b5a0299d76815d6ab8088fff761e7b099e56c (patch) | |
tree | 95330ad353611f40f508ca0c9062ae1bc3a8046c /org.eclipse.egit.core/src/org/eclipse/egit/core | |
parent | 0ba5b25039d2f1154996cd3c9da8bcb033c1e4d2 (diff) | |
download | egit-821b5a0299d76815d6ab8088fff761e7b099e56c.tar.gz egit-821b5a0299d76815d6ab8088fff761e7b099e56c.tar.xz egit-821b5a0299d76815d6ab8088fff761e7b099e56c.zip |
Allow creation of empty IndexDiffData objects
Also make sure all getters are consistently returning non null data.
Change-Id: I239a7a113dfd0d69e4b9216b9ef0ae351a4a5a8d
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.egit.core/src/org/eclipse/egit/core')
-rw-r--r-- | org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffData.java | 33 | ||||
-rw-r--r-- | org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java | 26 |
2 files changed, 43 insertions, 16 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffData.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffData.java index d30ed36a1c..c0b5d26dcb 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffData.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffData.java @@ -14,6 +14,7 @@ import java.util.HashSet; import java.util.Set; import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.IndexDiff; @@ -51,6 +52,24 @@ public class IndexDiffData { private final Collection<IResource> changedResources; /** + * Empty, immutable data + */ + public IndexDiffData() { + added = Collections.emptySet(); + changed = Collections.emptySet(); + removed = Collections.emptySet(); + missing = Collections.emptySet(); + modified = Collections.emptySet(); + untracked = Collections.emptySet(); + untrackedFolders = Collections.emptySet(); + conflicts = Collections.emptySet(); + ignored = Collections.emptySet(); + symlinks = Collections.emptySet(); + submodules = Collections.emptySet(); + changedResources = Collections.emptySet(); + } + + /** * @param indexDiff */ public IndexDiffData(IndexDiff indexDiff) { @@ -75,7 +94,7 @@ public class IndexDiffData { .getPathsWithIndexMode(FileMode.SYMLINK))); submodules = Collections.unmodifiableSet(new HashSet<String>(indexDiff .getPathsWithIndexMode(FileMode.GITLINK))); - changedResources = null; + changedResources = Collections.emptySet(); } private Set<String> getUntrackedFolders(IndexDiff indexDiff) { @@ -224,6 +243,7 @@ public class IndexDiffData { /** * @return list of files added to the index, not in the tree */ + @NonNull public Set<String> getAdded() { return Collections.unmodifiableSet(added); } @@ -231,6 +251,7 @@ public class IndexDiffData { /** * @return list of files changed from tree to index */ + @NonNull public Set<String> getChanged() { return changed; } @@ -238,6 +259,7 @@ public class IndexDiffData { /** * @return list of files removed from index, but in tree */ + @NonNull public Set<String> getRemoved() { return removed; } @@ -245,6 +267,7 @@ public class IndexDiffData { /** * @return list of files in index, but not filesystem */ + @NonNull public Set<String> getMissing() { return missing; } @@ -252,6 +275,7 @@ public class IndexDiffData { /** * @return list of files modified on disk relative to the index */ + @NonNull public Set<String> getModified() { return modified; } @@ -259,6 +283,7 @@ public class IndexDiffData { /** * @return list of files that are not ignored, and not in the index. */ + @NonNull public Set<String> getUntracked() { return untracked; } @@ -267,6 +292,7 @@ public class IndexDiffData { * @return list of folders containing only untracked files/folders * The folder paths end with / */ + @NonNull public Set<String> getUntrackedFolders() { return untrackedFolders; } @@ -274,6 +300,7 @@ public class IndexDiffData { /** * @return list of files that are in conflict */ + @NonNull public Set<String> getConflicting() { return conflicts; } @@ -282,6 +309,7 @@ public class IndexDiffData { * @see IndexDiff#getIgnoredNotInIndex() * @return list of files that are ignored */ + @NonNull public Set<String> getIgnoredNotInIndex() { return ignored; } @@ -289,6 +317,7 @@ public class IndexDiffData { /** * @return list of files that are symlinks */ + @NonNull public Set<String> getSymlinks() { return symlinks; } @@ -296,6 +325,7 @@ public class IndexDiffData { /** * @return list of files that are submodules */ + @NonNull public Set<String> getSubmodules() { return submodules; } @@ -303,6 +333,7 @@ public class IndexDiffData { /** * @return the changed files */ + @NonNull public Collection<IResource> getChangedResources() { return changedResources; } diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java index ba518a4d86..5dda5b81cb 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java @@ -537,21 +537,17 @@ public class ResourceUtil { if (indexDiffData != null) { Collection<IResource> changedResources = indexDiffData .getChangedResources(); - if (changedResources != null) { - for (IResource changedResource : changedResources) { - if (changedResource instanceof IFile - && changedResource.exists()) { - try { - ResourceUtil.saveLocalHistory(changedResource); - } catch (CoreException e) { - // Ignore error. Failure to save local history must - // not interfere with the operation. - Activator - .logError( - MessageFormat - .format(CoreText.ResourceUtil_SaveLocalHistoryFailed, - changedResource), e); - } + for (IResource changedResource : changedResources) { + if (changedResource instanceof IFile + && changedResource.exists()) { + try { + ResourceUtil.saveLocalHistory(changedResource); + } catch (CoreException e) { + // Ignore error. Failure to save local history must + // not interfere with the operation. + Activator.logError(MessageFormat.format( + CoreText.ResourceUtil_SaveLocalHistoryFailed, + changedResource), e); } } } |