Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

kdb-ls-depth: Implement depth parameter for kdb ls #1345

Closed
wants to merge 8 commits into from

Conversation

e1528532
Copy link
Contributor

@e1528532 e1528532 commented Feb 15, 2017

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

  • commit messages are fine (with references to issues)
  • I ran all tests and everything went fine
  • I added unit tests
  • affected documentation is fixed
  • I added code comments, logging, and assertions
  • meta data is updated (e.g. README.md of plugins)

@markus2330 please review my pull request, and keep my comments in #1237 in mind.

@markus2330
Copy link
Contributor

markus2330 commented Feb 15, 2017

@tom-wa can you check if you like the behavior please?

Copy link
Contributor

@markus2330 markus2330 left a 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)

@@ -21,12 +21,9 @@ LsCommand::LsCommand () : kdb (root)
{
}

int LsCommand::execute (Cmdline const & cl)
int LsCommand::execute (const Cmdline & cl)
Copy link
Contributor

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.

Copy link
Contributor Author

@e1528532 e1528532 Feb 15, 2017

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

e1528532 added a commit to e1528532/libelektra that referenced this pull request Feb 16, 2017
e1528532 added a commit to e1528532/libelektra that referenced this pull request Feb 16, 2017

< kdb mount $File $Mountpoint $Storage

< kdb set $Mountpoint/test bla
Copy link
Contributor

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?

Copy link
Contributor Author

@e1528532 e1528532 Feb 16, 2017

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.

e1528532 added a commit to e1528532/libelektra that referenced this pull request Feb 17, 2017
@e1528532 e1528532 mentioned this pull request Feb 21, 2017
27 tasks
e1528532 added a commit to e1528532/libelektra that referenced this pull request Feb 23, 2017
@e1528532
Copy link
Contributor Author

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.

@tom-wa
Copy link
Contributor

tom-wa commented May 9, 2017

i can't get the short options to work
the only thing thats a little bit annoying is the difference between having and not having a / at the end

kdb ls system/info/elektra --max-depth=1
kdb ls system/info/elektra/ --max-depth=1
system/info/elektra/constants
system/info/elektra/uname

@e1528532 e1528532 mentioned this pull request Jun 15, 2017
6 tasks
@e1528532
Copy link
Contributor Author

fixed the short option argument issue, depends on PR #1510 now.
that behavior with the slash at the end is intended as explained in #1237 to be consistent with how min and max depth work with kdb complete. If we want that consistency.

@e1528532
Copy link
Contributor Author

if we are fine with that, we can merge this i think

@markus2330
Copy link
Contributor

jenkins build fast please

@markus2330
Copy link
Contributor

Looks good, thank you. But seems like we have a conflict here 😢 please rebase.

@sanssecours
Copy link
Member

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.

@markus2330
Copy link
Contributor

markus2330 commented Jul 26, 2017

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.

@sanssecours
Copy link
Member

Seems like you merged master into this branch?

Yes, I assume commit cc0afe6 is the result of the command git merge master.

If rebasing can be easily done I would prefer rebasing nevertheless.

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);
Copy link
Member

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

.

@sanssecours sanssecours mentioned this pull request Jul 27, 2017
2 tasks
markus2330 pushed a commit that referenced this pull request Jul 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants