Fix NPE when checking out from dashboard

Change-Id: I2ec49672659f1a1aef94d5bd6832e979e93f9415
diff --git a/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/BranchSelectionDialog.java b/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/BranchSelectionDialog.java
index 12eac6a..63b0417 100644
--- a/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/BranchSelectionDialog.java
+++ b/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/BranchSelectionDialog.java
@@ -15,6 +15,7 @@
 import java.util.Map.Entry;
 
 import org.eclipse.egerrit.internal.model.ChangeInfo;
+import org.eclipse.egerrit.internal.model.RevisionInfo;
 import org.eclipse.egerrit.internal.ui.table.model.BranchMatch;
 import org.eclipse.egerrit.internal.ui.table.model.BranchSelectionTableModel;
 import org.eclipse.egerrit.internal.ui.table.model.ITableModel;
@@ -67,13 +68,17 @@
 
 	private ChangeInfo changeInfo;
 
+	private RevisionInfo revisionCheckedOut;
+
 	private final static int WIDTH = 400;
 
-	public BranchSelectionDialog(Shell parent, Map<String, BranchMatch> potentialBranches2, ChangeInfo changeInfo) {
+	public BranchSelectionDialog(Shell parent, Map<String, BranchMatch> potentialBranches2, ChangeInfo changeInfo,
+			RevisionInfo revisionCheckedOut) {
 		super(parent);
 		setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.MAX | SWT.RESIZE | getDefaultOrientation());
 		this.potentialBranches = potentialBranches2;
 		this.changeInfo = changeInfo;
+		this.revisionCheckedOut = revisionCheckedOut;
 	}
 
 	@Override
@@ -122,8 +127,8 @@
 		aParent.setLayout(layout);
 		// Create the table viewer to maintain the list of review files
 		Label labelHeader = new Label(aParent, SWT.NONE | SWT.WRAP);
-		labelHeader.setText(NLS.bind(Messages.BranchSelectionTableModel_question,
-				changeInfo.getUserSelectedRevision().get_number(), changeInfo.getSubject()));
+		labelHeader.setText(NLS.bind(Messages.BranchSelectionTableModel_question, revisionCheckedOut.get_number(),
+				changeInfo.getSubject()));
 		labelHeader.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
 
 		fViewer = new TableViewer(aParent, TABLE_STYLE);
diff --git a/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/CheckoutRevision.java b/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/CheckoutRevision.java
index ab9e7d9..f63d52a 100644
--- a/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/CheckoutRevision.java
+++ b/org.eclipse.egerrit.ui/src/org/eclipse/egerrit/internal/ui/editors/CheckoutRevision.java
@@ -47,16 +47,16 @@
 

 public class CheckoutRevision extends Action {

 

-	private RevisionInfo revision;

+	private RevisionInfo revisionCheckedOut;

 

 	private GerritClient gerritClient;

 

 	private ChangeInfo changeInfo;

 

 	public CheckoutRevision(RevisionInfo revision, GerritClient gerritClient) {

-		this.revision = revision;

+		this.revisionCheckedOut = revision;

 		this.gerritClient = gerritClient;

-		this.changeInfo = this.revision.getChangeInfo();

+		this.changeInfo = this.revisionCheckedOut.getChangeInfo();

 		setText(Messages.CheckoutRevision_0);

 	}

 

@@ -70,7 +70,7 @@
 			return;

 		}

 

-		String psSelected = revision.getRef();

+		String psSelected = revisionCheckedOut.getRef();

 		if ((psSelected == null) || psSelected.isEmpty()) {

 			Status status = new Status(IStatus.ERROR, EGerritCorePlugin.PLUGIN_ID, Messages.CheckoutRevision_4);

 			ErrorDialog.openError(getShell(), Messages.CheckoutRevision_2, Messages.CheckoutRevision_3, status);

@@ -98,7 +98,7 @@
 				}

 			}

 		}

-		ActiveWorkspaceRevision.getInstance().activateCurrentRevision(gerritClient, revision);

+		ActiveWorkspaceRevision.getInstance().activateCurrentRevision(gerritClient, revisionCheckedOut);

 	}

 

 	public Map<String, BranchMatch> findAllPotentialBranches(Repository localRepo) {

@@ -147,12 +147,13 @@
 	 * @param potentialBranches

 	 */

 	private void branchUiSelection(Repository localRepo, Map<String, BranchMatch> potentialBranches) {

-		BranchSelectionDialog branchSelectDialog = new BranchSelectionDialog(null, potentialBranches, changeInfo);

+		BranchSelectionDialog branchSelectDialog = new BranchSelectionDialog(null, potentialBranches, changeInfo,

+				revisionCheckedOut);

 		int result = branchSelectDialog.open();

 		String selectedBranch = branchSelectDialog.getSelectedBranch();

 		if (result == IDialogConstants.OK_ID) {

 			//New selected

-			String psSelected = revision.getRef();

+			String psSelected = revisionCheckedOut.getRef();

 			FetchGerritChangeWizard var = new FetchGerritChangeWizard(localRepo, psSelected);

 			WizardDialog w = new WizardDialog(getShell(), var);

 			w.create();

@@ -168,11 +169,11 @@
 	}

 

 	private Map<String, BranchMatch> mapPotentialBranch(Map<String, Map<String, List<String>>> mapBranchesChangeId) {

-		String lookingChangeId = revision.getChangeInfo().getChange_id().trim();

-		String lookingCommitIdForRevision = revision.getCommit().getCommit().trim();

+		String lookingChangeId = revisionCheckedOut.getChangeInfo().getChange_id().trim();

+		String lookingCommitIdForRevision = revisionCheckedOut.getCommit().getCommit().trim();

 		Map<String, BranchMatch> mapBranches = new TreeMap<String, BranchMatch>();

 		String defaultBranchName = changeInfo.get_number() + "/" //$NON-NLS-1$

-				+ revision.get_number();

+				+ revisionCheckedOut.get_number();

 		Iterator<Entry<String, Map<String, List<String>>>> iterBranch = mapBranchesChangeId.entrySet().iterator();

 		while (iterBranch.hasNext()) {

 			Entry<String, Map<String, List<String>>> entryBranch = iterBranch.next();