bac4732ecdf3a0c26b29b910e9d7e402c321477a
kate
  Fri Jun 28 15:36:45 2019 -0700
Allow tableBrowser setting in hubs. Requested for GeneHancer hub. refs #23744

diff --git src/hg/lib/cartTrackDb.c src/hg/lib/cartTrackDb.c
index 2a50696..6d4c762 100644
--- src/hg/lib/cartTrackDb.c
+++ src/hg/lib/cartTrackDb.c
@@ -9,70 +9,70 @@
 #include "hdb.h"
 #include "hgConfig.h"
 #include "hgMaf.h"
 #include "hubConnect.h"
 #include "joiner.h"
 #include "trackHub.h"
 #include "wikiTrack.h"
 
 /* Static globals */
 static boolean useAC = FALSE;
 static struct slRef *accessControlTrackRefList = NULL;
 
 static struct trackDb *getFullTrackList(struct cart *cart, char *db, struct grp **pHubGroups)
 {
 struct trackDb *list = hTrackDb(db);
-struct customTrack *ctList, *ct;
+
+// get hub tracks
+struct trackDb *hubTdbList = hubCollectTracks(db, pHubGroups);
+list = slCat(list, hubTdbList);
 
 /* exclude any track with a 'tableBrowser off' setting */
 struct trackDb *tdb, *nextTdb, *newList = NULL;
 for (tdb = list;  tdb != NULL;  tdb = nextTdb)
     {
     nextTdb = tdb->next;
     if (tdbIsDownloadsOnly(tdb) || tdb->table == NULL)
         {
         //freeMem(tdb);  // should not free tdb's.
         // While hdb.c should and says it does cache the tdbList, it doesn't.
         // The most notable reason that the tdbs are not cached is this hgTables CGI !!!
         // It needs to be rewritten to make tdbRef structures for the lists it creates here!
         continue;
         }
 
     char *tbOff = trackDbSetting(tdb, "tableBrowser");
     if (useAC && tbOff != NULL &&
         (startsWithWord("off", tbOff) || startsWithWord("noGenome", tbOff)))
         {
         slAddHead(&accessControlTrackRefList, slRefNew(tdb));
         if (! startsWithWord("off", tbOff))
             slAddHead(&newList, tdb);
         }
     else
 	slAddHead(&newList, tdb);
     }
-slReverse(&newList);
 list = newList;
 
 /* add wikiTrack if enabled */
 if (wikiTrackEnabled(db, NULL))
     slAddHead(&list, wikiTrackDb());
-slSort(&list, trackDbCmp);
 
-// Add hub tracks at head of list
-struct trackDb *hubTdbList = hubCollectTracks(db, pHubGroups);
-list = slCat(list, hubTdbList);
+slSort(&list, trackDbCmp);
 
 // Add custom tracks at head of list
+struct customTrack *ctList, *ct;
 ctList = customTracksParseCart(db, cart, NULL, NULL);
 for (ct = ctList; ct != NULL; ct = ct->next)
     {
     slAddHead(&list, ct->tdb);
     }
 
 return list;
 }
 
 static struct grp *makeGroupList(char *db, struct trackDb *trackList, struct grp **pHubGrpList,
                                  boolean allTablesOk)
 /* Get list of groups that actually have something in them. */
 {
 struct grp *groupsAll, *groupList = NULL, *group;
 struct hash *groupsInTrackList = newHash(0);