b02d20dede590203b6ecca10be473e7e22179a51
braney
  Thu Jan 12 13:12:53 2023 -0800
deal with some weird edge cases in hub that Hiram's hub illicit.   Don't
read a single trackDb.txt file more than once even if it's referenced
from mulitple hubs.  Also, only the first time a genome is defined does
it get to populate its own groups.  Subsequent examples get put into
their own group, just like a normal track hub does.

diff --git src/hg/lib/trackHub.c src/hg/lib/trackHub.c
index 8553c53..60351b7 100644
--- src/hg/lib/trackHub.c
+++ src/hg/lib/trackHub.c
@@ -1052,34 +1052,35 @@
         {
         validateOneTrack(hub, genome, tdb);
         }
     errCatchEnd(errCatch);
     if (errCatch->gotError)
         {
         tdb->errMessage = cloneString(errCatch->message->string);
         }
 
     // clear these two pointers which we set in markContainers
     tdb->subtracks = NULL;
     tdb->parent = NULL;
     }
 }
 
-struct trackDb *trackHubTracksForGenome(struct trackHub *hub, struct trackHubGenome *genome, struct dyString *incFiles)
+struct trackDb *trackHubTracksForGenome(struct trackHub *hub, struct trackHubGenome *genome, struct dyString *incFiles, boolean *foundFirstGenome)
 /* Get list of tracks associated with genome.  Check that it only is composed of legal
  * types.  Do a few other quick checks to catch errors early. If incFiles is not NULL,
- * put the list of included files in there. */
+ * put the list of included files in there.  Only the first example of a genome 
+ * gets to populate groups, the others get a group for the trackHub.  */
 {
 struct lineFile *lf = udcWrapShortLineFile(genome->trackDbFile, NULL, MAX_HUB_TRACKDB_FILE_SIZE);
 struct trackDb *tdbList = trackDbFromOpenRa(lf, NULL, incFiles);
 lineFileClose(&lf);
 
 char *tabMetaName = hashFindVal(genome->settingsHash, "metaTab");
 char *absTabName  = NULL;
 if (tabMetaName)
     absTabName  = trackHubRelativeUrl(hub->url, tabMetaName);
 
 char *tagStormName = hashFindVal(genome->settingsHash, "metaDb");
 char *absStormName  = NULL;
 if (tagStormName)
     absStormName  = trackHubRelativeUrl(hub->url, tagStormName);
 
@@ -1087,32 +1088,34 @@
 struct trackDb *tdb;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
     {
     expandBigDataUrl(hub, genome, tdb);
     if  (absStormName)
         hashReplace(tdb->settingsHash, "metaDb", absStormName);
     if  (absTabName)
         hashReplace(tdb->settingsHash, "metaTab", absTabName);
     }
 
 validateTracks(hub, genome, tdbList);
 
 trackDbAddTableField(tdbList);
 if (!isEmpty(hub->name))
     trackHubAddNamePrefix(hub->name, tdbList);
-if (genome->twoBitPath == NULL)
+if (genome->twoBitPath == NULL || *foundFirstGenome)
     trackHubAddGroupName(hub->name, tdbList);
+else
+    *foundFirstGenome = TRUE;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
     {
     trackDbFieldsFromSettings(tdb);
     trackDbPolish(tdb);
     }
 return tdbList;
 }
 
 static void reprefixString(char **pString, char *prefix)
 /* Replace *pString with prefix + *pString, freeing
  * whatever was in *pString before. */
 {
 char *oldName = *pString;
 *pString = catTwoStrings(prefix, oldName);
 freeMem(oldName);