658bb95a9b155d3f759744f760320e90e99fe2d8
braney
  Fri Sep 13 10:59:53 2019 -0700
allow a comma-separated list in hubUrl statements

diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c
index 9a752d5..66db045 100644
--- src/hg/lib/hubConnect.c
+++ src/hg/lib/hubConnect.c
@@ -558,65 +558,90 @@
 char **row;
 while ((row = sqlNextRow(sr)) != NULL)
     {
     int id = sqlUnsigned(row[0]);
     char buffer[512];
 
     safef(buffer, sizeof(buffer), "hgHubConnect.hub.%d", id);
     cartRemove(cart, buffer);
     }
 sqlFreeResult(&sr);
 
 hDisconnectCentral(&conn);
 }
 
 static char  *checkForNew( struct cart *cart)
-/* see if the user just typed in a new hub url, return id if so */
+/* see if the user just typed in a new hub url, or we have a hubUrl on the 
+ * command line.  Return the new database if there is one. */
 {
-struct hubConnectStatus *hub;
-char *url = cartOptionalString(cart, hgHubDataClearText);
+char *newDatabase = NULL;
+boolean doClear = FALSE;
+char *assemblyDb = cartOptionalString(cart, hgHubGenome);
+char *wantFirstDb = cartOptionalString(cart, hgHubDoFirstDb);
 
-if (url != NULL)
-    disconnectHubsSamePrefix(cart, url);
+char *urls = cloneString(cartOptionalString(cart, hgHubDataClearText));
+if (urls)
+    doClear = TRUE;
 else
-    url = cartOptionalString(cart, hgHubDataText);
+    urls = cloneString(cartOptionalString(cart, hgHubDataText));
+
+cartRemove(cart, hgHubDataClearText);
+cartRemove(cart, hgHubDataText);
 
-if (url == NULL)
+if (urls == NULL)
     return NULL;
 
+char *words[128];
+int count = chopString(urls, ",", words, sizeof words/sizeof(char *));
+
+int ii;
+for(ii = 0; ii < count; ii++)
+    {
+    char *url = words[ii];
+
+    if (doClear)
+        disconnectHubsSamePrefix(cart, url);
+
     trimSpaces(url);
 
+    // go and grab the hub and set the cart variables to connect it
+    struct hubConnectStatus *hub;
     gNewHub = hub = getAndSetHubStatus( cart, url, TRUE);
 
-cartRemove(cart, hgHubDataClearText);
-cartRemove(cart, hgHubDataText);
-
-char *wantFirstDb = cartOptionalString(cart, hgHubDoFirstDb);
-char *newDatabase = NULL;
-if ((wantFirstDb != NULL) && (hub->trackHub != NULL))
+    if (newDatabase == NULL)  // if we haven't picked a new database yet
+        {
+        if ((wantFirstDb != NULL) && (hub->trackHub != NULL)) // choose the first db
             newDatabase = hub->trackHub->defaultDb;
-else 
+        else if (assemblyDb != NULL)
             {
             // Check to see if the user specified an assembly within
             // an assembly hub.
-    char *assemblyDb = cartOptionalString(cart, hgHubGenome);
-    if (assemblyDb != NULL)
+            struct trackHub *trackHub = hub->trackHub;
+            if (trackHub != NULL)
                 {
-        char buffer[512];
+                struct trackHubGenome *genomeList = trackHub->genomeList;
 
-        safef(buffer, sizeof buffer, "hub_%d_%s",  hub->id, assemblyDb);
-        newDatabase = cloneString(buffer);
+                for(; genomeList; genomeList = genomeList->next)
+                    {
+                    if (sameString(assemblyDb, hubConnectSkipHubPrefix(genomeList->name)))
+                        {
+                        newDatabase = genomeList->name;
+                        break;
+                        }
+                    }
+                }
+            }
         }
     }
 
 cartRemove(cart, hgHubDoFirstDb);
 cartRemove(cart, hgHubGenome);
 return newDatabase;
 }
 
 unsigned hubResetError(char *url)
 /* clear the error for this url in the hubStatus table,return the id */
 {
 struct sqlConnection *conn = hConnectCentral();
 char query[512];
 
 sqlSafef(query, sizeof(query), "select id from %s where hubUrl = \"%s\"", getHubStatusTableName(), url);