Skip to content

Commit

Permalink
Merge pull request #209 from sgtcoolguy/haywire
Browse files Browse the repository at this point in the history
TISTUD-6376 Appcelerator Studio 3.3.0.201405211748 (RC) is very slow to work
  • Loading branch information
pinnamur committed Jun 4, 2014
2 parents 1f2391b + b811a3c commit 7dbebe9
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean deleteFile(final IResourceTree tree, final IFile file, final int
tree.addToLocalHistory(file);

// Delete the file through the repo
IStatus status = repo.deleteFile(changed.getPath());
IStatus status = repo.deleteFile(changed.getRelativePath());
if (status.isOK())
{
tree.deletedFile(file);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Aptana Studio
* Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2005-2014 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
* Please see the license.html included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
Expand All @@ -10,12 +10,16 @@
import java.text.MessageFormat;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.IPath;

import com.aptana.core.logging.IdeLog;
import com.aptana.git.core.GitPlugin;

/**
* A value object representing a changed file in a git repo. There can be a large number of these and they can be
* constantly sorted/hashed/compared - so we try to use direct field references over accessors. We also pre-generate
* both a portable and OS-specific version of the relative path once.
* constantly sorted/hashed/compared. Ideally we don't want to modify the state of a ChangedFile, but to generate a new
* instance with the changes we want. However, we still do cheat in a handful of cases where we mark the staged/unstaged
* booleans.
*
* @author cwilliams
*/
Expand All @@ -33,41 +37,72 @@ public enum Status
*
* @param other
*/
public ChangedFile(ChangedFile other)
private ChangedFile(ChangedFile other)
{
this(other.portablePath, other.status);
this.hasStagedChanges = other.hasStagedChanges;
this.hasUnstagedChanges = other.hasUnstagedChanges;
this.commitBlobMode = other.commitBlobMode;
this.commitBlobSHA = other.commitBlobSHA;
this(other.repo, other.path, other.status, other.commitBlobMode, other.commitBlobSHA, other.hasStagedChanges,
other.hasUnstagedChanges);
}

public ChangedFile(String path, Status status)
// FIXME can we enforce that a ChangedFile cannot live outside it's repo? What sort of sanity checking can we do
// against the repo/location?
public ChangedFile(GitRepository repository, IPath path, Status status, String mode, String sha, boolean staged,
boolean unstaged)
{
this.portablePath = path;
this.repo = repository;
this.path = path;
this.status = status;
this.osPath = Path.fromPortableString(path).toOSString();
this.commitBlobMode = mode;
this.commitBlobSHA = sha;
this.hasStagedChanges = staged;
this.hasUnstagedChanges = unstaged;
}

private String osPath;
String portablePath;
Status status;
boolean hasStagedChanges;
boolean hasUnstagedChanges;
String commitBlobSHA;
String commitBlobMode;
private final GitRepository repo;
private final IPath path;
final Status status;
private boolean hasStagedChanges;
private boolean hasUnstagedChanges;
private final String commitBlobSHA;
private final String commitBlobMode;

// FIXME Use IPath
public String getPath()
/**
* Returns the path relative to the repo root.
*
* @return
*/
public IPath getRelativePath()
{
return osPath;
return path;
}

public Status getStatus()
{
return status;
}

/**
* Forces this to be marked as having staged changes, no unstaged changes.
*/
public void makeStaged()
{
hasUnstagedChanges = false;
hasStagedChanges = true;
}

/**
* Forces this to be marked as having unstaged changes, no staged changes.
*/
public void makeUnstaged()
{
this.hasUnstagedChanges = true;
this.hasStagedChanges = false;
}

public void setUnstaged(boolean unstaged)
{
this.hasUnstagedChanges = unstaged;
}

public boolean hasStagedChanges()
{
return hasStagedChanges;
Expand All @@ -94,17 +129,17 @@ protected String indexInfo()
"File is not new, but doesn't have an index entry!"); //$NON-NLS-1$
if (commitBlobSHA == null)
{
return MessageFormat.format("0 0000000000000000000000000000000000000000\t{0}\0", portablePath); //$NON-NLS-1$
return MessageFormat.format("0 0000000000000000000000000000000000000000\t{0}\0", path.toPortableString()); //$NON-NLS-1$
}

return MessageFormat.format("{0} {1}\t{2}\0", commitBlobMode, commitBlobSHA, portablePath); //$NON-NLS-1$
return MessageFormat.format("{0} {1}\t{2}\0", commitBlobMode, commitBlobSHA, path.toPortableString()); //$NON-NLS-1$
}

@Override
public String toString()
{
return MessageFormat.format(
"{0} {1} (Staged? {2}, Unstaged? {3})", status, osPath, hasStagedChanges, hasUnstagedChanges); //$NON-NLS-1$
return MessageFormat
.format("{0} {1} (Staged? {2}, Unstaged? {3})", status, path.toOSString(), hasStagedChanges, hasUnstagedChanges); //$NON-NLS-1$
}

public boolean hasUnmergedChanges()
Expand All @@ -114,7 +149,7 @@ public boolean hasUnmergedChanges()

public int compareTo(ChangedFile o)
{
return portablePath.compareTo(o.portablePath);
return path.toPortableString().compareTo(o.path.toPortableString());
}

@Override
Expand All @@ -124,7 +159,7 @@ public boolean equals(Object obj)
{
ChangedFile other = (ChangedFile) obj;
return (hasStagedChanges == other.hasStagedChanges) && (hasUnstagedChanges == other.hasUnstagedChanges)
&& (status == other.status) && (portablePath == other.portablePath);
&& (status == other.status) && (path.equals(other.path));
}
return false;
}
Expand All @@ -135,7 +170,39 @@ public int hashCode()
int hash = 31 + Boolean.valueOf(hasStagedChanges).hashCode();
hash = hash * 31 + Boolean.valueOf(hasUnstagedChanges).hashCode();
hash = hash * 31 + status.hashCode();
hash = hash * 31 + portablePath.hashCode();
hash = hash * 31 + path.hashCode();
return hash;
}

public ChangedFile clone()
{
return new ChangedFile(this);
}

public ChangedFile merge(ChangedFile other)
{
String mode = this.commitBlobMode;
if (mode == null)
{
mode = other.commitBlobMode;
}

String sha = this.commitBlobSHA;
if (sha == null)
{
sha = other.commitBlobSHA;
}
if (status != other.status)
{
IdeLog.logWarning(GitPlugin.getDefault(), "Mismatch statuses when merging. Who wins? " + status.name()
+ ", " + other.status.name());
}
return new ChangedFile(this.repo, this.path, status, mode, sha,
this.hasStagedChanges || other.hasStagedChanges, this.hasUnstagedChanges || other.hasUnstagedChanges);
}

public GitRepository getRepository()
{
return repo;
}
}
Loading

0 comments on commit 7dbebe9

Please sign in to comment.