-
Notifications
You must be signed in to change notification settings - Fork 123
kdb-ls-depth: Implement depth parameter for kdb ls #1345
Conversation
@tom-wa can you check if you like the behavior please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some shell recorder tests. (Also from basic functionality)
src/tools/kdb/ls.cpp
Outdated
@@ -21,12 +21,9 @@ LsCommand::LsCommand () : kdb (root) | |||
{ | |||
} | |||
|
|||
int LsCommand::execute (Cmdline const & cl) | |||
int LsCommand::execute (const Cmdline & cl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep it <obj> const & cl
, otherwise we have a mix of style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used const before the class type all the time, also in kdb complete. Should i change it too in there?
and what about something like const Key key
(without &), should it also be Key const key
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used const before the class type all the time, also in kdb complete. Should i change it too in there?
It is not urgent, please not within this PR. Maybe together with #1328 or even seperately.
and what about something like const Key key (without &), should it also be Key const key?
It actually does not make much sense to do that, at least not like you did it. It will increase/decrease the ref counter unnecessarily.
Also const int
as formal parameter is of little use, the value is copied anyway, why protect it from writing to it?
The position of const seems to be inconsistent at some other places, e.g. const char *
, maybe one of the llvm tools can change it automatically?
Btw. it is good that you use const
so frequently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok i have to admit i haven't thought about the ref counter of the Keys yet. You are right in that cases it probably makes more sense to pass them around by reference if applicable to avoid that.
But i meant the general cases where i pass a const object around, for example a string. Should i use const string foo
or string const foo
in the future?
Doesn't the const int indicate that this integer will not change in this method? I've seen it more from the perspective of immutability. If i want to express that some parameter should not change in a method, i mark it as const, regardless of wheter its getting passed by copy so modifications wouldn't make a difference outside the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, its a very strict sense of immutability, which is a bit unusual, e.g. https://isocpp.org/wiki/faq/const-correctness does not recommend it. It is a bit misleading from the interface perspective. But I am okay with it if you use it. (For APIs (like libtools) we should check if all compilers are ABI compatible when const
needs to be removed).
About the placement of const
: Anything is okay as long as it is used consistently. It is not so often used in the code base, so even if llvm cannot do it, you can also change it by hand if you prefer one over the other. Otherwise simply use, what is already used.
… improve reference const style ElektraInitiative#1345
|
||
< kdb mount $File $Mountpoint $Storage | ||
|
||
< kdb set $Mountpoint/test bla |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can and should use the tutorial style syntax or did you have any problems with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh you've already seen it, i was still messing around with the shell recorder. What do you mean with tutorial syntax? I haven't found anything about that in the Readme. Do you mean i should write a tutorial how to use kdb ls and then use this tutorial wrapper?
I'm not really sure how the shellrecorder has to be used correctly yet. I've created my esr script which contains some commands that will be done on a temporary mountpoint to avoid polluting the host system. I think the extra mount was totally unnecessary as it seems the shell recorder already takes care about that, so i removed it. Also i moved the mountpoint to user where everyone can write to without having root rights.
Then i execute this script via the shellrecorder and grab the protocol it produces (kdb_lsprotocol). After checking if the output of each command was as expected in the protocol, the test can be executed by running the shellrecorder script again and comparing the output to the stored protocol file, which should match (and did match when i execute the test directly via ./shell_recorder.sh kdb_ls.esr kdb_lsprotocol
). This way we can prevent regression bugs in future versions.
But does the test execution (make_run) even compare the output against the protocol file? Inspecting the CMakeFile made me doubt that. Do i have to copy the expected output back in the script file (kdb_ls.esr) and check it everywhere with the STDOUT command? That would be much more cumbersome than simply comparing against the protocol.
And in all the .esr files it uses the kdb commands directly, but if i don't use e.g. kdb ls instead of just ls, it will fail as it actually tries to use my system's ls command and not the one of kdb.
… improve reference const style ElektraInitiative#1345
checked out the tutorial syntax and used the example section in the documentation of kdb-ls to implement the test cases, so that they serve as examples for users at the same time. The syntax looks not perfect, but still a win/win i think. |
i can't get the short options to work
|
if we are fine with that, we can merge this i think |
jenkins build fast please |
Looks good, thank you. But seems like we have a conflict here 😢 please rebase. |
Sorry, I should not have resolved the conflict 😳. I just wanted to try GitHub’s online editor. Anyway, as far as I can tell, rebasing should work the same as always. I already rebased the PR locally. Sorry again, if commit cc0afe6 caused any problems. |
Seems like you merged master into this branch? Merging now would work. If rebasing can be easily done I would prefer rebasing nevertheless. @e1528532 Simply readd "ready to merge" if done. |
Yes, I assume commit cc0afe6 is the result of the command
If you want, I can just push a rebased version of this pull request. |
{ | ||
const int offset = root.getBaseName ().empty () || shallShowNextLevel (cl.arguments[0]) ? 1 : 0; | ||
const int relativeMinDepth = rootDepth + cl.minDepth + offset; | ||
const int relativeMaxDepth = std::max (cl.maxDepth, rootDepth + cl.maxDepth + offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this line may cause an integer overflow:
../src/tools/kdb/ls.cpp:76:64: runtime error: signed integer overflow: 1 + 2147483647 cannot be represented in type 'int'
SUMMARY: AddressSanitizer: undefined-behavior ../src/tools/kdb/ls.cpp:76:64
.
Purpose
Like said, the purpose of this PR is to provide a depth parameter for kdb ls, like we have in kdb complete as requested in #1237
Checklist
@markus2330 please review my pull request, and keep my comments in #1237 in mind.