Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-07-06 13:18:52 -0400
committerThomas Wolf2019-07-07 09:51:12 -0400
commit10293f9f0c3739a66e772d7cd3e7560f7c4b7ccd (patch)
tree1016e62c613fff40582fbe13bda40a73f1d2fd11 /org.eclipse.egit.ui
parentb9df19f1d83ca2daa7272369d264f9806d8118ab (diff)
downloadegit-10293f9f0c3739a66e772d7cd3e7560f7c4b7ccd.tar.gz
egit-10293f9f0c3739a66e772d7cd3e7560f7c4b7ccd.tar.xz
egit-10293f9f0c3739a66e772d7cd3e7560f7c4b7ccd.zip
Fix showing selected refs or commits in history view
When the history view shows only the current branch ("Show all branches and tags" _off_), selecting some other branch in the git repositories view might not show the selected branch. It would be shown only if that branch happened to be merged into the currently checked out branch. The same could be observed when using "Show In History" on a commit in the results of a "Git Search": the commit would only be selected if it was contained in the branch currently checked out. Change this by always considering such a selected branch or commit as an additional start point for the RevWalk. This enables the user to make the history view show exactly two branches (plus all those merged into these two), and also correctly selects commits not on the current branch. Bug: 360868 Change-Id: Ib2e071f40c57b06a0ce0a51defac3fe30f481e03 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java33
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryWalk.java19
2 files changed, 44 insertions, 8 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 589d849b8..3a9c6ec71 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
@@ -809,6 +809,9 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
/** Repository of the last input*/
private Repository currentRepo;
+ /** ObjectId of the ref or commit of the last input, if any. */
+ private ObjectId selectedObj;
+
private boolean currentShowAllBranches;
private boolean currentShowAdditionalRefs;
@@ -1661,6 +1664,8 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
renameTracker.reset(null);
Job.getJobManager().cancel(JobFamilies.HISTORY_DIFF);
+ currentRepo = null;
+ selectedObj = null;
super.dispose();
}
@@ -1685,6 +1690,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
private void clearHistoryPage() {
currentRepo = null;
+ selectedObj = null;
name = ""; //$NON-NLS-1$
input = null;
commentViewer.setInput(null);
@@ -1957,7 +1963,13 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
setErrorMessage(null);
try {
- initAndStartRevWalk(false);
+ ObjectId id = null;
+ if (ref != null) {
+ id = ref.getLeaf().getObjectId();
+ } else if (selection != null) {
+ id = selection.getId();
+ }
+ initAndStartRevWalk(false, id);
} catch (IllegalStateException e) {
Activator.handleError(e.getMessage(), e, true);
return false;
@@ -2291,7 +2303,13 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
warningComposite.getParent().layout(true);
}
- void initAndStartRevWalk(boolean forceNewWalk) throws IllegalStateException {
+ private void initAndStartRevWalk(boolean forceNewWalk) {
+ initAndStartRevWalk(forceNewWalk, selectedObj);
+ }
+
+ private void initAndStartRevWalk(boolean forceNewWalk,
+ ObjectId newSelectedObj)
+ throws IllegalStateException {
try {
if (trace)
GitTraceLocation.getTrace().traceEntry(
@@ -2309,6 +2327,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
if (headId == null) {
currentHeadId = null;
currentFetchHeadId = null;
+ selectedObj = null;
currentRepo = db;
clearViewers();
return;
@@ -2324,7 +2343,13 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
currentRepo = db;
}
- if (forceNewWalk || repoChanged
+ boolean objChanged = false;
+ if (newSelectedObj != null && newSelectedObj != selectedObj) {
+ objChanged = !newSelectedObj.equals(selectedObj);
+ }
+ selectedObj = newSelectedObj;
+
+ if (forceNewWalk || repoChanged || objChanged
|| shouldRedraw(headId, fetchHeadId, paths)) {
releaseGenerateHistoryJob();
@@ -2501,7 +2526,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
AnyObjectId fetchHeadId) {
currentHeadId = headId;
currentFetchHeadId = fetchHeadId;
- SWTWalk walk = new GitHistoryWalk(db, headId);
+ SWTWalk walk = new GitHistoryWalk(db, headId, selectedObj);
try {
if (store
.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_ADDITIONAL_REFS))
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryWalk.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryWalk.java
index ec5fd7c7d..57ccd8e79 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryWalk.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryWalk.java
@@ -21,6 +21,7 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
@@ -39,9 +40,12 @@ class GitHistoryWalk extends SWTWalk {
private final AnyObjectId headId;
- GitHistoryWalk(Repository repository, AnyObjectId headId) {
+ private final ObjectId toShow;
+
+ GitHistoryWalk(Repository repository, AnyObjectId headId, ObjectId toShow) {
super(repository);
this.headId = headId;
+ this.toShow = toShow;
}
@Override
@@ -85,6 +89,9 @@ class GitHistoryWalk extends SWTWalk {
markUninteresting(db, Constants.R_NOTES);
}
markStart(parseCommit(headId));
+ if (toShow != null) {
+ markStart(toShow);
+ }
} catch (IOException e) {
throw new IOException(MessageFormat.format(
UIText.GitHistoryPage_errorSettingStartPoints,
@@ -111,11 +118,10 @@ class GitHistoryWalk extends SWTWalk {
}
}
- private void markStartRef(Ref ref)
+ private void markStart(ObjectId id)
throws IOException, IncorrectObjectTypeException {
try {
- RevObject refTarget = parseAny(ref.getLeaf().getObjectId());
- RevObject peeled = peel(refTarget);
+ RevObject peeled = peel(parseAny(id));
if (peeled instanceof RevCommit) {
markStart((RevCommit) peeled);
}
@@ -126,6 +132,11 @@ class GitHistoryWalk extends SWTWalk {
}
}
+ private void markStartRef(Ref ref)
+ throws IOException, IncorrectObjectTypeException {
+ markStart(ref.getLeaf().getObjectId());
+ }
+
private void markUninteresting(RefDatabase db, String prefix)
throws IOException, IncorrectObjectTypeException {
for (Ref ref : db.getRefsByPrefix(prefix)) {

Back to the top