ae9de008e7786f3fccd9f52db6514540b1c995d5
kent
Thu Mar 31 05:52:43 2011 -0700
Smoothing out the handling of the track->children pointer and track->subtracks pointer so that it works the same in hgTrackUi as elsewhere. The children pointers are set after pruning the track list for ones where the data table is not available.
diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index d5aa689..fa69cf0 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -3562,61 +3562,81 @@
}
static struct trackDb *rFindTrack(int level, struct trackDb *tdbList, char *track)
/* Look for named track in list or children. */
{
struct trackDb *tdb;
for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
{
if (sameString(track, tdb->track))
return tdb;
struct trackDb *matchingChild = rFindTrack(level+1, tdb->subtracks, track);
if (matchingChild != NULL)
return matchingChild;
}
-/* Look "to the sky" in parents of root generation well. */
+/* Look "to the sky" in parents of root generation as well. */
if (level == 0)
{
for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
{
struct trackDb *p = tdb->parent;
if (p != NULL && sameString(track, p->track))
return p;
}
}
return NULL;
}
#ifdef DEBUG
static void dumpFlagStatus(struct trackDb *tdbList, char *tableName, char *label)
/* Look for tdbList for track matching tableName. Print out info on it starting with label. */
{
struct trackDb *tdb = rFindTrack(0, tdbList, tableName);
if (tdb == NULL)
printf("%s: nil
\n", label);
else
printf("%s: treeNodeType %d, composite? %d, supertrack ? %d
\n", label, tdb->treeNodeType, COMPOSITE_NODE(tdb->treeNodeType), SUPERTRACK_NODE(tdb->treeNodeType));
}
#endif /* DEBUG */
+static void addChildRefsToParents(struct trackDb *tdbList)
+/* Go through tdbList and set up the ->children field in parents with references
+ * to their children. */
+{
+struct trackDb *tdb;
+
+/* Insert a little paranoid check here to make sure this doesn't get called twice. */
+for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
+ if (tdb->children != NULL)
+ internalErr();
+
+for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
+ {
+ struct trackDb *parent = tdb->parent;
+ if (parent != NULL)
+ refAdd(&parent->children, tdb);
+ }
+}
+
struct trackDb *trackDbPolishAfterLinkup(struct trackDb *tdbList, char *db)
/* Do various massaging that can only be done after parent/child
* relationships are established. */
{
tdbList = pruneEmpties(tdbList, db, hIsPrivateHost() || hIsPreviewHost(), 0);
+addChildRefsToParents(tdbList);
trackDbContainerMarkup(NULL, tdbList);
rInheritFields(tdbList);
slSort(&tdbList, trackDbCmp);
return tdbList;
}
struct trackDb *hTrackDb(char *db)
/* Load tracks associated with current db.
* Supertracks are loaded as a trackDb, but are not in the returned list,
* but are accessible via the parent pointers of the member tracks. Also,
* the supertrack trackDb subtrack fields are not set here (would be
* incompatible with the returned list)
* Returns list sorted by priority
* NOTE: this result is cached, do not free it !
*/
@@ -3646,51 +3666,30 @@
char *track)
/* Load trackDb object for a track. this is common code for two external
* functions. Handle composite tracks and subtrack inheritance here.
*/
{
struct trackDb *trackTdb = NULL;
char where[256];
safef(where, sizeof(where), "tableName = '%s'", track);
trackTdb = loadAndLookupTrackDb(conn, where);
if (!trackTdb)
return NULL;
return trackTdb;
}
-void hTrackDbLoadSuper(char *db, struct trackDb *tdb)
-/* Populate child trackDbs of this supertrack */
-{
-if (!tdb || !tdbIsSuper(tdb))
- return;
-
-struct sqlConnection *conn = hAllocConn(db);
-char where[256];
-safef(where, sizeof(where),
- "settings rlike '^(.*\n)?superTrack %s([ \n].*)?$' order by priority desc",
- tdb->track);
-tdb->subtracks = loadAndLookupTrackDb(conn, where); // TODO: Straighten out when super points to children and when not!
-struct trackDb *subTdb;
-for (subTdb = tdb->subtracks; subTdb != NULL; subTdb = subTdb->next)
- {
- subTdb->parent = tdb;
- trackDbSuperMemberSettings(subTdb);
- }
-hFreeConn(&conn);
-}
-
struct trackDb *tdbForTrack(char *db, char *track,struct trackDb **tdbList)
/* Load trackDb object for a track. If track is composite, its subtracks
* will also be loaded and inheritance will be handled; if track is a
* subtrack then inheritance will be handled. (Unless a subtrack has
* "noInherit on"...) This will die if the current database does not have
* a trackDb, but will return NULL if track is not found.
* MAY pass in prepopulated trackDb list, or may receive the trackDb list as an inout. */
{
/* Get track list .*/
struct trackDb *theTdbs = NULL;
if (tdbList == NULL || *tdbList == NULL)
{
if (isHubTrack(track))
{
struct hash *hash = hashNew(0);