diff options
author | Matthias Sohn | 2011-01-13 22:05:23 +0000 |
---|---|---|
committer | Matthias Sohn | 2011-01-13 22:05:23 +0000 |
commit | 5847c540a9afea6a4fdb38a092e2bbc760484526 (patch) | |
tree | 74c61d7afb755f9b72a8b154dbc2a2faf4a3a577 /org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java | |
parent | 8d7705d2709e80ea50f9115c2abbca98e9d9344c (diff) | |
download | egit-5847c540a9afea6a4fdb38a092e2bbc760484526.tar.gz egit-5847c540a9afea6a4fdb38a092e2bbc760484526.tar.xz egit-5847c540a9afea6a4fdb38a092e2bbc760484526.zip |
Fix chaotic order of fields and methods in GitHistoryPage
Change-Id: I44e61a004380030b0d695fe4f5739b0e6d621ba3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java')
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java | 982 |
1 files changed, 491 insertions, 491 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java index efc5ea61d6..46c1038424 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java @@ -407,69 +407,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { private GitHistoryPageActions actions; - private void initActions() { - try { - showAllFilter = ShowFilter.valueOf(Activator.getDefault() - .getPreferenceStore().getString(PREF_SHOWALLFILTER)); - } catch (IllegalArgumentException e) { - showAllFilter = ShowFilter.SHOWALLRESOURCE; - } - - actions = new GitHistoryPageActions(this); - setupToolBar(); - setupViewMenu(); - - graph.getControl().addMenuDetectListener(new MenuDetectListener() { - public void menuDetected(MenuDetectEvent e) { - popupMgr.add(actions.showFilesAction); - popupMgr.add(actions.showCommentAction); - } - }); - } - - private void setupToolBar() { - IToolBarManager mgr = getSite().getActionBars().getToolBarManager(); - mgr.add(actions.findAction); - mgr.add(new Separator()); - mgr.add(actions.showAllRepoVersionsAction); - mgr.add(actions.showAllProjectVersionsAction); - mgr.add(actions.showAllFolderVersionsAction); - mgr.add(actions.showAllResourceVersionsAction); - mgr.add(new Separator()); - mgr.add(actions.compareModeAction); - mgr.add(actions.showAllBranchesAction); - } - - private void setupViewMenu() { - IMenuManager viewMenuMgr = getSite().getActionBars().getMenuManager(); - viewMenuMgr.add(actions.refreshAction); - - viewMenuMgr.add(new Separator()); - IMenuManager showSubMenuMgr = new MenuManager( - UIText.GitHistoryPage_ShowSubMenuLabel); - viewMenuMgr.add(showSubMenuMgr); - showSubMenuMgr.add(actions.showAllBranchesAction); - showSubMenuMgr.add(actions.findAction); - showSubMenuMgr.add(actions.showFilesAction); - showSubMenuMgr.add(actions.showCommentAction); - - IMenuManager filterSubMenuMgr = new MenuManager( - UIText.GitHistoryPage_FilterSubMenuLabel); - viewMenuMgr.add(filterSubMenuMgr); - filterSubMenuMgr.add(actions.showAllRepoVersionsAction); - filterSubMenuMgr.add(actions.showAllProjectVersionsAction); - filterSubMenuMgr.add(actions.showAllFolderVersionsAction); - filterSubMenuMgr.add(actions.showAllResourceVersionsAction); - - viewMenuMgr.add(new Separator()); - viewMenuMgr.add(actions.compareModeAction); - viewMenuMgr.add(actions.reuseCompareEditorAction); - - viewMenuMgr.add(new Separator()); - viewMenuMgr.add(actions.wrapCommentAction); - viewMenuMgr.add(actions.fillCommentAction); - } - /** An error text to be shown instead of the control */ private StyledText errorText; @@ -484,46 +421,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { private boolean trace = GitTraceLocation.HISTORYVIEW.isActive(); - /** - * Determine if the input can be shown in this viewer. - * - * @param object - * an object that is hopefully of type ResourceList or IResource, - * but may be anything (including null). - * @return true if the input is a ResourceList or an IResource of type FILE, - * FOLDER or PROJECT and we can show it; false otherwise. - */ - public static boolean canShowHistoryFor(final Object object) { - if (object instanceof HistoryPageInput) { - return true; - } - - if (object instanceof IResource) { - return typeOk((IResource) object); - } - - if (object instanceof RepositoryTreeNode) - return true; - - if (object instanceof IAdaptable) { - IResource resource = (IResource) ((IAdaptable) object) - .getAdapter(IResource.class); - return resource == null ? false : typeOk(resource); - } - - return false; - } - - private static boolean typeOk(final IResource object) { - switch (object.getType()) { - case IResource.FILE: - case IResource.FOLDER: - case IResource.PROJECT: - return true; - } - return false; - } - /** Overall composite hosting all of our controls. */ private Composite topControl; @@ -576,160 +473,56 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { */ private List<String> pathFilters; + private Runnable refschangedRunnable; + /** - * The default constructor + * Determine if the input can be shown in this viewer. + * + * @param object + * an object that is hopefully of type ResourceList or IResource, + * but may be anything (including null). + * @return true if the input is a ResourceList or an IResource of type FILE, + * FOLDER or PROJECT and we can show it; false otherwise. */ - public GitHistoryPage() { - trace = GitTraceLocation.HISTORYVIEW.isActive(); - if (trace) - GitTraceLocation.getTrace().traceEntry( - GitTraceLocation.HISTORYVIEW.getLocation()); - } - - void initAndStartRevWalk(boolean forceNewWalk) throws IllegalStateException { - try { - if (trace) - GitTraceLocation.getTrace().traceEntry( - GitTraceLocation.HISTORYVIEW.getLocation()); - - cancelRefreshJob(); - Repository db = input.getRepository(); - AnyObjectId headId = resolveHead(db); - - List<String> paths = buildFilterPaths(input.getItems(), input - .getFileList(), db); - - if (forceNewWalk || pathChange(pathFilters, paths) - || currentWalk == null || !headId.equals(currentHeadId)) { - // TODO Do not dispose SWTWalk just because HEAD changed - // In theory we should be able to update the graph and - // not dispose of the SWTWalk, even if HEAD was reset to - // HEAD^1 and the old HEAD commit should not be visible. - // - createNewWalk(db, headId); - } else { - currentWalk.reset(); - } - setWalkStartPoints(db, headId); - - final TreeWalk fileWalker = setupFileViewer(db, paths); - setupCommentViewer(db, fileWalker); - - scheduleNewGenerateHistoryJob(); - } finally { - if (trace) - GitTraceLocation.getTrace().traceExit( - GitTraceLocation.HISTORYVIEW.getLocation()); - + public static boolean canShowHistoryFor(final Object object) { + if (object instanceof HistoryPageInput) { + return true; } - } - private AnyObjectId resolveHead(Repository db) { - AnyObjectId headId; - try { - headId = db.resolve(Constants.HEAD); - } catch (IOException e) { - throw new IllegalStateException(NLS.bind( - UIText.GitHistoryPage_errorParsingHead, Activator - .getDefault().getRepositoryUtil() - .getRepositoryName(db))); + if (object instanceof IResource) { + return typeOk((IResource) object); } - if (headId == null) - throw new IllegalStateException(NLS.bind( - UIText.GitHistoryPage_errorParsingHead, Activator - .getDefault().getRepositoryUtil() - .getRepositoryName(db))); - return headId; - } - private void createNewWalk(Repository db, AnyObjectId headId) { - currentHeadId = headId; - if (currentWalk != null) - currentWalk.release(); - currentWalk = new SWTWalk(db); - currentWalk.sort(RevSort.COMMIT_TIME_DESC, true); - currentWalk.sort(RevSort.BOUNDARY, true); - highlightFlag = currentWalk.newFlag("highlight"); //$NON-NLS-1$ - } + if (object instanceof RepositoryTreeNode) + return true; - private void setWalkStartPoints(Repository db, AnyObjectId headId) { - try { - if (store - .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_ALL_BRANCHES)) { - markStartAllRefs(Constants.R_HEADS); - markStartAllRefs(Constants.R_REMOTES); - } else - currentWalk.markStart(currentWalk.parseCommit(headId)); - } catch (IOException e) { - throw new IllegalStateException(NLS.bind( - UIText.GitHistoryPage_errorReadingHeadCommit, headId, - db.getDirectory().getAbsolutePath()), e); + if (object instanceof IAdaptable) { + IResource resource = (IResource) ((IAdaptable) object) + .getAdapter(IResource.class); + return resource == null ? false : typeOk(resource); } - } - private void setupCommentViewer(Repository db, final TreeWalk fileWalker) { - commentViewer.setTreeWalk(fileWalker); - commentViewer.setDb(db); - commentViewer.refresh(); - } - - private TreeWalk setupFileViewer(Repository db, List<String> paths) { - final TreeWalk fileWalker = createFileWalker(db, paths); - fileViewer.setTreeWalk(db, fileWalker); - fileViewer.refresh(); - fileViewer.addSelectionChangedListener(commentViewer); - return fileWalker; + return false; } - private TreeWalk createFileWalker(Repository db, List<String> paths) { - final TreeWalk fileWalker = new TreeWalk(db); - fileWalker.setRecursive(true); - if (paths.size() > 0) { - pathFilters = paths; - currentWalk.setTreeFilter(AndTreeFilter.create(PathFilterGroup - .createFromStrings(paths), TreeFilter.ANY_DIFF)); - fileWalker.setFilter(currentWalk.getTreeFilter().clone()); - - } else { - pathFilters = null; - currentWalk.setTreeFilter(TreeFilter.ALL); - fileWalker.setFilter(TreeFilter.ANY_DIFF); + private static boolean typeOk(final IResource object) { + switch (object.getType()) { + case IResource.FILE: + case IResource.FOLDER: + case IResource.PROJECT: + return true; } - return fileWalker; - } - - private void scheduleNewGenerateHistoryJob() { - final SWTCommitList list = new SWTCommitList(graph.getControl().getDisplay()); - list.source(currentWalk); - final GenerateHistoryJob rj = new GenerateHistoryJob(this, list); - rj.addJobChangeListener(new JobChangeAdapter() { - @Override - public void done(final IJobChangeEvent event) { - final Control graphctl = graph.getControl(); - if (job != rj || graphctl.isDisposed()) - return; - graphctl.getDisplay().asyncExec(new Runnable() { - public void run() { - if (job == rj) - job = null; - } - }); - } - }); - job = rj; - if (trace) - GitTraceLocation.getTrace().trace( - GitTraceLocation.HISTORYVIEW.getLocation(), - "Scheduling GenerateHistoryJob"); //$NON-NLS-1$ - schedule(rj); + return false; } /** - * @param compareMode - * switch compare mode button of the view on / off + * The default constructor */ - public void setCompareMode(boolean compareMode) { - store.setValue(UIPreferences.RESOURCEHISTORY_COMPARE_MODE, compareMode); + public GitHistoryPage() { + trace = GitTraceLocation.HISTORYVIEW.isActive(); + if (trace) + GitTraceLocation.getTrace().traceEntry( + GitTraceLocation.HISTORYVIEW.getLocation()); } @Override @@ -770,44 +563,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { GitTraceLocation.HISTORYVIEW.getLocation()); } - /** - * @return the selection provider - */ - public ISelectionProvider getSelectionProvider() { - return graph.getTableView(); - } - - private Runnable refschangedRunnable; - - public void onRefsChanged(final RefsChangedEvent e) { - if (input == null || e.getRepository() != input.getRepository()) - return; - - if (getControl().isDisposed()) - return; - - synchronized (this) { - if (refschangedRunnable == null) { - refschangedRunnable = new Runnable() { - public void run() { - if (!getControl().isDisposed()) { - if (GitTraceLocation.HISTORYVIEW.isActive()) - GitTraceLocation - .getTrace() - .trace( - GitTraceLocation.HISTORYVIEW - .getLocation(), - "Executing async repository changed event"); //$NON-NLS-1$ - refschangedRunnable = null; - initAndStartRevWalk(true); - } - } - }; - getControl().getDisplay().asyncExec(refschangedRunnable); - } - } - } - private void layoutSashForm(final SashForm sf, final String key) { sf.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { @@ -912,6 +667,69 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { }); } + private void initActions() { + try { + showAllFilter = ShowFilter.valueOf(Activator.getDefault() + .getPreferenceStore().getString(PREF_SHOWALLFILTER)); + } catch (IllegalArgumentException e) { + showAllFilter = ShowFilter.SHOWALLRESOURCE; + } + + actions = new GitHistoryPageActions(this); + setupToolBar(); + setupViewMenu(); + + graph.getControl().addMenuDetectListener(new MenuDetectListener() { + public void menuDetected(MenuDetectEvent e) { + popupMgr.add(actions.showFilesAction); + popupMgr.add(actions.showCommentAction); + } + }); + } + + private void setupToolBar() { + IToolBarManager mgr = getSite().getActionBars().getToolBarManager(); + mgr.add(actions.findAction); + mgr.add(new Separator()); + mgr.add(actions.showAllRepoVersionsAction); + mgr.add(actions.showAllProjectVersionsAction); + mgr.add(actions.showAllFolderVersionsAction); + mgr.add(actions.showAllResourceVersionsAction); + mgr.add(new Separator()); + mgr.add(actions.compareModeAction); + mgr.add(actions.showAllBranchesAction); + } + + private void setupViewMenu() { + IMenuManager viewMenuMgr = getSite().getActionBars().getMenuManager(); + viewMenuMgr.add(actions.refreshAction); + + viewMenuMgr.add(new Separator()); + IMenuManager showSubMenuMgr = new MenuManager( + UIText.GitHistoryPage_ShowSubMenuLabel); + viewMenuMgr.add(showSubMenuMgr); + showSubMenuMgr.add(actions.showAllBranchesAction); + showSubMenuMgr.add(actions.findAction); + showSubMenuMgr.add(actions.showFilesAction); + showSubMenuMgr.add(actions.showCommentAction); + + IMenuManager filterSubMenuMgr = new MenuManager( + UIText.GitHistoryPage_FilterSubMenuLabel); + viewMenuMgr.add(filterSubMenuMgr); + filterSubMenuMgr.add(actions.showAllRepoVersionsAction); + filterSubMenuMgr.add(actions.showAllProjectVersionsAction); + filterSubMenuMgr.add(actions.showAllFolderVersionsAction); + filterSubMenuMgr.add(actions.showAllResourceVersionsAction); + + viewMenuMgr.add(new Separator()); + viewMenuMgr.add(actions.compareModeAction); + viewMenuMgr.add(actions.reuseCompareEditorAction); + + viewMenuMgr.add(new Separator()); + viewMenuMgr.add(actions.wrapCommentAction); + viewMenuMgr.add(actions.fillCommentAction); + } + public void dispose() { trace = GitTraceLocation.HISTORYVIEW.isActive(); if (trace) @@ -942,11 +760,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { super.dispose(); } - public void refresh() { - this.input = null; - inputSet(); - } - @Override public void setFocus() { graph.getControl().setFocus(); @@ -957,6 +770,55 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { return topControl; } + public void refresh() { + this.input = null; + inputSet(); + } + + /** + * @param compareMode + * switch compare mode button of the view on / off + */ + public void setCompareMode(boolean compareMode) { + store.setValue(UIPreferences.RESOURCEHISTORY_COMPARE_MODE, compareMode); + } + + /** + * @return the selection provider + */ + public ISelectionProvider getSelectionProvider() { + return graph.getTableView(); + } + + public void onRefsChanged(final RefsChangedEvent e) { + if (input == null || e.getRepository() != input.getRepository()) + return; + + if (getControl().isDisposed()) + return; + + synchronized (this) { + if (refschangedRunnable == null) { + refschangedRunnable = new Runnable() { + public void run() { + if (!getControl().isDisposed()) { + if (GitTraceLocation.HISTORYVIEW.isActive()) + GitTraceLocation + .getTrace() + .trace( + GitTraceLocation.HISTORYVIEW + .getLocation(), + "Executing async repository changed event"); //$NON-NLS-1$ + refschangedRunnable = null; + initAndStartRevWalk(true); + } + } + }; + getControl().getDisplay().asyncExec(refschangedRunnable); + } + } + } + @Override public boolean setInput(Object object) { try { @@ -1070,213 +932,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { } } - private ArrayList<String> buildFilterPaths(final IResource[] inResources, - final File[] inFiles, final Repository db) - throws IllegalStateException { - final ArrayList<String> paths; - if (inResources != null) { - paths = new ArrayList<String>(inResources.length); - for (final IResource r : inResources) { - final RepositoryMapping map = RepositoryMapping.getMapping(r); - if (map == null) - continue; - if (db != map.getRepository()) { - throw new IllegalStateException( - UIText.AbstractHistoryCommanndHandler_NoUniqueRepository); - } - - if (showAllFilter == ShowFilter.SHOWALLFOLDER) { - final String path; - // if the resource's parent is the workspace root, we will - // get nonsense from map.getRepoRelativePath(), so we - // check here and use the project instead - if (r.getParent() instanceof IWorkspaceRoot) - path = map.getRepoRelativePath(r.getProject()); - else - path = map.getRepoRelativePath(r.getParent()); - if (path != null && path.length() > 0) - paths.add(path); - } else if (showAllFilter == ShowFilter.SHOWALLPROJECT) { - final String path = map.getRepoRelativePath(r.getProject()); - if (path != null && path.length() > 0) - paths.add(path); - } else if (showAllFilter == ShowFilter.SHOWALLREPO) { - // nothing - } else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */{ - final String path = map.getRepoRelativePath(r); - if (path != null && path.length() > 0) - paths.add(path); - } - } - } else if (inFiles != null) { - IPath workdirPath = new Path(db.getWorkTree().getPath()); - IPath gitDirPath = new Path(db.getDirectory().getPath()); - int segmentCount = workdirPath.segmentCount(); - paths = new ArrayList<String>(inFiles.length); - for (File file : inFiles) { - IPath filePath; - if (showAllFilter == ShowFilter.SHOWALLFOLDER) { - filePath = new Path(file.getParentFile().getPath()); - } else if (showAllFilter == ShowFilter.SHOWALLPROJECT - || showAllFilter == ShowFilter.SHOWALLREPO) { - // we don't know of projects here -> treat as SHOWALLREPO - continue; - } else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */{ - filePath = new Path(file.getPath()); - } - - if (gitDirPath.isPrefixOf(filePath)) { - throw new IllegalStateException( - NLS - .bind( - UIText.GitHistoryPage_FileOrFolderPartOfGitDirMessage, - filePath.toOSString())); - } - - IPath pathToAdd = filePath.removeFirstSegments(segmentCount) - .setDevice(null); - if (!pathToAdd.isEmpty()) { - paths.add(pathToAdd.toString()); - } - } - } else { - paths = new ArrayList<String>(0); - } - return paths; - } - - /** - * @param message - * the message to display instead of the control - */ - public void setErrorMessage(final String message) { - if (trace) - GitTraceLocation.getTrace().traceEntry( - GitTraceLocation.HISTORYVIEW.getLocation(), message); - getHistoryPageSite().getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - StackLayout layout = (StackLayout) topControl.getLayout(); - if (message != null) { - errorText.setText(message); - layout.topControl = errorText; - } else { - errorText.setText(""); //$NON-NLS-1$ - layout.topControl = historyControl; - } - topControl.layout(); - } - }); - if (trace) - GitTraceLocation.getTrace().traceExit( - GitTraceLocation.HISTORYVIEW.getLocation()); - } - - /** - * {@link RevWalk#markStart(RevCommit)} all refs with given prefix to mark - * start of graph traversal using currentWalker - * - * @param prefix - * prefix of refs to be marked - * @throws IOException - * @throws MissingObjectException - * @throws IncorrectObjectTypeException - */ - private void markStartAllRefs(String prefix) throws IOException, - MissingObjectException, IncorrectObjectTypeException { - for (Entry<String, Ref> refEntry : input.getRepository() - .getRefDatabase().getRefs(prefix).entrySet()) { - Ref ref = refEntry.getValue(); - if (ref.isSymbolic()) - continue; - currentWalk.markStart(currentWalk.parseCommit(ref.getObjectId())); - } - } - - private void cancelRefreshJob() { - if (job != null && job.getState() != Job.NONE) { - job.cancel(); - try { - job.join(); - } catch (InterruptedException e) { - cancelRefreshJob(); - return; - } - job = null; - } - } - - private boolean pathChange(final List<String> o, final List<String> n) { - if (o == null) - return !n.isEmpty(); - return !o.equals(n); - } - - private void schedule(final Job j) { - final IWorkbenchPartSite site = getWorkbenchSite(); - if (site != null) { - final IWorkbenchSiteProgressService p; - p = (IWorkbenchSiteProgressService) site - .getAdapter(IWorkbenchSiteProgressService.class); - if (p != null) { - p.schedule(j, 0, true /* use half-busy cursor */); - return; - } - } - j.schedule(); - } - - void showCommitList(final Job j, final SWTCommitList list, - final SWTCommit[] asArray) { - if (trace) - GitTraceLocation.getTrace().traceEntry( - GitTraceLocation.HISTORYVIEW.getLocation(), - new Object[] { list, asArray }); - if (job != j || graph.getControl().isDisposed()) - return; - - graph.getControl().getDisplay().asyncExec(new Runnable() { - public void run() { - if (!graph.getControl().isDisposed() && job == j) { - graph.setInput(highlightFlag, list, asArray, input); - if (trace) - GitTraceLocation.getTrace().trace( - GitTraceLocation.HISTORYVIEW.getLocation(), - "Setting input to table"); //$NON-NLS-1$ - findToolbar.setInput(highlightFlag, graph.getTableView() - .getTable(), asArray); - setErrorMessage(null); - } - } - }); - if (trace) - GitTraceLocation.getTrace().traceExit( - GitTraceLocation.HISTORYVIEW.getLocation()); - } - - private IWorkbenchPartSite getWorkbenchSite() { - final IWorkbenchPart part = getHistoryPageSite().getPart(); - return part != null ? part.getSite() : null; - } - - public boolean isValidInput(final Object object) { - return canShowHistoryFor(object); - } - - public Object getAdapter(final Class adapter) { - return null; - } - - public String getName() { - return this.name; - } - - /** - * @return the internal input object, or <code>null</code> - */ - public HistoryPageInput getInputInternal() { - return this.input; - } - private static String calculateName(HistoryPageInput in) { // we always visualize the current input in the form // <type>: <path> [<respository name>] @@ -1376,6 +1031,40 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { .toString(); } + /** + * @param message + * the message to display instead of the control + */ + public void setErrorMessage(final String message) { + if (trace) + GitTraceLocation.getTrace().traceEntry( + GitTraceLocation.HISTORYVIEW.getLocation(), message); + getHistoryPageSite().getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + StackLayout layout = (StackLayout) topControl.getLayout(); + if (message != null) { + errorText.setText(message); + layout.topControl = errorText; + } else { + errorText.setText(""); //$NON-NLS-1$ + layout.topControl = historyControl; + } + topControl.layout(); + } + }); + if (trace) + GitTraceLocation.getTrace().traceExit( + GitTraceLocation.HISTORYVIEW.getLocation()); + } + + public boolean isValidInput(final Object object) { + return canShowHistoryFor(object); + } + + public Object getAdapter(final Class adapter) { + return null; + } + public String getDescription() { // this doesn't seem to be rendered anywhere, but still... String filterHint = null; @@ -1395,4 +1084,315 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener { } return NLS.bind(DESCRIPTION_PATTERN, getName(), filterHint); } + + public String getName() { + return this.name; + } + + /** + * @return the internal input object, or <code>null</code> + */ + public HistoryPageInput getInputInternal() { + return this.input; + } + + void showCommitList(final Job j, final SWTCommitList list, + final SWTCommit[] asArray) { + if (trace) + GitTraceLocation.getTrace().traceEntry( + GitTraceLocation.HISTORYVIEW.getLocation(), + new Object[] { list, asArray }); + if (job != j || graph.getControl().isDisposed()) + return; + + graph.getControl().getDisplay().asyncExec(new Runnable() { + public void run() { + if (!graph.getControl().isDisposed() && job == j) { + graph.setInput(highlightFlag, list, asArray, input); + if (trace) + GitTraceLocation.getTrace().trace( + GitTraceLocation.HISTORYVIEW.getLocation(), + "Setting input to table"); //$NON-NLS-1$ + findToolbar.setInput(highlightFlag, graph.getTableView() + .getTable(), asArray); + setErrorMessage(null); + } + } + }); + if (trace) + GitTraceLocation.getTrace().traceExit( + GitTraceLocation.HISTORYVIEW.getLocation()); + } + + void initAndStartRevWalk(boolean forceNewWalk) throws IllegalStateException { + try { + if (trace) + GitTraceLocation.getTrace().traceEntry( + GitTraceLocation.HISTORYVIEW.getLocation()); + + cancelRefreshJob(); + Repository db = input.getRepository(); + AnyObjectId headId = resolveHead(db); + + List<String> paths = buildFilterPaths(input.getItems(), input + .getFileList(), db); + + if (forceNewWalk || pathChange(pathFilters, paths) + || currentWalk == null || !headId.equals(currentHeadId)) { + // TODO Do not dispose SWTWalk just because HEAD changed + // In theory we should be able to update the graph and + // not dispose of the SWTWalk, even if HEAD was reset to + // HEAD^1 and the old HEAD commit should not be visible. + // + createNewWalk(db, headId); + } else { + currentWalk.reset(); + } + setWalkStartPoints(db, headId); + + final TreeWalk fileWalker = setupFileViewer(db, paths); + setupCommentViewer(db, fileWalker); + + scheduleNewGenerateHistoryJob(); + } finally { + if (trace) + GitTraceLocation.getTrace().traceExit( + GitTraceLocation.HISTORYVIEW.getLocation()); + + } + } + + private AnyObjectId resolveHead(Repository db) { + AnyObjectId headId; + try { + headId = db.resolve(Constants.HEAD); + } catch (IOException e) { + throw new IllegalStateException(NLS.bind( + UIText.GitHistoryPage_errorParsingHead, Activator + .getDefault().getRepositoryUtil() + .getRepositoryName(db))); + } + if (headId == null) + throw new IllegalStateException(NLS.bind( + UIText.GitHistoryPage_errorParsingHead, Activator + .getDefault().getRepositoryUtil() + .getRepositoryName(db))); + return headId; + } + + private ArrayList<String> buildFilterPaths(final IResource[] inResources, + final File[] inFiles, final Repository db) + throws IllegalStateException { + final ArrayList<String> paths; + if (inResources != null) { + paths = new ArrayList<String>(inResources.length); + for (final IResource r : inResources) { + final RepositoryMapping map = RepositoryMapping.getMapping(r); + if (map == null) + continue; + if (db != map.getRepository()) { + throw new IllegalStateException( + UIText.AbstractHistoryCommanndHandler_NoUniqueRepository); + } + + if (showAllFilter == ShowFilter.SHOWALLFOLDER) { + final String path; + // if the resource's parent is the workspace root, we will + // get nonsense from map.getRepoRelativePath(), so we + // check here and use the project instead + if (r.getParent() instanceof IWorkspaceRoot) + path = map.getRepoRelativePath(r.getProject()); + else + path = map.getRepoRelativePath(r.getParent()); + if (path != null && path.length() > 0) + paths.add(path); + } else if (showAllFilter == ShowFilter.SHOWALLPROJECT) { + final String path = map.getRepoRelativePath(r.getProject()); + if (path != null && path.length() > 0) + paths.add(path); + } else if (showAllFilter == ShowFilter.SHOWALLREPO) { + // nothing + } else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */{ + final String path = map.getRepoRelativePath(r); + if (path != null && path.length() > 0) + paths.add(path); + } + } + } else if (inFiles != null) { + IPath workdirPath = new Path(db.getWorkTree().getPath()); + IPath gitDirPath = new Path(db.getDirectory().getPath()); + int segmentCount = workdirPath.segmentCount(); + paths = new ArrayList<String>(inFiles.length); + for (File file : inFiles) { + IPath filePath; + if (showAllFilter == ShowFilter.SHOWALLFOLDER) { + filePath = new Path(file.getParentFile().getPath()); + } else if (showAllFilter == ShowFilter.SHOWALLPROJECT + || showAllFilter == ShowFilter.SHOWALLREPO) { + // we don't know of projects here -> treat as SHOWALLREPO + continue; + } else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */{ + filePath = new Path(file.getPath()); + } + + if (gitDirPath.isPrefixOf(filePath)) { + throw new IllegalStateException( + NLS + .bind( + UIText.GitHistoryPage_FileOrFolderPartOfGitDirMessage, + filePath.toOSString())); + } + + IPath pathToAdd = filePath.removeFirstSegments(segmentCount) + .setDevice(null); + if (!pathToAdd.isEmpty()) { + paths.add(pathToAdd.toString()); + } + } + } else { + paths = new ArrayList<String>(0); + } + return paths; + } + + private boolean pathChange(final List<String> o, final List<String> n) { + if (o == null) + return !n.isEmpty(); + return !o.equals(n); + } + + private void createNewWalk(Repository db, AnyObjectId headId) { + currentHeadId = headId; + if (currentWalk != null) + currentWalk.release(); + currentWalk = new SWTWalk(db); + currentWalk.sort(RevSort.COMMIT_TIME_DESC, true); + currentWalk.sort(RevSort.BOUNDARY, true); + highlightFlag = currentWalk.newFlag("highlight"); //$NON-NLS-1$ + } + + private void setWalkStartPoints(Repository db, AnyObjectId headId) { + try { + if (store + .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_ALL_BRANCHES)) { + markStartAllRefs(Constants.R_HEADS); + markStartAllRefs(Constants.R_REMOTES); + } else + currentWalk.markStart(currentWalk.parseCommit(headId)); + } catch (IOException e) { + throw new IllegalStateException(NLS.bind( + UIText.GitHistoryPage_errorReadingHeadCommit, headId, + db.getDirectory().getAbsolutePath()), e); + } + } + + private void setupCommentViewer(Repository db, final TreeWalk fileWalker) { + commentViewer.setTreeWalk(fileWalker); + commentViewer.setDb(db); + commentViewer.refresh(); + } + + private TreeWalk setupFileViewer(Repository db, List<String> paths) { + final TreeWalk fileWalker = createFileWalker(db, paths); + fileViewer.setTreeWalk(db, fileWalker); + fileViewer.refresh(); + fileViewer.addSelectionChangedListener(commentViewer); + return fileWalker; + } + + private TreeWalk createFileWalker(Repository db, List<String> paths) { + final TreeWalk fileWalker = new TreeWalk(db); + fileWalker.setRecursive(true); + if (paths.size() > 0) { + pathFilters = paths; + currentWalk.setTreeFilter(AndTreeFilter.create(PathFilterGroup + .createFromStrings(paths), TreeFilter.ANY_DIFF)); + fileWalker.setFilter(currentWalk.getTreeFilter().clone()); + + } else { + pathFilters = null; + currentWalk.setTreeFilter(TreeFilter.ALL); + fileWalker.setFilter(TreeFilter.ANY_DIFF); + } + return fileWalker; + } + + private void scheduleNewGenerateHistoryJob() { + final SWTCommitList list = new SWTCommitList(graph.getControl().getDisplay()); + list.source(currentWalk); + final GenerateHistoryJob rj = new GenerateHistoryJob(this, list); + rj.addJobChangeListener(new JobChangeAdapter() { + @Override + public void done(final IJobChangeEvent event) { + final Control graphctl = graph.getControl(); + if (job != rj || graphctl.isDisposed()) + return; + graphctl.getDisplay().asyncExec(new Runnable() { + public void run() { + if (job == rj) + job = null; + } + }); + } + }); + job = rj; + if (trace) + GitTraceLocation.getTrace().trace( + GitTraceLocation.HISTORYVIEW.getLocation(), + "Scheduling GenerateHistoryJob"); //$NON-NLS-1$ + schedule(rj); + } + + private void schedule(final Job j) { + final IWorkbenchPartSite site = getWorkbenchSite(); + if (site != null) { + final IWorkbenchSiteProgressService p; + p = (IWorkbenchSiteProgressService) site + .getAdapter(IWorkbenchSiteProgressService.class); + if (p != null) { + p.schedule(j, 0, true /* use half-busy cursor */); + return; + } + } + j.schedule(); + } + + private IWorkbenchPartSite getWorkbenchSite() { + final IWorkbenchPart part = getHistoryPageSite().getPart(); + return part != null ? part.getSite() : null; + } + + /** + * {@link RevWalk#markStart(RevCommit)} all refs with given prefix to mark + * start of graph traversal using currentWalker + * + * @param prefix + * prefix of refs to be marked + * @throws IOException + * @throws MissingObjectException + * @throws IncorrectObjectTypeException + */ + private void markStartAllRefs(String prefix) throws IOException, + MissingObjectException, IncorrectObjectTypeException { + for (Entry<String, Ref> refEntry : input.getRepository() + .getRefDatabase().getRefs(prefix).entrySet()) { + Ref ref = refEntry.getValue(); + if (ref.isSymbolic()) + continue; + currentWalk.markStart(currentWalk.parseCommit(ref.getObjectId())); + } + } + + private void cancelRefreshJob() { + if (job != null && job.getState() != Job.NONE) { + job.cancel(); + try { + job.join(); + } catch (InterruptedException e) { + cancelRefreshJob(); + return; + } + job = null; + } + } } |