Skip to content
Browse files

Relative path resolution.

  • Loading branch information...
1 parent ec76f0d commit 06a1f8a9fcb85db21d97b62d28c03f00e9c268e2 @blabno committed
View
14 src/pl/com/it_crowd/cra/model/AssistantHelper.java
@@ -2,8 +2,6 @@
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ContentRevision;
-import org.jetbrains.idea.svn.RootUrlInfo;
-import org.jetbrains.idea.svn.SvnVcs;
import java.io.File;
@@ -19,17 +17,7 @@ public static boolean affectsFile(Change change, File ioFile)
|| afterRevision != null && ioFileAbsolutePath.endsWith(afterRevision.getFile().getPath());
}
- public static String getRelativePath(File file, SvnVcs vcs)
- {
- final RootUrlInfo wcRootForFilePath = vcs.getSvnFileUrlMapping().getWcRootForFilePath(file);
- if (wcRootForFilePath == null) {
- throw new IllegalArgumentException("Cannot get working copy root for file: " + file.getAbsolutePath());
- }
- final int length = wcRootForFilePath.getIoFile().getAbsolutePath().length();
- return file.getAbsolutePath().substring(length);
- }
-
-// --------------------------- CONSTRUCTORS ---------------------------
+ // --------------------------- CONSTRUCTORS ---------------------------
private AssistantHelper()
{
View
100 src/pl/com/it_crowd/cra/model/CodeReviewAssistant.java
@@ -1,14 +1,21 @@
package pl.com.it_crowd.cra.model;
import com.intellij.openapi.components.ProjectComponent;
+import com.intellij.openapi.progress.ProgressIndicator;
+import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.changes.Change;
+import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.idea.svn.RootsToWorkingCopies;
import org.jetbrains.idea.svn.SvnVcs;
+import org.jetbrains.idea.svn.WorkingCopy;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
+import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.wc.ISVNDiffStatusHandler;
import org.tmatesoft.svn.core.wc.SVNDiffStatus;
@@ -32,6 +39,8 @@
public static final String REVISION_RANGE_PROPERTY = "revisionRange";
+ public static final String STATE_PROPERTY = "state";
+
private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private final List<File> changedFiles = new ArrayList<File>();
@@ -48,15 +57,25 @@
private final List<File> unmodifiableChangedFilesView;
+ private State state = State.CLEAR;
+
+ public static enum State {
+ CLEAR,
+ LOADING,
+ LOADED
+ }
+
// -------------------------- STATIC METHODS --------------------------
private static Change createChange(SvnVcs vcs, File file, int startRevision, int endRevision)
{
Change change;
- final String relativePath = AssistantHelper.getRelativePath(file, vcs).substring(1);
+ final SVNURL repositoryRootURL = vcs.getInfo(file).getRepositoryRootURL();
+ final SVNURL urlForFile = vcs.getSvnFileUrlMapping().getUrlForFile(file);
+ final String relativePath = urlForFile.getPath().substring(repositoryRootURL.getPath().length());
final SVNRepository repository;
try {
- repository = vcs.createRepository(vcs.getInfo(file).getRepositoryRootURL());
+ repository = vcs.createRepository(repositoryRootURL);
} catch (SVNException ex) {
throw new RuntimeException(ex);
}
@@ -135,6 +154,11 @@ public void addPropertyChangeListener(PropertyChangeListener listener)
return unmodifiableChangedFilesView;
}
+ public void removePropertyChangeListener(PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
public void selectFile(@Nullable Integer index)
{
File oldValue = this.currentFile;
@@ -142,24 +166,68 @@ public void selectFile(@Nullable Integer index)
changeSupport.firePropertyChange(CURRENT_FILE_PROPERTY, oldValue, this.currentFile);
}
- public void setRevisionRange(int startRevision, int endRevision) throws SVNException
+ public void setRevisionRange(final int startRevision, final int endRevision)
{
final RevisionRange oldRange = this.revisionRange;
this.revisionRange = new RevisionRange(startRevision, endRevision);
changeSupport.firePropertyChange(REVISION_RANGE_PROPERTY, oldRange, this.revisionRange);
- changedFiles.clear();
- changes.clear();
- changeSupport.firePropertyChange(CHANGED_FILES_PROPERTY, null, changedFiles);
+ clear();
+ final State oldState = state;
+ state = State.LOADING;
+ changeSupport.firePropertyChange(STATE_PROPERTY, oldState, state);
- final SvnVcs svnVcs = SvnVcs.getInstance(project);
- final SVNRevision svnRevision = SVNRevision.create(startRevision);
- svnVcs.createDiffClient()
- .doDiffStatus(new File(project.getBasePath()), svnRevision, SVNRevision.create(endRevision), svnRevision, SVNDepth.INFINITY, true,
- diffStatusHandler);
- changeSupport.firePropertyChange(CHANGED_FILES_PROPERTY, null, changedFiles);
selectFile(null);
+
+ ProgressManager.getInstance().run(new Task.Backgroundable(project, "Getting changed files") {
+ public void run(@NotNull ProgressIndicator progressIndicator)
+ {
+ final SvnVcs svnVcs = SvnVcs.getInstance(project);
+ final SVNRevision svnRevision = SVNRevision.create(startRevision);
+
+ final RootsToWorkingCopies rootsToWorkingCopies = svnVcs.getRootsToWorkingCopies();
+ if (rootsToWorkingCopies == null) {
+ throw new RuntimeException("Cannot get VCS roots to working copies");
+ }
+ final VirtualFile baseDir = project.getBaseDir();
+ final WorkingCopy wcRoot = rootsToWorkingCopies.getWcRoot(baseDir);
+ if (wcRoot == null) {
+ throw new RuntimeException("Cannot get working copy root for path " + baseDir);
+ }
+ final SVNURL wcRootUrl = wcRoot.getUrl();
+ try {
+ svnVcs.createDiffClient()
+ .doDiffStatus(wcRootUrl, svnRevision, SVNRevision.create(endRevision), svnRevision, SVNDepth.INFINITY, true, diffStatusHandler);
+ } catch (SVNException e) {
+ throw new RuntimeException("Cannot get list of changed files from " + wcRootUrl, e);
+ }
+ changeSupport.firePropertyChange(CHANGED_FILES_PROPERTY, null, changedFiles);
+ }
+
+ @Override
+ public void onSuccess()
+ {
+ State oldState = state;
+ state = State.LOADED;
+ changeSupport.firePropertyChange(STATE_PROPERTY, oldState, state);
+ }
+
+ @Override
+ public void onCancel()
+ {
+ clear();
+ State oldState = state;
+ state = State.CLEAR;
+ changeSupport.firePropertyChange(STATE_PROPERTY, oldState, state);
+ }
+ });
}
+ private void clear()
+ {
+ changedFiles.clear();
+ changes.clear();
+ changeSupport.firePropertyChange(CHANGED_FILES_PROPERTY, null, changedFiles);
+ }
// -------------------------- INNER CLASSES --------------------------
@@ -175,10 +243,12 @@ public void handleDiffStatus(SVNDiffStatus svnDiffStatus) throws SVNException
final int startRevision = getRevisionRange().getStartRevision();
final int endRevision = getRevisionRange().getEndRevision();
final SVNStatusType modificationType = svnDiffStatus.getModificationType();
- if (!SVNStatusType.UNCHANGED.equals(modificationType) && !SVNStatusType.STATUS_NONE.equals(modificationType)) {
- changedFiles.add(svnDiffStatus.getFile());
+ final File svnDiffStatusFile = new File(vcs.getSvnFileUrlMapping().getLocalPath(svnDiffStatus.getURL().toString()));
+ if (!SVNStatusType.UNCHANGED.equals(modificationType) && !SVNStatusType.STATUS_NONE.equals(modificationType) && !SVNStatusType.STATUS_DELETED
+ .equals(modificationType) && svnDiffStatusFile.exists()) {
+ changedFiles.add(svnDiffStatusFile);
if (SVNNodeKind.FILE.equals(svnDiffStatus.getKind())) {
- changes.add(createChange(vcs, svnDiffStatus.getFile(), startRevision, endRevision));
+ changes.add(createChange(vcs, svnDiffStatusFile, startRevision, endRevision));
}
}
}
View
2 src/pl/com/it_crowd/cra/ui/CodeReviewAssistantPanel.java
@@ -197,7 +197,7 @@ public ChangeDiffRequestPresentable convert(Change o)
final ChangeDiffRequest request = new ChangeDiffRequest(CodeReviewAssistantPanel.this.project, changeList, context.getActionsFactory(),
context.isShowFrame());
- DiffRequest simpleRequest = null;
+ DiffRequest simpleRequest;
try {
request.quickCheckHaveStuff();
simpleRequest = request.init(0);
View
20 src/pl/com/it_crowd/cra/ui/RevisionRangeDialog.java
@@ -4,7 +4,6 @@
import com.intellij.openapi.ui.Messages;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
-import org.tmatesoft.svn.core.SVNException;
import pl.com.it_crowd.cra.model.CodeReviewAssistant;
import javax.swing.JButton;
@@ -21,6 +20,8 @@
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
public class RevisionRangeDialog extends JDialog {
// ------------------------------ FIELDS ------------------------------
@@ -116,14 +117,17 @@ private void onOK()
Messages.showWarningDialog(e.getMessage(), "Invalid End Revision");
return;
}
- try {
- assistant.setRevisionRange(startRevision, endRevision);
- } catch (SVNException e) {
- Messages.showWarningDialog(e.getMessage(), "Invalid Revision Range");
- return;
- }
+ assistant.setRevisionRange(startRevision, endRevision);
+ assistant.addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ if (CodeReviewAssistant.STATE_PROPERTY.equals(evt.getPropertyName()) && !CodeReviewAssistant.State.LOADING.equals(evt.getNewValue())) {
+ CodeReviewAssistantPanel.show(project);
+ assistant.removePropertyChangeListener(this);
+ }
+ }
+ });
dispose();
- CodeReviewAssistantPanel.show(project);
}
/**

0 comments on commit 06a1f8a

Please sign in to comment.
Something went wrong with that request. Please try again.