Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-05-10 09:03:46 -0400
committerMichael Keppler2019-05-14 12:37:16 -0400
commit7258517aa01f4dbf4ed45ed1f0e14e6d88f79ef0 (patch)
tree4cc1d360ea7e74855c07199eaab073d72d2ac37a
parent0efded6b96f5eae953f448e36cb7a874853e4c85 (diff)
downloadegit-7258517aa01f4dbf4ed45ed1f0e14e6d88f79ef0.tar.gz
egit-7258517aa01f4dbf4ed45ed1f0e14e6d88f79ef0.tar.xz
egit-7258517aa01f4dbf4ed45ed1f0e14e6d88f79ef0.zip
Minor re-organization of FileRevisionEditorInput
Move the temp files into the plugin's state location instead of using /tmp. Shorted file names by using only the first 7 characters of the commit SHA1. Also remove an unused constructor, and replace Object by IFileRevision in the others: this is only ever used with IFileRevision. As far as I see it is also never used with IFileState for the storage. Removing that code is for another commit, though. Bug: 547110 Change-Id: I88aa62a0200bd9c1b5414a93024d6649842473c5 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/revision/FileRevisionEditorInput.java46
1 files changed, 20 insertions, 26 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/revision/FileRevisionEditorInput.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/revision/FileRevisionEditorInput.java
index f054fecd8..8fe617d27 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/revision/FileRevisionEditorInput.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/revision/FileRevisionEditorInput.java
@@ -52,11 +52,11 @@ public class FileRevisionEditorInput extends PlatformObject implements
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
"yyyyMMdd_HHmmss"); //$NON-NLS-1$
- private final Object fileRevision;
+ private final IFileRevision fileRevision;
private final IStorage storage;
- private IPath tmpFile = null;
+ private IPath tmpFile;
/**
* @param revision
@@ -159,7 +159,7 @@ public class FileRevisionEditorInput extends PlatformObject implements
* @param storage
* the contents of the file revision
*/
- public FileRevisionEditorInput(Object revision, IStorage storage) {
+ public FileRevisionEditorInput(IFileRevision revision, IStorage storage) {
Assert.isNotNull(revision);
Assert.isNotNull(storage);
this.fileRevision = revision;
@@ -167,19 +167,11 @@ public class FileRevisionEditorInput extends PlatformObject implements
}
/**
- * @param state
- * the file state
- */
- public FileRevisionEditorInput(IFileState state) {
- this(state, state);
- }
-
- /**
* @param revision
* @param storage
* @param charset
*/
- public FileRevisionEditorInput(Object revision, IStorage storage,
+ public FileRevisionEditorInput(IFileRevision revision, IStorage storage,
String charset) {
this(revision, wrapStorage(storage, charset));
}
@@ -199,15 +191,22 @@ public class FileRevisionEditorInput extends PlatformObject implements
return null;
}
+ private String abbreviate(String id) {
+ if (id.length() > 7) {
+ // 7 characters as in Utils.getShortObjectId()
+ return id.substring(0, 7);
+ }
+ return id;
+ }
+
@Override
public String getName() {
IFileRevision rev = AdapterUtils.adapt(this, IFileRevision.class);
if (rev != null) {
String identifier;
if (rev instanceof CommitFileRevision) {
- // 7 characters as in Utils.getShortObjectId(), used in the
- // window title
- identifier = rev.getContentIdentifier().substring(0, 7);
+ // Used in the window title
+ identifier = abbreviate(rev.getContentIdentifier());
} else {
identifier = rev.getContentIdentifier();
}
@@ -293,21 +292,14 @@ public class FileRevisionEditorInput extends PlatformObject implements
* @return the revision
*/
public IFileRevision getFileRevision() {
- if (fileRevision instanceof IFileRevision) {
- return (IFileRevision) fileRevision;
- }
- return null;
+ return fileRevision;
}
/**
* @return the revision
*/
public URI getURI() {
- if (fileRevision instanceof IFileRevision) {
- IFileRevision fr = (IFileRevision) fileRevision;
- return fr.getURI();
- }
- return null;
+ return fileRevision.getURI();
}
@Override
@@ -326,7 +318,9 @@ public class FileRevisionEditorInput extends PlatformObject implements
if (tempName.length() > 200) {
tempName = storage.getName();
}
- path = Files.createTempDirectory("egit") //$NON-NLS-1$
+ path = Files
+ .createTempDirectory(Activator.getDefault()
+ .getStateLocation().toFile().toPath(), "egit") //$NON-NLS-1$
.resolve(tempName);
try (InputStream in = storage.getContents()) {
Files.copy(in, path);
@@ -356,7 +350,7 @@ public class FileRevisionEditorInput extends PlatformObject implements
private String getRevisionPrefix() {
IFileRevision rev = AdapterUtils.adapt(this, IFileRevision.class);
if (rev != null) {
- return rev.getContentIdentifier() + '_';
+ return abbreviate(rev.getContentIdentifier()) + '_';
}
IFileState state = AdapterUtils.adapt(this, IFileState.class);
if (state != null) {

Back to the top