Conversation
|
You'll need to look into the submission guidelines regarding commit formatting, etc. |
|
I will rebase with a proper commit message once I'm satisfied. |
|
The shunit2 test is broken, does not fail if one of the subtests fails, because exit code 1 is not propagated. In tests/shunit2/tests.sh: should be: See #21 |
c1e751f to
075d2cb
Compare
92f0747 to
bf0a598
Compare
bf0a598 to
a84cbcb
Compare
shunit2 test with failing subtest incorrectly produced:
Start 2: shunit2
2/2 Test openwrt#2: shunit2 .......................... Passed 52.70 sec
100% tests passed, 0 tests failed out of 2
now correctly produces:
Start 2: shunit2
2/2 Test openwrt#2: shunit2 ..........................***Failed 53.68 sec
#
# Performing tests
#
...
test_get_option
ASSERT:expected:<badval> but was:<val>
test_get_option_multiline
...
#
# Test report
#
tests passed: 111 99%
tests failed: 1 1%
tests skipped: 0 0%
tests total: 112 100%
50% tests passed, 1 tests failed out of 2
Total Test time (real) = 59.67 sec
The following tests FAILED:
2 - shunit2 (Failed)
Errors while running CTest
make: *** [Makefile:74: test] Error 8
make: Leaving directory '/home/user/repos/uci/build'
Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
Comment lines before an entry, and the comment at the end of an entry
are considered to be associated with that entry.
Example:
# this comment line is associated with section2
# this comment line is associated with section2
config type section2 # this comment is associated with section 2
# this comment line is associated with opt
# this comment line is associated with opt
option opt 'val' # this comment is associated with opt
# this comment line is not associated with any entry
Added code to optionally, for each entry in the configuration file:
- parse the associated comments, and store them in buffer 'commentbuf'
in the parse context.
- empty commentbuf after the associated entry has been processed.
Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
56181fc to
0cb0626
Compare
|
This is ready for review. |
|
I've just locally built, for 25.12.2, x86_64 target:
This produced the following apk files that are all needed: Installed these on my system, restarted service rpcd, added comments to |
|
I would like to enable comment preservation by default, but I'm cautious, for the following reasons:
But I'm open to enabling comment preservation by default, and optionally adding flag UCI_FLAG_STRIP_COMMENTS instead of UCI_FLAG_COMMENTS, and a command line option to strip comments instead of option '-k'. |
|
I've decided to enable preservation of comments by default. The use cases against disabling it by default (memory usage and some tests that may need to be adapted) are very unlikely a problem. It can still be disabled. |
c5eae7b to
f1c8b3c
Compare
With option '-k': - uci command 'import' preserves comments of unchanged configuration entries, but does not import comments - uci command 'export' exports entries with their associated comments - uci command 'commit' preserves comments of unchanged configuration entries when commiting changes with uci commands 'add', 'delete', 'set', 'add_list', and/or 'del_list'. - preserved comment lines are auto-indented Limitation: - comments at the end of the file are not preserved, because they are not associated with an entry Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
Added shunit2 tests for option '-k': keep comments for unchanged entries. Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
With option '-k': - uci command 'import' now also imports comments associated with imported entries - imported comments are auto-indented Limitation: - comment lines at the end of the file are not imported Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
Test that 'import' with option '-k' also imports comments associated with imported entries. Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
- `uci -k get '<config>.<section>' '#'` shows the section comment - `uci -k get '<config>.<section>.<option> '#'` shows the option comment - `uci -k set '<config>.<section>=<value>' '#<comment>'` sets the section value and comment - `uci -k set '<config>.<section>.option=<value>' '#<comment>'` sets the option value and comment - `uci -k add_list '<config>.<section>.option=<value> '#<comment>'` adds a list entry with value and comment - `uci -k changes` also shows comments - `uci -k show` does not show comments - `uci -k batch` supports the above commands - comments are auto-indented if set or added Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
- `uci -k get '<config>.<section>' '#'` - `uci -k get '<config>.<section>.<option> '#'` - `uci -k set '<config>.<section>=<value>' '#<comment>'` - `uci -k set '<config>.<section>.option=<value>' '#<comment>'` - `uci -k add_list '<config>.<section>.option=<value> '#<comment>'` - `uci -k changes` - `uci -k show` - `uci -k batch` Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
Comments are now preserved by default by uci and libuci. There are a lot of programs that would otherwise need to be modified to explicitly set a flag to preserve comments. - replaced UCI_FLAG_COMMENTS by UCI_FLAG_NO_COMMENTS (to be able to explicitly request the old behavior, if you really want to strip comments for some reason). - replaced option -k (keep comments) with option -D (don't keep comments) - also fixed a pre-existing memory leak in cli.c:main() on invalid option. Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
f1c8b3c to
db733c0
Compare
This pull request implements preservation of comments in configuration files.
Comment lines before an entry, and the comment at the end of an entry are considered to be associated with that entry.
Example:
Wih option
-D, uci works as before and strips comments. The following commands have enhanced behaviour:uci importpreserves comments of unchanged configuration entries, and imports entries with their associated commentsuci exportexports entries with their associated commentsuci 'commitpreserves comments of unchanged configuration entries when committing changes with uci commands 'add', 'delete', 'set', 'add_list', and/or 'del_list'.uci get '<config>.<section>' '#'shows the section commentuci get '<config>.<section>.<option> '#'shows the option commentuci set '<config>.<section>=<value>' '<comment>'sets the section value and commentuci set '<config>.<section>.option=<value>' '<comment>'sets the option value and commentuci add_list '<config>.<section>.option=<value> '<comment>'adds a list entry with value and commentuci changesalso shows commentsuci showdoes not show commentsuci batchsupports the above commandsFeatures:
I've added lots of shunit2 tests to verify the implementation.
An example of a result: the above example after and option 'opt2' has been added: