More fix problems with cl:ignore attribute for xml_diff2cbuf & co

This commit is contained in:
Olof hagsand 2024-02-07 15:57:49 +01:00
parent 833e748288
commit 9f592911f5
3 changed files with 101 additions and 54 deletions

View file

@ -654,7 +654,10 @@ text_diff2cbuf_ordered_by_user(cbuf *cb,
* + value [ * + value [
* + 97 * + 97
* - 99 * - 99
* @see xml_diff2cbuf * @see clixon_compare_xmls which uses files and is independent of YANG
* @see xml_diff2cbuf for XML
* @see xml_tree_equal Equal or not
* @see xml_diff Diff sets
*/ */
static int static int
text_diff2cbuf(cbuf *cb, text_diff2cbuf(cbuf *cb,
@ -679,6 +682,7 @@ text_diff2cbuf(cbuf *cb,
char *leaflname = NULL; // XXX char *leaflname = NULL; // XXX
cxobj *xi; cxobj *xi;
cxobj *xj; cxobj *xj;
int extflag;
level1 = level*PRETTYPRINT_INDENT; level1 = level*PRETTYPRINT_INDENT;
if ((y0 = xml_spec(x0)) != NULL){ if ((y0 = xml_spec(x0)) != NULL){
@ -694,40 +698,59 @@ text_diff2cbuf(cbuf *cb,
/* Check if one or both subtrees are NULL */ /* Check if one or both subtrees are NULL */
if (x0c == NULL && x1c == NULL) if (x0c == NULL && x1c == NULL)
goto ok; goto ok;
else if (x0c == NULL){ else {
if (nr==0 && skiptop==0){ yc0 = NULL;
cprintf(cb, "%*s", level1, ""); yc1 = NULL;
if (prefix) /* If cl:ignore-compare extension, skip */
cprintf(cb, "%s:", prefix); if (x0c && (yc0 = xml_spec(x0c)) != NULL){
cprintf(cb, "%s", xml_name(x1)); if (yang_extension_value(yc0, "ignore-compare", CLIXON_LIB_NS, &extflag, NULL) < 0)
text_diff_keys(cb, x1, y0); goto done;
cprintf(cb, " {\n"); if (extflag){ /* skip */
nr++; x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
}
} }
if (text2cbuf(cb, x1c, level+1, "+", 0, &leafl, &leaflname) < 0) if (x1c && (yc1 = xml_spec(x1c)) != NULL){
goto done; if (yang_extension_value(yc1, "ignore-compare", CLIXON_LIB_NS, &extflag, NULL) < 0)
x1c = xml_child_each(x1, x1c, CX_ELMNT); goto done;
continue; if (extflag){ /* skip */
} x1c = xml_child_each(x1, x1c, CX_ELMNT);
else if (x1c == NULL){ continue;
if (nr==0 && skiptop==0){ }
cprintf(cb, "%*s", level1, ""); }
if (prefix) if (x0c == NULL){
cprintf(cb, "%s:", prefix); if (nr==0 && skiptop==0){
cprintf(cb, "%s", xml_name(x0)); cprintf(cb, "%*s", level1, "");
text_diff_keys(cb, x0, y0); if (prefix)
cprintf(cb, "{\n"); cprintf(cb, "%s:", prefix);
nr++; cprintf(cb, "%s", xml_name(x1));
text_diff_keys(cb, x1, y0);
cprintf(cb, " {\n");
nr++;
}
if (text2cbuf(cb, x1c, level+1, "+", 0, &leafl, &leaflname) < 0)
goto done;
x1c = xml_child_each(x1, x1c, CX_ELMNT);
continue;
}
else if (x1c == NULL){
if (nr==0 && skiptop==0){
cprintf(cb, "%*s", level1, "");
if (prefix)
cprintf(cb, "%s:", prefix);
cprintf(cb, "%s", xml_name(x0));
text_diff_keys(cb, x0, y0);
cprintf(cb, "{\n");
nr++;
}
if (text2cbuf(cb, x0c, level+1, "-", 0, &leafl, &leaflname) < 0)
goto done;
x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
} }
if (text2cbuf(cb, x0c, level+1, "-", 0, &leafl, &leaflname) < 0)
goto done;
x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
} }
/* Both x0c and x1c exists, check if they are yang-equal. */ /* Both x0c and x1c exists, check if they are yang-equal. */
eq = xml_cmp(x0c, x1c, 0, 0, NULL); eq = xml_cmp(x0c, x1c, 0, 0, NULL);
yc0 = xml_spec(x0c);
yc1 = xml_spec(x1c);
if (eq && yc0 && yc1 && yc0 == yc1 && yang_find(yc0, Y_ORDERED_BY, "user")){ if (eq && yc0 && yc1 && yc0 == yc1 && yang_find(yc0, Y_ORDERED_BY, "user")){
if (text_diff2cbuf_ordered_by_user(cb, x0, x1, x0c, x1c, yc0, if (text_diff2cbuf_ordered_by_user(cb, x0, x1, x0c, x1c, yc0,
level, skiptop) < 0) level, skiptop) < 0)

View file

@ -1278,7 +1278,9 @@ xml_diff2cbuf_ordered_by_user(cbuf *cb,
* @endcode * @endcode
* @see xml_diff which returns diff sets * @see xml_diff which returns diff sets
* @see clixon_compare_xmls which uses files and is independent of YANG * @see clixon_compare_xmls which uses files and is independent of YANG
* @see text_diff2cbuf * @see text_diff2cbuf for curly
* @see xml_tree_equal Equal or not
* @see xml_diff Diff sets
*/ */
static int static int
xml_diff2cbuf(cbuf *cb, xml_diff2cbuf(cbuf *cb,
@ -1302,6 +1304,7 @@ xml_diff2cbuf(cbuf *cb,
int level1; int level1;
cxobj *xi; cxobj *xi;
cxobj *xj; cxobj *xj;
int extflag;
level1 = level*PRETTYPRINT_INDENT; level1 = level*PRETTYPRINT_INDENT;
y0 = xml_spec(x0); y0 = xml_spec(x0);
@ -1312,33 +1315,52 @@ xml_diff2cbuf(cbuf *cb,
for (;;){ for (;;){
if (x0c == NULL && x1c == NULL) if (x0c == NULL && x1c == NULL)
goto ok; goto ok;
else if (x0c == NULL){ else {
/* Check if one or both subtrees are NULL */ yc0 = NULL;
if (nr==0 && skiptop==0){ yc1 = NULL;
xml_diff_context(cb, x1, level1); /* If cl:ignore-compare extension, skip */
xml_diff_keys(cb, x1, y0, (level+1)*PRETTYPRINT_INDENT); if (x0c && (yc0 = xml_spec(x0c)) != NULL){
nr++; if (yang_extension_value(yc0, "ignore-compare", CLIXON_LIB_NS, &extflag, NULL) < 0)
goto done;
if (extflag){ /* skip */
x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
}
} }
if (clixon_xml2cbuf(cb, x1c, level+1, 1, "+", -1, 0) < 0) if (x1c && (yc1 = xml_spec(x1c)) != NULL){
goto done; if (yang_extension_value(yc1, "ignore-compare", CLIXON_LIB_NS, &extflag, NULL) < 0)
x1c = xml_child_each(x1, x1c, CX_ELMNT); goto done;
continue; if (extflag){ /* skip */
} x1c = xml_child_each(x1, x1c, CX_ELMNT);
else if (x1c == NULL){ continue;
if (nr==0 && skiptop==0){ }
xml_diff_context(cb, x0, level1); }
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT); if (x0c == NULL){
nr++; /* Check if one or both subtrees are NULL */
if (nr==0 && skiptop==0){
xml_diff_context(cb, x1, level1);
xml_diff_keys(cb, x1, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
if (clixon_xml2cbuf(cb, x1c, level+1, 1, "+", -1, 0) < 0)
goto done;
x1c = xml_child_each(x1, x1c, CX_ELMNT);
continue;
}
else if (x1c == NULL){
if (nr==0 && skiptop==0){
xml_diff_context(cb, x0, level1);
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
if (clixon_xml2cbuf(cb, x0c, level+1, 1, "-", -1, 0) < 0)
goto done;
x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
} }
if (clixon_xml2cbuf(cb, x0c, level+1, 1, "-", -1, 0) < 0)
goto done;
x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
} }
/* Both x0c and x1c exists, check if they are yang-equal. */ /* Both x0c and x1c exists, check if yang equal */
eq = xml_cmp(x0c, x1c, 0, 0, NULL); eq = xml_cmp(x0c, x1c, 0, 0, NULL);
yc0 = xml_spec(x0c);
yc1 = xml_spec(x1c);
if (eq && yc0 && yc1 && yc0 == yc1 && yang_find(yc0, Y_ORDERED_BY, "user")){ if (eq && yc0 && yc1 && yc0 == yc1 && yang_find(yc0, Y_ORDERED_BY, "user")){
if (xml_diff2cbuf_ordered_by_user(cb, x0, x1, x0c, x1c, yc0, if (xml_diff2cbuf_ordered_by_user(cb, x0, x1, x0c, x1c, yc0,
level, skiptop) < 0) level, skiptop) < 0)

View file

@ -570,6 +570,8 @@ xml_diff(cxobj *x0,
* @retval 1 Not equal * @retval 1 Not equal
* @retval 0 Equal * @retval 0 Equal
* @see xml_diff which returns diff sets * @see xml_diff which returns diff sets
* @see xml_diff2cbuf Diff buffer in XML
* @see text_diff2cbuf Diff buffer in curly
*/ */
int int
xml_tree_equal(cxobj *x0, xml_tree_equal(cxobj *x0,