src/hg/oneShot/tdbRewriteReduceReplaces/tdbRewriteReduceReplaces.c 1.2
1.2 2010/01/04 19:12:39 kent
Merging viewInTheMiddle branch.
Index: src/hg/oneShot/tdbRewriteReduceReplaces/tdbRewriteReduceReplaces.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/oneShot/tdbRewriteReduceReplaces/tdbRewriteReduceReplaces.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -b -B -U 4 -r1.1 -r1.2
--- src/hg/oneShot/tdbRewriteReduceReplaces/tdbRewriteReduceReplaces.c 9 Dec 2009 02:28:29 -0000 1.1
+++ src/hg/oneShot/tdbRewriteReduceReplaces/tdbRewriteReduceReplaces.c 4 Jan 2010 19:12:39 -0000 1.2
@@ -78,24 +78,8 @@
struct raFile *fileList; /* List of files at this level. */
struct hash *trackHash; /* Hash of all track records in level. */
};
-#ifdef SOON
-static void raTagWrite(struct raTag *tag, FILE *f)
-/* Write tag to file */
-{
-fputs(tag->text, f);
-}
-#endif
-
-int raTagCmp(const void *va, const void *vb)
-/* Compare two raTags. */
-{
-const struct raTag *a = *((struct raTag **)va);
-const struct raTag *b = *((struct raTag **)vb);
-return strcmp(a->name, b->name);
-}
-
void recordLocationReport(struct raRecord *rec, FILE *out)
/* Write out where record ends. */
{
fprintf(out, "in stanza from lines %d-%d of %s\n",
@@ -286,9 +270,9 @@
for (hel = hashLookup(level->trackHash, parentKey); hel != NULL; hel = hashLookupNext(hel))
{
struct raRecord *parent = hel->val;
int distance = record->startLineIx - parent->startLineIx;
- if (distance < 0)
+ if (distance > 0)
distance = BIGNUM/4 - distance;
if (record->file != parent->file)
distance = BIGNUM/2;
if (distance < closestDistance)
@@ -366,20 +350,24 @@
return FALSE;
return TRUE;
}
-boolean canTurnToOverride(struct raRecord *parent, struct raRecord *child)
+boolean canTurnToOverride(struct raRecord *parent, struct raRecord *child, struct dyString *dy)
/* If child has all the fields that parent has, then can express it as override of parent. */
{
struct raTag *t;
+boolean ok = TRUE;
for (t = parent->tagList; t != NULL; t = t->next)
{
if (!raRecordFindTag(child, t->name))
{
- return FALSE;
+ if (dy->stringSize != 0)
+ dyStringAppendC(dy, ',');
+ dyStringAppend(dy, t->name);
+ ok = FALSE;
}
}
-return TRUE;
+return ok;
}
boolean canSwallow(struct raRecord *parent, struct raRecord *child)
/* Return TRUE if parent has all records in child, and has the same value for them. */
@@ -418,17 +406,22 @@
}
if (parentRecord != NULL && sameString(mergeOp, "replace"))
{
- if (canTurnToOverride(parentRecord, r))
+ struct dyString *replaceReasons = dyStringNew(0);
+ if (canTurnToOverride(parentRecord, r, replaceReasons))
{
if (canSwallow(parentRecord, r))
{
+ if (verboseLevel() >= 2)
+ recordWarn(r, "swallowing record that is same as in parent dir");
}
else
{
mustWrite(f, t->text, tagStart - t->text);
fprintf(f, "track %s override\n", r->key);
+ if (verboseLevel() >= 2)
+ recordWarn(r, "turning replace record into override");
for (t = t->next; t != NULL; t = t->next)
{
if (!sameTagInOtherRecord(t, parentRecord))
fputs(t->text, f);
@@ -448,9 +441,10 @@
mustWrite(f, t->text, spaceCount);
}
/* Write out comment making replacement explicit. */
- fprintf(f, "#%s replaces record in parent directory\n", r->key);
+ fprintf(f, "#replaces record %s in parent dir missing/extra %s\n", r->key,
+ replaceReasons->string);
/* Writing out rest of stanza. */
for (; t != NULL; t = t->next)
fputs(t->text, f);