da1f0d67fe492b997b07bbebe6e5f4a86170331b
angie
  Wed May 4 10:07:18 2016 -0700
Same as in hgGateway (d30337d4), I forgot to initialize oldVars (thanks Hiram for noticing!) and also wasn't using getDbGenomeClade which handles position reset when db changes.  refs #17267#note-5.

diff --git src/hg/hgChooseDb/hgChooseDb.c src/hg/hgChooseDb/hgChooseDb.c
index df28237..bc19308 100644
--- src/hg/hgChooseDb/hgChooseDb.c
+++ src/hg/hgChooseDb/hgChooseDb.c
@@ -12,30 +12,31 @@
 #include "common.h"
 #include "cart.h"
 #include "cartJson.h"
 #include "cheapcgi.h"
 #include "hCommon.h"
 #include "hdb.h"
 #include "hui.h"
 #include "jsHelper.h"
 #include "jsonParse.h"
 #include "obscure.h"  // for readInGulp
 #include "trackHub.h"
 #include "web.h"
 
 /* Global Variables */
 struct cart *cart = NULL;             /* CGI and other variables */
+struct hash *oldVars = NULL;          /* Old contents of cart before it was updated by CGI */
 
 #define SEARCH_TERM "hgcd_term"
 
 static char *getPhotoForGenome(char *genome, char *db)
 /* If the expected file for this genome's description page photo exists, return the filename. */
 {
 if (db == NULL)
     db = hDefaultDbForGenome(genome);
 char baseName[PATH_LEN];
 if (sameString("Human", genome))
     safecpy(baseName, sizeof(baseName), "human.jpg");
 else
     {
     safef(baseName, sizeof(baseName), "%s.jpg", hScientificName(db));
     subChar(baseName, ' ', '_');
@@ -149,31 +150,32 @@
 static void doCartJson()
 /* Perform UI commands to update the cart and/or retrieve cart vars & metadata. */
 {
 struct cartJson *cj = cartJsonNew(cart);
 cartJsonRegisterHandler(cj, "getPopularSpecies", getPopularSpecies);
 cartJsonRegisterHandler(cj, "getDbMenu", getDbMenu);
 cartJsonRegisterHandler(cj, "getDescriptionHtml", getDescriptionHtml);
 cartJsonExecute(cj);
 }
 
 static void doMainPage()
 /* Send HTML with javascript to bootstrap the user interface. */
 {
 //#*** A lot of this is copied from hgIntegrator... libify!
 
-char *db = cartUsualString(cart, "db", hDefaultDb());
+char *db = NULL, *genome = NULL, *clade = NULL;
+getDbGenomeClade(cart, &db, &genome, &clade, oldVars);
 webStartWrapperDetailedNoArgs(cart, trackHubSkipHubName(db),
                               "", "UCSC Genome Browser Databases",
                               TRUE, FALSE, TRUE, TRUE);
 
 // Ideally these would go in the <HEAD>
 puts("<link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css\">");
 puts("<link rel=\"stylesheet\" href=\"//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css\">");
 
 puts("<div id=\"appContainer\">Loading...</div>");
 
 // Set a global JS variable hgsid.
 // Plain old "var ..." doesn't work (other scripts can't see it), it has to belong to window.
 printf("<script>window.%s='%s';</script>\n", cartSessionVarName(), cartSessionId(cart));
 
 jsIncludeReactLibs();
@@ -259,25 +261,25 @@
     jsonWriteObjectStart(jw, NULL);
     jsonWriteString(jw, "value", hel->name);
     jsonWriteString(jw, "genome", dbDb->genome);
     jsonWriteObjectEnd(jw);
     }
 jsonWriteListEnd(jw);
 puts(jw->dy->string);
 }
 
 int main(int argc, char *argv[])
 /* Process CGI / command line. */
 {
 /* Null terminated list of CGI Variables we don't want to save
  * permanently. */
 char *excludeVars[] = {SEARCH_TERM, CARTJSON_COMMAND, NULL,};
-struct hash *oldVars = NULL;
 cgiSpoof(&argc, argv);
 setUdcCacheDir();
+oldVars = hashNew(10);
 if (cgiOptionalString(SEARCH_TERM))
     // Skip the cart for speedy searches
     lookupTerm();
 else
     cartEmptyShellNoContent(doMiddle, hUserCookie(), excludeVars, oldVars);
 return 0;
 }