diff options
author | Jens Baumgart | 2010-04-15 13:12:41 +0000 |
---|---|---|
committer | Jens Baumgart | 2010-04-15 13:12:41 +0000 |
commit | 03499e9cd2bbb17551ce4abdcbbec94a41ec119a (patch) | |
tree | bb6401122bb810765c40553a023b29fcc45999fa | |
parent | 45b206ac6a565f79d7bcda970d405099ab168fb0 (diff) | |
download | egit-03499e9cd2bbb17551ce4abdcbbec94a41ec119a.tar.gz egit-03499e9cd2bbb17551ce4abdcbbec94a41ec119a.tar.xz egit-03499e9cd2bbb17551ce4abdcbbec94a41ec119a.zip |
Fix incorrect editor updates with changes from diff-viewer
The issue occurs if BlobStorage.getFullPath returns a path
that is equal to the path of the file in the workspace. In this
case Eclipse seems to share the editor documents.
The fix provides new implementations for getFullPath
which provide a path of form
<repositoy name>/<path> <commit id>
When viewing a revision this path is shown as tool tip
of the editor title (similar to CVS).
Bug: 302145
Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
6 files changed, 129 insertions, 3 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java new file mode 100644 index 0000000000..e8df4292e4 --- /dev/null +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com> + * + * 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.core.internal; + +import java.io.File; + +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; + +/** + * Utility class + * + */ +public class Utils { + + /** + * @param repository + * @return display name of the repository + */ + public static String getRepositoryName(Repository repository) { + String repositoryName; + File gitDir = repository.getDirectory(); + if (gitDir != null) + repositoryName = repository.getDirectory().getParentFile() + .getName(); + else + repositoryName = ""; //$NON-NLS-1$ + return repositoryName; + } + + /** + * @param id + * @return a shortened ObjectId (first 6 digits) + */ + public static String getShortObjectId(ObjectId id) { + return id.getName().substring(0, 6); + } + +} diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/BlobStorage.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/BlobStorage.java index f6374534ea..cd30bc2d06 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/BlobStorage.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/BlobStorage.java @@ -29,7 +29,7 @@ import org.eclipse.osgi.util.NLS; /** Accesses a blob from Git. */ class BlobStorage implements IStorage { - private final Repository db; + protected final Repository db; private final String path; diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitBlobStorage.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitBlobStorage.java new file mode 100644 index 0000000000..bb3d11c3f0 --- /dev/null +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitBlobStorage.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com> + * + * 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.core.internal.storage; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.egit.core.internal.Utils; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; + +/** + * Blob Storage related to a RevCommit. Method <code>getFullPath</code> returns + * a path of format <repository name>/<file path> <commit id> This results in a + * useful tool tip on the editor title when viewing a revision and avoids the + * issue that editors get dirty because Eclipse seems to share the document of + * the workspace file if the remote file has the same full path. + */ +public class CommitBlobStorage extends BlobStorage { + + private final RevCommit commit; + + CommitBlobStorage(final Repository repository, final String fileName, + final ObjectId blob, RevCommit commit) { + super(repository, fileName, blob); + this.commit = commit; + } + + @Override + public IPath getFullPath() { + IPath repoPath = new Path(Utils.getRepositoryName(db)); + String pathString = super.getFullPath().toPortableString() + " " //$NON-NLS-1$ + + Utils.getShortObjectId(commit.getId()); + return repoPath.append(Path.fromPortableString(pathString)); + } + +} diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java index 7f55f8ed91..d219aabe08 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java @@ -71,7 +71,7 @@ class CommitFileRevision extends GitFileRevision { throws CoreException { if (blobId == null) blobId = locateBlobObjectId(); - return new BlobStorage(db, path, blobId); + return new CommitBlobStorage(db, path, blobId, commit); } public long getTimestamp() { diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexBlobStorage.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexBlobStorage.java new file mode 100644 index 0000000000..9d07971464 --- /dev/null +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexBlobStorage.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com> + * + * 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.core.internal.storage; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.egit.core.internal.Utils; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; + +/** + * Blob Storage related to a file in the index. Method <code>getFullPath</code> + * returns a path of format <repository name>/<file path> index + * + * @see CommitBlobStorage + * + */ +public class IndexBlobStorage extends BlobStorage { + + IndexBlobStorage(final Repository repository, final String fileName, + final ObjectId blob) { + super(repository, fileName, blob); + } + + @Override + public IPath getFullPath() { + IPath repoPath = new Path(Utils.getRepositoryName(db)); + String pathString = super.getFullPath().toPortableString() + " index"; //$NON-NLS-1$ + return repoPath.append(Path.fromPortableString(pathString)); + } + +} diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexFileRevision.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexFileRevision.java index 756c4d0997..eb377a920f 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexFileRevision.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexFileRevision.java @@ -42,7 +42,7 @@ class IndexFileRevision extends GitFileRevision implements IFileRevision { public IStorage getStorage(IProgressMonitor monitor) throws CoreException { if (blobId == null) blobId = locateBlobObjectId(); - return new BlobStorage(db, path, blobId); + return new IndexBlobStorage(db, path, blobId); } public boolean isPropertyMissing() { |