From cf2099d77c405fc5f516527b528f0bd6a6d8fe86 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 19 Sep 2007 00:03:19 +0200 Subject: [PATCH] Improve cancel logic for history view refresh. Signed-off-by: Robin Rosenberg --- .../egit/core/internal/mapping/GitFileHistory.java | 5 + .../src/org/spearce/egit/ui/GitHistoryPage.java | 208 +++++++++++---------- 2 files changed, 116 insertions(+), 97 deletions(-) diff --git a/org.spearce.egit.core/src/org/spearce/egit/core/internal/mapping/GitFileHistory.java b/org.spearce.egit.core/src/org/spearce/egit/core/internal/mapping/GitFileHistory.java index ccf0c8b0..889ca0cd 100644 --- a/org.spearce.egit.core/src/org/spearce/egit/core/internal/mapping/GitFileHistory.java +++ b/org.spearce.egit.core/src/org/spearce/egit/core/internal/mapping/GitFileHistory.java @@ -24,6 +24,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.CancellationException; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; @@ -148,6 +149,10 @@ public class GitFileHistory extends FileHistory implements IAdaptable { @Override protected void record(ObjectId pred, ObjectId succ) { super.record(pred, succ); + if (monitor.isCanceled()) { + System.out.println("Cancelled"); + throw new CancellationException("history refresh cancelled"); + } } } diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java index 2c65cd20..6d45b5aa 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.CancellationException; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.structuremergeviewer.ICompareInput; @@ -33,7 +34,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; @@ -581,116 +581,130 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, } protected IStatus run(IProgressMonitor monitor) { - monitor = new NullProgressMonitor(); - monitor.beginTask("UpdateHistory", IProgressMonitor.UNKNOWN); - IProject project = ((IResource) getInput()).getProject(); - RepositoryProvider provider = RepositoryProvider - .getProvider(project); - RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project); - Map newappliedPatches = null; - try { - newappliedPatches = repositoryMapping.getRepository().getAppliedPatches(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Map newtags = new HashMap(); try { - for (String name : repositoryMapping.getRepository().getTags()) { - Tag t = repositoryMapping.getRepository().mapTag(name); - Tag[] samecommit = newtags.get(t.getObjId()); - if (samecommit==null) { - samecommit = new Tag[] { t }; - } else { - Tag[] n=new Tag[samecommit.length+1]; - for (int j=0; j newtags = new HashMap(); + try { + for (String name : repositoryMapping.getRepository().getTags()) { + Tag t = repositoryMapping.getRepository().mapTag(name); + Tag[] samecommit = newtags.get(t.getObjId()); + if (samecommit==null) { + samecommit = new Tag[] { t }; + } else { + Tag[] n=new Tag[samecommit.length+1]; + for (int j=0; j newBranches = new HashMap(); - try { - for (String branch : repositoryMapping.getRepository().getBranches()) { - ObjectId id = repositoryMapping.getRepository().resolve(branch); - String[] samecommit = newBranches.get(id); + try { + currentHead = repositoryMapping.getRepository().resolve("HEAD"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Map newBranches = new HashMap(); + try { + for (String branch : repositoryMapping.getRepository().getBranches()) { + ObjectId id = repositoryMapping.getRepository().resolve(branch); + String[] samecommit = newBranches.get(id); + if (samecommit == null) { + samecommit = new String[] { branch }; + } else { + String[] n=new String[samecommit.length + 1]; + for (int j=0; j ftags = newtags; - - table.getDisplay().asyncExec(new Runnable() { - - public void run() { - table.removeAll(); - table.setItemCount(fileRevisions.size()); - table.setData("X"); - table.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true)); - System.out.println("inputchanged, invoking refresh"); - appliedPatches = fnewappliedPatches; - tags = ftags; - long t0 = System.currentTimeMillis(); - viewer.refresh(); - long t1 = System.currentTimeMillis(); - System.out.println("refresh in "+(t1-t0)/1000.0+"s"); - done(Status.OK_STATUS); + GitFileHistoryProvider fileHistoryProvider = (GitFileHistoryProvider) provider + .getFileHistoryProvider(); + IResource startingPoint = (IResource) getInput(); + if (isShowAllFolderVersions()) + if (!(startingPoint instanceof IContainer)) + startingPoint = startingPoint.getParent(); + if (isShowAllProjectVersions()) + startingPoint = startingPoint.getProject(); + + GitFileHistory fileHistoryFor = fileHistoryProvider + .getHistoryFor(startingPoint, + -1, + monitor, + isShowAllRepoVersions()); + fileRevisions = fileHistoryFor.getFileRevisionsList(); + final Map fnewappliedPatches = newappliedPatches; + final Map ftags = newtags; + + table.getDisplay().asyncExec(new Runnable() { + + public void run() { + table.removeAll(); + table.setItemCount(fileRevisions.size()); + table.setData("X"); + table.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true)); + System.out.println("inputchanged, invoking refresh"); + appliedPatches = fnewappliedPatches; + tags = ftags; + long t0 = System.currentTimeMillis(); + viewer.refresh(); + long t1 = System.currentTimeMillis(); + System.out.println("refresh in "+(t1-t0)/1000.0+"s"); + done(Status.OK_STATUS); + System.out.println("History refresh at "+new Date()); + } + + }); + done(Status.OK_STATUS); + + } catch (CancellationException e) { + System.out.println("Job cancelled"); + done(Status.CANCEL_STATUS); + return Status.CANCEL_STATUS; + + } finally { + if (getState() == Job.RUNNING) { + System.out.println("Job aborted for unknow reason"); + done(Status.CANCEL_STATUS); } - - }); + } return Status.OK_STATUS; } - } HistoryRefreshJob historyRefreshJob = new HistoryRefreshJob("Git history refresh"); -- 2.11.4.GIT