diff options
Diffstat (limited to 'org.eclipse.egit.ui')
5 files changed, 254 insertions, 313 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 4e9ae809eb..7e579367a4 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 @@ -16,7 +16,6 @@ import java.io.IOException; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.ITypedElement; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -63,7 +62,7 @@ public class GitModelBlob extends GitModelCommit { * human readable blob name (file name) * @throws IOException */ - public GitModelBlob(GitModelCommit parent, RevCommit commit, + public GitModelBlob(GitModelObjectContainer parent, RevCommit commit, ObjectId ancestorId, ObjectId baseId, ObjectId remoteId, String name) throws IOException { // only direction is important for us, therefore we mask rest of bits in kind @@ -88,11 +87,6 @@ public class GitModelBlob extends GitModelCommit { } @Override - public IProject[] getProjects() { - return getParent().getProjects(); - } - - @Override public IPath getLocation() { return location; } @@ -125,19 +119,6 @@ public class GitModelBlob extends GitModelCommit { } @Override - protected ObjectId getBaseObjectId() { - return baseId; - } - - @Override - protected ObjectId getRemoteObjectId() { - return remoteId; - } - - private boolean objectExist(RevCommit commit, ObjectId id) { - return commit != null && id != null && !id.equals(zeroId()); - } - public void prepareInput(CompareConfiguration configuration, IProgressMonitor monitor) throws CoreException { configuration.setLeftLabel(getFileRevisionLabel(getLeft())); @@ -145,6 +126,10 @@ public class GitModelBlob extends GitModelCommit { } + private boolean objectExist(RevCommit commit, ObjectId id) { + return commit != null && id != null && !id.equals(zeroId()); + } + private String getFileRevisionLabel(ITypedElement element) { if (element instanceof FileRevisionTypedElement) { FileRevisionTypedElement castElement = (FileRevisionTypedElement)element; 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 b9698969ec..7f64050d21 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,55 +8,23 @@ *******************************************************************************/ package org.eclipse.egit.ui.internal.synchronize.model; -import static org.eclipse.compare.structuremergeviewer.Differencer.ADDITION; -import static org.eclipse.compare.structuremergeviewer.Differencer.CHANGE; -import static org.eclipse.compare.structuremergeviewer.Differencer.DELETION; -import static org.eclipse.compare.structuremergeviewer.Differencer.LEFT; -import static org.eclipse.compare.structuremergeviewer.Differencer.RIGHT; -import static org.eclipse.jgit.lib.ObjectId.zeroId; - 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.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; -import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.egit.core.Activator; -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; -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 implements +public class GitModelCommit extends GitModelObjectContainer implements ISynchronizationCompareInput { - private final RevCommit baseCommit; - - private final RevCommit remoteCommit; - - private final RevCommit ancestorCommit; - - private int kind; - - private String name; - - private GitModelObject[] children; - /** * @param parent * instance of repository model object that is parent for this @@ -69,17 +37,7 @@ public class GitModelCommit extends GitModelObject implements */ public GitModelCommit(GitModelRepository parent, RevCommit commit, int direction) throws IOException { - super(parent); - kind = direction; - remoteCommit = commit; - ancestorCommit = calculateAncestor(remoteCommit); - - RevCommit[] parents = remoteCommit.getParents(); - if (parents != null && parents.length > 0) - baseCommit = remoteCommit.getParent(0); - else { - baseCommit = null; - } + super(parent, commit, direction); } /** @@ -98,72 +56,7 @@ public class GitModelCommit extends GitModelObject implements */ protected GitModelCommit(GitModelObject parent, RevCommit commit, int direction) throws IOException { - super(parent); - kind = direction; - remoteCommit = commit; - ancestorCommit = calculateAncestor(remoteCommit); - - RevCommit[] parents = remoteCommit.getParents(); - if (parents != null && parents.length > 0) - baseCommit = remoteCommit.getParent(0); - else { - baseCommit = null; - } - } - - @Override - public GitModelObject[] getChildren() { - if (children == null) - getChildrenImpl(); - - return children; - - } - - @Override - public String getName() { - if (name == null) - name = remoteCommit.getShortMessage(); - - return name; - } - - @Override - public IProject[] getProjects() { - return getParent().getProjects(); - } - - /** - * Returns common ancestor for this commit and all it parent's commits. - * - * @return common ancestor commit - */ - public RevCommit getAncestorCommit() { - return ancestorCommit; - } - - /** - * Returns instance of commit that is parent for one that is associated with - * this model object. - * - * @return base commit - */ - public RevCommit getBaseCommit() { - return baseCommit; - } - - /** - * Resurns instance of commit that is associated with this model object. - * - * @return rev commit - */ - public RevCommit getRemoteCommit() { - return remoteCommit; - } - - @Override - public IPath getLocation() { - return getParent().getLocation(); + super(parent, commit, direction); } @Override @@ -199,81 +92,8 @@ public class GitModelCommit extends GitModelObject implements return result; } - public Image getImage() { - // currently itsn't used - return null; - } - - public int getKind() { - if (kind == -1 || kind == LEFT || kind == RIGHT) - calculateKind(getBaseObjectId(), getRemoteObjectId()); - - 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 - } - @Override - public boolean isContainer() { - return true; - } - - /** - * @return base object ObjectId - */ - protected ObjectId getBaseObjectId() { - return baseCommit != null ? baseCommit.getId() : zeroId(); - } - - /** - * @return remote object ObjectId - */ - protected ObjectId getRemoteObjectId() { - return remoteCommit.getId(); - } - - private RevCommit calculateAncestor(RevCommit actual) throws IOException { - RevWalk rw = new RevWalk(getRepository()); - rw.setRevFilter(RevFilter.MERGE_BASE); - - for (RevCommit parent : actual.getParents()) { - RevCommit parentCommit = rw.parseCommit(parent.getId()); - rw.markStart(parentCommit); - } - - rw.markStart(rw.parseCommit(actual.getId())); - - RevCommit result = rw.next(); - return result != null ? result : rw.parseCommit(ObjectId.zeroId()); - } - - private void getChildrenImpl() { + protected GitModelObject[] getChildrenImpl() { List<GitModelObject> result = new ArrayList<GitModelObject>(); try { @@ -296,59 +116,7 @@ public class GitModelCommit extends GitModelObject implements Activator.logError(e.getMessage(), e); } - children = result.toArray(new GitModelObject[result.size()]); - } - - private GitModelObject getModelObject(TreeWalk tw, int ancestorNth, - int baseNth, int actualNth) throws IOException { - String objName = tw.getNameString(); - - ObjectId objBaseId; - if (baseNth > -1) - objBaseId = tw.getObjectId(baseNth); - else - objBaseId = ObjectId.zeroId(); - - ObjectId objRemoteId = tw.getObjectId(actualNth); - ObjectId objAncestorId = tw.getObjectId(ancestorNth); - int objectType = tw.getFileMode(actualNth).getObjectType(); - - if (objectType == Constants.OBJ_BLOB) - return new GitModelBlob(this, remoteCommit, objAncestorId, - objBaseId, objRemoteId, objName); - else if (objectType == Constants.OBJ_TREE) - return new GitModelTree(this, remoteCommit, objAncestorId, - objBaseId, objRemoteId, objName); - - return null; - } - - private void calculateKind(ObjectId baseId, ObjectId remoteId) { - if (baseId.equals(zeroId())) - kind = kind | ADDITION; - else if (remoteId.equals(zeroId())) - 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() { - return getLocation().toPortableString(); - } - - public boolean isCompareInputFor(Object object) { - // TODO Auto-generated method stub - return false; + return result.toArray(new GitModelObject[result.size()]); } } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObjectContainer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObjectContainer.java new file mode 100644 index 0000000000..99a0a56e4b --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObjectContainer.java @@ -0,0 +1,237 @@ +/******************************************************************************* + * Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.ui.internal.synchronize.model; + +import static org.eclipse.compare.structuremergeviewer.Differencer.ADDITION; +import static org.eclipse.compare.structuremergeviewer.Differencer.CHANGE; +import static org.eclipse.compare.structuremergeviewer.Differencer.DELETION; +import static org.eclipse.compare.structuremergeviewer.Differencer.LEFT; +import static org.eclipse.compare.structuremergeviewer.Differencer.RIGHT; +import static org.eclipse.jgit.lib.ObjectId.zeroId; + +import java.io.IOException; + +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.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +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; + +abstract class GitModelObjectContainer extends GitModelObject implements + ISynchronizationCompareInput { + + private int kind = -1; + + private String name; + + private GitModelObject[] children; + + protected final RevCommit baseCommit; + + protected final RevCommit remoteCommit; + + protected final RevCommit ancestorCommit; + + protected GitModelObjectContainer(GitModelObject parent, RevCommit commit, + int direction) throws IOException { + super(parent); + kind = direction; + remoteCommit = commit; + ancestorCommit = calculateAncestor(remoteCommit); + + RevCommit[] parents = remoteCommit.getParents(); + if (parents != null && parents.length > 0) + baseCommit = remoteCommit.getParent(0); + else { + baseCommit = null; + } + } + + public Image getImage() { + // currently itsn't used + return null; + } + + /** + * Returns common ancestor for this commit and all it parent's commits. + * + * @return common ancestor commit + */ + public RevCommit getAncestorCommit() { + return ancestorCommit; + } + + /** + * Returns instance of commit that is parent for one that is associated with + * this model object. + * + * @return base commit + */ + public RevCommit getBaseCommit() { + return baseCommit; + } + + /** + * Resurns instance of commit that is associated with this model object. + * + * @return rev commit + */ + public RevCommit getRemoteCommit() { + return remoteCommit; + } + + public int getKind() { + if (kind == -1 || kind == LEFT || kind == RIGHT) + calculateKind(); + + return kind; + } + + @Override + public GitModelObject[] getChildren() { + if (children == null) + children = getChildrenImpl(); + + return children; + + } + + @Override + public String getName() { + if (name == null) + name = remoteCommit.getShortMessage(); + + return name; + } + + @Override + public IProject[] getProjects() { + return getParent().getProjects(); + } + + @Override + public IPath getLocation() { + return getParent().getLocation(); + } + + 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 + } + + @Override + public boolean isContainer() { + return true; + } + + public SaveableComparison getSaveable() { + // currently not used + return null; + } + + public void prepareInput(CompareConfiguration configuration, + IProgressMonitor monitor) throws CoreException { + // there is no needed configuration for commit object + } + + public String getFullPath() { + return getLocation().toPortableString(); + } + + public boolean isCompareInputFor(Object object) { + // currently not used + return false; + } + + protected abstract GitModelObject[] getChildrenImpl(); + + protected GitModelObject getModelObject(TreeWalk tw, int ancestorNth, + int baseNth, int actualNth) throws IOException { + String objName = tw.getNameString(); + + ObjectId objBaseId; + if (baseNth > -1) + objBaseId = tw.getObjectId(baseNth); + else + objBaseId = ObjectId.zeroId(); + + ObjectId objRemoteId = tw.getObjectId(actualNth); + ObjectId objAncestorId = tw.getObjectId(ancestorNth); + int objectType = tw.getFileMode(actualNth).getObjectType(); + + if (objectType == Constants.OBJ_BLOB) + return new GitModelBlob(this, getRemoteCommit(), objAncestorId, + objBaseId, objRemoteId, objName); + else if (objectType == Constants.OBJ_TREE) + return new GitModelTree(this, getRemoteCommit(), objAncestorId, + objBaseId, objRemoteId, objName); + + return null; + } + + private void calculateKind() { + ObjectId base = baseCommit != null ? baseCommit.getId() : zeroId(); + if (base.equals(zeroId())) + kind = kind | ADDITION; + else if (remoteCommit.equals(zeroId())) + kind = kind | DELETION; + else + kind = kind | CHANGE; + } + + private RevCommit calculateAncestor(RevCommit actual) throws IOException { + RevWalk rw = new RevWalk(getRepository()); + rw.setRevFilter(RevFilter.MERGE_BASE); + + for (RevCommit parent : actual.getParents()) { + RevCommit parentCommit = rw.parseCommit(parent.getId()); + rw.markStart(parentCommit); + } + + rw.markStart(rw.parseCommit(actual.getId())); + + RevCommit result = rw.next(); + return result != null ? result : rw.parseCommit(ObjectId.zeroId()); + } + +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java index 1ecb840d06..53c67ccb3e 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelRepository.java @@ -116,7 +116,6 @@ public class GitModelRepository extends GitModelObject { return true; } - private void getChildrenImpl() { RevWalk rw = new RevWalk(repo); RevFlag localFlag = rw.newFlag("local"); //$NON-NLS-1$ @@ -125,7 +124,7 @@ public class GitModelRepository extends GitModelObject { allFlags.add(localFlag); allFlags.add(remoteFlag); rw.carry(allFlags); - List<GitModelCommit> result = new ArrayList<GitModelCommit>(); + List<GitModelObjectContainer> result = new ArrayList<GitModelObjectContainer>(); rw.setRetainBody(true); try { @@ -150,7 +149,8 @@ public class GitModelRepository extends GitModelObject { Activator.logError(e.getMessage(), e); } - childrens = result.toArray(new GitModelCommit[result.size()]); + + childrens = result.toArray(new GitModelObjectContainer[result.size()]); } } 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 186edff46e..f658ef04a0 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 @@ -16,10 +16,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.egit.core.Activator; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.treewalk.TreeWalk; @@ -37,8 +35,6 @@ public class GitModelTree extends GitModelCommit { private final ObjectId ancestorId; - private GitModelObject[] children; - private IPath location; /** @@ -56,7 +52,7 @@ public class GitModelTree extends GitModelCommit { * name resource associated with this tree * @throws IOException */ - public GitModelTree(GitModelCommit parent, RevCommit commit, + public GitModelTree(GitModelObjectContainer parent, RevCommit commit, ObjectId ancestorId, ObjectId baseId, ObjectId remoteId, String name) throws IOException { // only direction is important for us, therefore we mask rest of bits in kind @@ -68,23 +64,10 @@ public class GitModelTree extends GitModelCommit { } @Override - public GitModelObject[] getChildren() { - if (children == null) - getChildrenImpl(); - - return children; - } - - @Override public String getName() { return name; } - @Override - public IProject[] getProjects() { - return getParent().getProjects(); - } - /** * Return id of tree that should be used as a base variant in * three-way-compare. @@ -112,17 +95,7 @@ public class GitModelTree extends GitModelCommit { return location; } - @Override - protected ObjectId getBaseObjectId() { - return baseId; - } - - @Override - protected ObjectId getRemoteObjectId() { - return remoteId; - } - - private void getChildrenImpl() { + protected GitModelObject[] getChildrenImpl() { List<GitModelObject> result = new ArrayList<GitModelObject>(); try { @@ -138,7 +111,7 @@ public class GitModelTree extends GitModelCommit { ancestorNth = tw.addTree(ancestorId); while (tw.next()) { - GitModelObject obj = createChildren(tw, ancestorNth, baseNth, + GitModelObject obj = getModelObject(tw, ancestorNth, baseNth, remoteNth); if (obj != null) result.add(obj); @@ -147,29 +120,7 @@ public class GitModelTree extends GitModelCommit { Activator.logError(e.getMessage(), e); } - children = result.toArray(new GitModelObject[result.size()]); - } - - private GitModelObject createChildren(TreeWalk tw, int ancestorNth, - int baseNth, int remoteNth) throws IOException { - ObjectId objRemoteId = tw.getObjectId(remoteNth); - if (objRemoteId.equals(zeroId())) - return null; - - String objName = tw.getNameString(); - ObjectId objBaseId = baseNth != -1 ? tw.getObjectId(baseNth) : zeroId(); - ObjectId objAncestorId = ancestorNth != -1 ? tw - .getObjectId(ancestorNth) : zeroId(); - int objectType = tw.getFileMode(remoteNth).getObjectType(); - - if (objectType == Constants.OBJ_BLOB) - return new GitModelBlob(this, getRemoteCommit(), objAncestorId, - objBaseId, objRemoteId, objName); - else if (objectType == Constants.OBJ_TREE) - return new GitModelTree(this, getRemoteCommit(), objAncestorId, - objBaseId, objRemoteId, objName); - - return null; + return result.toArray(new GitModelObject[result.size()]); } } |