From 03499e9cd2bbb17551ce4abdcbbec94a41ec119a Mon Sep 17 00:00:00 2001 From: Jens Baumgart Date: Thu, 15 Apr 2010 15:12:41 +0200 Subject: [PATCH] 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 / 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 --- .../src/org/eclipse/egit/core/internal/Utils.java | 45 ++++++++++++++++++++++ .../egit/core/internal/storage/BlobStorage.java | 2 +- .../core/internal/storage/CommitBlobStorage.java | 43 +++++++++++++++++++++ .../core/internal/storage/CommitFileRevision.java | 2 +- .../core/internal/storage/IndexBlobStorage.java | 38 ++++++++++++++++++ .../core/internal/storage/IndexFileRevision.java | 2 +- 6 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java create mode 100644 org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitBlobStorage.java create mode 100644 org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/IndexBlobStorage.java 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 00000000..e8df4292 --- /dev/null +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2010, Jens Baumgart + * + * 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 f6374534..cd30bc2d 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 00000000..bb3d11c3 --- /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 + * + * 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 getFullPath returns + * a path of format / 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 7f55f8ed..d219aabe 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 00000000..9d079714 --- /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 + * + * 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 getFullPath + * returns a path of format / 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 756c4d09..eb377a92 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() { -- 2.11.4.GIT