aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2010-08-09 18:48:56 (EDT)
committerChris Aniszczyk2010-08-11 20:47:33 (EDT)
commitdb9d89fe2f908a14cbdf1e04230cf17505b18462 (patch)
tree26cf3d0ae01a6434fc264816898de261a7056c25
parenta15eaffd115ba8de82c44ffca066375fa149209a (diff)
downloadegit-db9d89fe2f908a14cbdf1e04230cf17505b18462.zip
egit-db9d89fe2f908a14cbdf1e04230cf17505b18462.tar.gz
egit-db9d89fe2f908a14cbdf1e04230cf17505b18462.tar.bz2
Adds support for change direction decorator.refs/changes/70/1270/4
Add support for image decorations describing change direction on commit, folder and file level. Change-Id: I31dfaf78542ef771293f4259f718446c38f6d8a5 Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java54
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java118
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java15
3 files changed, 145 insertions, 42 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java
index cb534f9..ebc6248 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelBlob.java
@@ -14,8 +14,6 @@ import java.io.IOException;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.ITypedElement;
-import org.eclipse.compare.structuremergeviewer.Differencer;
-import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -27,14 +25,11 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.team.ui.mapping.ISynchronizationCompareInput;
-import org.eclipse.team.ui.mapping.SaveableComparison;
/**
* Git blob object representation in Git ChangeSet
*/
-public class GitModelBlob extends GitModelCommit implements ISynchronizationCompareInput {
+public class GitModelBlob extends GitModelCommit {
private final String name;
@@ -99,15 +94,7 @@ public class GitModelBlob extends GitModelCommit implements ISynchronizationComp
return location;
}
- public Image getImage() {
- // currently itsn't used
- return null;
- }
-
- public int getKind() {
- return Differencer.CONFLICTING;
- }
-
+ @Override
public ITypedElement getAncestor() {
if (objectExist(getAncestorCommit(), ancestorId))
return CompareUtils.getFileRevisionTypedElement(gitPath,
@@ -116,43 +103,38 @@ public class GitModelBlob extends GitModelCommit implements ISynchronizationComp
return null;
}
+ @Override
public ITypedElement getLeft() {
return CompareUtils.getFileRevisionTypedElement(gitPath,
getRemoteCommit(), getRepository(), remoteId);
-
}
+ @Override
public ITypedElement getRight() {
return CompareUtils.getFileRevisionTypedElement(gitPath,
getBaseCommit(), getRepository(), baseId);
}
- public void addCompareInputChangeListener(
- ICompareInputChangeListener listener) {
- // data in commit will never change, therefore change listeners are
- // useless
+ @Override
+ protected String getAncestorSha1() {
+ return ancestorId.getName();
}
- public void removeCompareInputChangeListener(
- ICompareInputChangeListener listener) {
- // data in commit will never change, therefore change listeners are
- // useless
+ @Override
+ protected String getBaseSha1() {
+ return baseId.getName();
}
- public void copy(boolean leftToRight) {
- // do nothing, we should disallow coping content between commits
+ @Override
+ protected String getRemoteSha1() {
+ return remoteId.getName();
}
private boolean objectExist(RevCommit commit, ObjectId id) {
return commit != null && id != null && !id.equals(zeroId());
}
- public SaveableComparison getSaveable() {
- // TODO Auto-generated method stub
- return null;
- }
-
public void prepareInput(CompareConfiguration configuration,
IProgressMonitor monitor) throws CoreException {
configuration.setLeftLabel(getFileRevisionLabel(getLeft()));
@@ -173,14 +155,4 @@ public class GitModelBlob extends GitModelCommit implements ISynchronizationComp
return element.getName();
}
- public String getFullPath() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public boolean isCompareInputFor(Object object) {
- // TODO Auto-generated method stub
- return false;
- }
-
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
index 5b8c92c..23a5807 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
@@ -8,12 +8,25 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.synchronize.model;
+import static org.eclipse.jgit.lib.ObjectId.zeroId;
+import static org.eclipse.team.core.synchronize.SyncInfo.ADDITION;
+import static org.eclipse.team.core.synchronize.SyncInfo.CHANGE;
+import static org.eclipse.team.core.synchronize.SyncInfo.CONFLICTING;
+import static org.eclipse.team.core.synchronize.SyncInfo.DELETION;
+import static org.eclipse.team.core.synchronize.SyncInfo.INCOMING;
+import static org.eclipse.team.core.synchronize.SyncInfo.OUTGOING;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.core.Activator;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -21,11 +34,14 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.team.ui.mapping.ISynchronizationCompareInput;
+import org.eclipse.team.ui.mapping.SaveableComparison;
/**
* Git commit object representation in Git ChangeSet
*/
-public class GitModelCommit extends GitModelObject {
+public class GitModelCommit extends GitModelObject implements ISynchronizationCompareInput {
private final RevCommit baseCommit;
@@ -33,6 +49,8 @@ public class GitModelCommit extends GitModelObject {
private final RevCommit ancestorCommit;
+ private int kind = -1;
+
private String name;
private GitModelObject[] children;
@@ -151,6 +169,67 @@ public class GitModelCommit extends GitModelObject {
return remoteCommit.hashCode();
}
+ public Image getImage() {
+ // currently itsn't used
+ return null;
+ }
+
+ public int getKind() {
+ if (kind == -1)
+ calculateKind(getAncestorSha1(), getBaseSha1(), getRemoteSha1());
+
+ return kind;
+ }
+
+ public ITypedElement getAncestor() {
+ return null;
+ }
+
+ public ITypedElement getLeft() {
+ return null;
+ }
+
+ public ITypedElement getRight() {
+ return null;
+ }
+
+ public void addCompareInputChangeListener(
+ ICompareInputChangeListener listener) {
+ // data in commit will never change, therefore change listeners are
+ // useless
+ }
+
+ public void removeCompareInputChangeListener(
+ ICompareInputChangeListener listener) {
+ // data in commit will never change, therefore change listeners are
+ // useless
+ }
+
+ public void copy(boolean leftToRight) {
+ // do nothing, we should disallow coping content between commits
+ }
+
+ /**
+ * @return SHA1 of ancestor object
+ */
+ protected String getAncestorSha1() {
+ return ancestorCommit.getId().getName();
+ }
+
+ /**
+ * @return SHA1 of base object
+ */
+ protected String getBaseSha1() {
+ return baseCommit.getId().getName();
+ }
+
+ /**
+ * @return SHA1 of remote object
+ */
+ protected String getRemoteSha1() {
+ return remoteCommit.getId().getName();
+ }
+
private RevCommit calculateAncestor(RevCommit actual) throws IOException {
RevWalk rw = new RevWalk(getRepository());
rw.setRevFilter(RevFilter.MERGE_BASE);
@@ -213,4 +292,41 @@ public class GitModelCommit extends GitModelObject {
return null;
}
+ private void calculateKind(String ancestorSha1, String baseSha1,
+ String remoteSha1) {
+ if (ancestorSha1.equals(baseSha1))
+ kind = INCOMING;
+ else if (ancestorSha1.equals(baseSha1))
+ kind = OUTGOING;
+ else
+ kind = CONFLICTING;
+
+ if (baseSha1.equals(zeroId().getName()))
+ kind = kind | ADDITION;
+ else if (remoteSha1.equals(zeroId().getName()))
+ kind = kind | DELETION;
+ else
+ kind = kind | CHANGE;
+ }
+
+ public SaveableComparison getSaveable() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void prepareInput(CompareConfiguration configuration,
+ IProgressMonitor monitor) throws CoreException {
+ // there is no needed configuration for commit object
+ }
+
+ public String getFullPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isCompareInputFor(Object object) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java
index 65ae9a2..475ef14 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java
@@ -109,6 +109,21 @@ public class GitModelTree extends GitModelCommit {
return location;
}
+ @Override
+ protected String getAncestorSha1() {
+ return ancestorId.getName();
+ }
+
+ @Override
+ protected String getBaseSha1() {
+ return baseId.getName();
+ }
+
+ @Override
+ protected String getRemoteSha1() {
+ return remoteId.getName();
+ }
+
private void getChildrenImpl() {
TreeWalk tw = createTreeWalk();
List<GitModelObject> result = new ArrayList<GitModelObject>();