Skip to content

Commit

Permalink
Fixed: [commit d
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Oct 4, 2023
1 parent 39d3e53 commit 0a72432
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
## 6.5.0
Expected: December 2023

### Corrected Bugs

* Fixed: [commit diff sometimes includes namespace in output](https://github.com/clicon/clixon-controller/issues/44)

## 6.4.0
30 September 2023

Expand Down
43 changes: 37 additions & 6 deletions lib/src/clixon_xml_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,37 @@ xml_diff_keys(cbuf *cb,
return 0;
}

/*! Print one line of context around diff
*/
static int
xml_diff_context(cbuf *cb,
cxobj *xn,
int level)
{
int retval = -1;
char *prefix;
char *namespace = NULL;

prefix = xml_prefix(xn);
if (xml2ns(xn, prefix, &namespace) < 0)
goto done;
cprintf(cb, "%*s<", level, "");
if (namespace){
if (prefix)
cprintf(cb, "%s:", prefix);
cprintf(cb, "%s xmlns", xml_name(xn));
if (prefix)
cprintf(cb, ":%s", prefix);
cprintf(cb, "=\"%s\"", namespace);
cprintf(cb, ">\n");
}
else
cprintf(cb, "%s>\n", xml_name(xn));
retval = 0;
done:
return retval;
}

/*! Print XML diff of two cxobj trees into a cbuf
*
* YANG dependent
Expand Down Expand Up @@ -971,7 +1002,7 @@ xml_diff2cbuf(cbuf *cb,
else if (x0c == NULL){
/* Check if one or both subtrees are NULL */
if (nr==0 && skiptop==0){
cprintf(cb, "%*s<%s>\n", level1, "", xml_name(x1));
xml_diff_context(cb, x1, level1);
xml_diff_keys(cb, x1, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
Expand All @@ -982,7 +1013,7 @@ xml_diff2cbuf(cbuf *cb,
}
else if (x1c == NULL){
if (nr==0 && skiptop==0){
cprintf(cb, "%*s<%s>\n", level1, "", xml_name(x0));
xml_diff_context(cb, x0, level1);
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
Expand All @@ -995,7 +1026,7 @@ xml_diff2cbuf(cbuf *cb,
eq = xml_cmp(x0c, x1c, 0, 0, NULL);
if (eq < 0){
if (nr==0 && skiptop==0){
cprintf(cb, "%*s<%s>\n", level1, "", xml_name(x0));
xml_diff_context(cb, x0, level1);
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
Expand All @@ -1006,7 +1037,7 @@ xml_diff2cbuf(cbuf *cb,
}
else if (eq > 0){
if (nr==0 && skiptop==0){
cprintf(cb, "%*s<%s>\n", level1, "", xml_name(x1));
xml_diff_context(cb, x1, level1);
xml_diff_keys(cb, x1, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
Expand All @@ -1023,7 +1054,7 @@ xml_diff2cbuf(cbuf *cb,
yc1 = xml_spec(x1c);
if (yc0 && yc1 && yc0 != yc1){ /* choice */
if (nr==0 && skiptop==0){
cprintf(cb, "%*s<%s>\n", level1, "", xml_name(x0));
xml_diff_context(cb, x0, level1);
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
Expand All @@ -1041,7 +1072,7 @@ xml_diff2cbuf(cbuf *cb,
else if (b0 == NULL || b1 == NULL
|| strcmp(b0, b1) != 0){
if (nr==0 && skiptop==0){
cprintf(cb, "%*s<%s>\n", level1, "", xml_name(x0));
xml_diff_context(cb, x0, level1);
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT);
nr++;
}
Expand Down
5 changes: 3 additions & 2 deletions test/test_cli_diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ expectpart "$($clixon_cli -1 -f $cfg set top section x table parameter d value 9
new "check candidate"
expectpart "$($clixon_cli -1 -f $cfg show config candidate)" 0 "^<top xmlns=\"urn:example:clixon\"><section><name>x</name><table><parameter><name>b</name><value>42</value></parameter><parameter><name>c</name><value>72</value></parameter><parameter><name>d</name><value>99</value></parameter></table></section></top>$"

new "check compare xml"
expectpart "$($clixon_cli -1 -f $cfg show compare xml)" 0 "<table>" "^\-\ *<parameter>" "^+\ *<parameter>" "^\-\ *<name>a</name>" "^+\ *<name>c</name>" --not-- "^+\ *<name>a</name>" "^\-\ *<name>c</name>"
new "check compare xml b"
echo "$clixon_cli -1 -f $cfg show compare xml"
expectpart "$($clixon_cli -1 -f $cfg show compare xml)" 0 "<table xmlns=\"urn:example:clixon\">" "^\-\ *<parameter>" "^+\ *<parameter>" "^\-\ *<name>a</name>" "^+\ *<name>c</name>" --not-- "^+\ *<name>a</name>" "^\-\ *<name>c</name>"

new "check compare text"
expectpart "$($clixon_cli -1 -f $cfg show compare text)" 0 "^\ *table {" "^\-\ *parameter a {" "^+\ *parameter c {" "^\-\ *value 98;" "^+\ *value 99;"
Expand Down

0 comments on commit 0a72432

Please sign in to comment.