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 [
* + 97
* - 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
text_diff2cbuf(cbuf *cb,
@ -679,6 +682,7 @@ text_diff2cbuf(cbuf *cb,
char *leaflname = NULL; // XXX
cxobj *xi;
cxobj *xj;
int extflag;
level1 = level*PRETTYPRINT_INDENT;
if ((y0 = xml_spec(x0)) != NULL){
@ -694,40 +698,59 @@ text_diff2cbuf(cbuf *cb,
/* Check if one or both subtrees are NULL */
if (x0c == NULL && x1c == NULL)
goto ok;
else if (x0c == NULL){
if (nr==0 && skiptop==0){
cprintf(cb, "%*s", level1, "");
if (prefix)
cprintf(cb, "%s:", prefix);
cprintf(cb, "%s", xml_name(x1));
text_diff_keys(cb, x1, y0);
cprintf(cb, " {\n");
nr++;
else {
yc0 = NULL;
yc1 = NULL;
/* If cl:ignore-compare extension, skip */
if (x0c && (yc0 = xml_spec(x0c)) != NULL){
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 (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 (x1c && (yc1 = xml_spec(x1c)) != NULL){
if (yang_extension_value(yc1, "ignore-compare", CLIXON_LIB_NS, &extflag, NULL) < 0)
goto done;
if (extflag){ /* skip */
x1c = xml_child_each(x1, x1c, CX_ELMNT);
continue;
}
}
if (x0c == NULL){
if (nr==0 && skiptop==0){
cprintf(cb, "%*s", level1, "");
if (prefix)
cprintf(cb, "%s:", prefix);
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. */
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 (text_diff2cbuf_ordered_by_user(cb, x0, x1, x0c, x1c, yc0,
level, skiptop) < 0)

View file

@ -1278,7 +1278,9 @@ xml_diff2cbuf_ordered_by_user(cbuf *cb,
* @endcode
* @see xml_diff which returns diff sets
* @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
xml_diff2cbuf(cbuf *cb,
@ -1302,6 +1304,7 @@ xml_diff2cbuf(cbuf *cb,
int level1;
cxobj *xi;
cxobj *xj;
int extflag;
level1 = level*PRETTYPRINT_INDENT;
y0 = xml_spec(x0);
@ -1312,33 +1315,52 @@ xml_diff2cbuf(cbuf *cb,
for (;;){
if (x0c == NULL && x1c == NULL)
goto ok;
else if (x0c == NULL){
/* 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++;
else {
yc0 = NULL;
yc1 = NULL;
/* If cl:ignore-compare extension, skip */
if (x0c && (yc0 = xml_spec(x0c)) != NULL){
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)
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 (x1c && (yc1 = xml_spec(x1c)) != NULL){
if (yang_extension_value(yc1, "ignore-compare", CLIXON_LIB_NS, &extflag, NULL) < 0)
goto done;
if (extflag){ /* skip */
x1c = xml_child_each(x1, x1c, CX_ELMNT);
continue;
}
}
if (x0c == NULL){
/* 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);
yc0 = xml_spec(x0c);
yc1 = xml_spec(x1c);
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,
level, skiptop) < 0)

View file

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