8000 Map Commands instead of using them as a slice by 0xmichalis · Pull Request #10914 · moby/moby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Map Commands instead of using them as a slice #10914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2015
Merged

Map Commands instead of using them as a slice #10914

merged 1 commit into from
Feb 20, 2015

Conversation

0xmichalis
Copy link
Contributor

The most obvious use case is when one wants to make sure as fast
as possible that a command is a valid Dockerfile command.

@GordonTheTurtle
Copy link

Can you please sign your commits following these rules:

https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work

The easiest way to do this is to amend the last commit:

$ git clone -b "map-commands" git@github.com:kargakis/docker.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f

This will update the existing PR, so you do not need to open a new one.

@0xmichalis
Copy link
Contributor Author

@GordonTheTurtle done!

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

@Kargakis I'm not sure what this PR does. You setup a map but then never actually modified any code to use it as a map.

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

@Kargakis please revert the change in docker_cli_build_test.go - we still need to use the old gofmt syntax on those loops for a while.

@0xmichalis
Copy link
Contributor Author

@duglin

I'm not sure what this PR does.

The modification helps anyone do the following:

import github.com/docker/docker/builder/command

// somewhere in the code
_, validDockerfileCmd := command.Commands[myCmd]; !validDockerfileCmd {
// it's not valid 
}

You setup a map but then never actually modified any code to use it as a map.

In Docker, you just use that slice in the test I modified to be used as a map and nowhere else. If I am missing it somewhere, please point it out so I can fix it.

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

@Kargakis yes I understand how a map can help speed things up, but my points is that if we never actually do that then I'm not sure I see the point in setting up a map - especially when our one and only use of that structure is to loop over it instead of a map-lookup. If you look at https://github.com/docker/docker/blob/master/builder/evaluator.go#L61 and https://github.com/docker/docker/blob/master/builder/evaluator.go#L284 you'll see that we do use a map for the exact reason you say.

@0xmichalis
Copy link
Contributor Author

yes I understand how a map can help speed things up, but my points is that if we never actually do that then I'm not sure I see the point in setting up a map - especially when our one and only use of that structure is to loop over it instead of a map-lookup. If you look at https://github.com/docker/docker/blob/master/builder/evaluator.go#L61 and https://github.com/docker/docker/blob/master/builder/evaluator.go#L284 you'll see that we do use a map for the exact reason you say.

Yep, I have seen that map, but it's unexported so it's of no use to people outside Docker. The same pr that made it unexported, added the slice in question.

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

yes and it was created because we needed to "loop" over the commands.

@0xmichalis
Copy link
Contributor Author

yes and it was created because we needed to "loop" over the commands.

But you don't actually use it except that test. Btw, you can loop over a map as well (even though a Go map returns the keys/values in random)

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

right but that's the only reason it was created. By point is that if we had some other use for it (as a map) then I think this change is worth it.

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

let me clarify.... I'm not -1'ing this. I was just pointing out that this change doesn't really help anything within Docker right now - meaning its not addressing a pain-point. I understand you're suggesting we do it because we may need a quick look-up at some point in the future. I guess you could say I'm +0 on it.

@0xmichalis
Copy link
Contributor Author

let me clarify.... I'm not -1'ing this. I was just pointing out that this change doesn't really help anything within Docker right now - meaning its not addressing a pain-point. I understand you're suggesting we do it because we may need a quick look-up at some point in the future. I guess you could say I'm +0 on it.

I made this pr because on OpenShift I am working on manipulating Docker files, at some point I want to verify that a Docker command is valid and the best way to do this is to have an operation from the Docker project that will do that for me instead of manually creating the map and keeping it on sync every time something changes upstream.

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

Ah, I didn't realize that - thanks a ton for the info. In that case, can you fix the jenkins issue? #10914 (comment)

The most obvious use case is when one wants to make sure as fast
as possible that a command is a valid Dockerfile command.

Signed-off-by: kargakis <kargakis@users.noreply.github.com>
@0xmichalis
Copy link
Contributor Author

can you fix the jenkins issue?

Yup, fixed

@duglin
Copy link
Contributor
duglin commented Feb 20, 2015

LGTM

1 similar comment
@tiborvass
Copy link
Contributor

LGTM

tiborvass added a commit that referenced this pull request Feb 20, 2015
Map Commands instead of using them as a slice
@tiborvass tiborvass merged commit c5aca86 into moby:master Feb 20, 2015
@0xmichalis 0xmichalis deleted the map-commands branch February 21, 2015 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0