{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/38053473","id":38053473,"diff_hunk":"@@ -26,21 +46,74 @@ type ContainersConfig struct {\n \tFilters string\n }\n \n+// listContext is the daemon generated filtering to iterate over containers.\n+// This is created based on the user specification.\n+type listContext struct {\n+\tidx             int\n+\tnames           map[string][]string\n+\tfilters         filters.Args\n+\texitAllowed     []int\n+\tbeforeContainer *Container\n+\tsinceContainer  *Container\n+\t*ContainersConfig\n+}\n+\n+// Containers returns the list of containers to show given the user's filtering.\n func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container, error) {\n-\tvar (\n-\t\tfoundBefore bool\n-\t\tdisplayed   int\n-\t\tall         = config.All\n-\t\tn           = config.Limit\n-\t\tpsFilters   filters.Args\n-\t\tfiltExited  []int\n-\t)\n+\treturn daemon.reduceContainers(config, daemon.transformContainer)\n+}\n+\n+// reduceContainer parses the user filtering and generates the list of containers to return based on a reducer.\n+func (daemon *Daemon) reduceContainers(config *ContainersConfig, reducer containerReducer) ([]*types.Container, error) {\n \tcontainers := []*types.Container{}\n \n+\tctx, err := daemon.foldFilter(config)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tfor _, container := range daemon.List() {\n+\t\tt, err := daemon.reducePsContainer(container, ctx, reducer)\n+\t\tif err != nil {\n+\t\t\tif err != errStopIteration {\n+\t\t\t\treturn nil, err\n+\t\t\t}\n+\t\t\tbreak\n+\t\t}\n+\t\tif t != nil {\n+\t\t\tcontainers = append(containers, t)\n+\t\t\tctx.idx++\n+\t\t}\n+\t}\n+\treturn containers, nil\n+}\n+\n+// reducePsContainer is the basic representation for a container as expected by the ps command.\n+func (daemon *Daemon) reducePsContainer(container *Container, ctx *listContext, reducer containerReducer) (*types.Container, error) {\n+\tcontainer.Lock()\n+\tdefer container.Unlock()\n+\n+\t// Container filtering\n+\taction := includeContainerInList(container, ctx)\n+\tswitch action {\n+\tcase excludeContainer:\n+\t\treturn nil, nil\n+\tcase stopIteration:\n+\t\treturn nil, errStopIteration\n+\t}\n+\n+\t// Model transformation","path":"daemon/list.go","position":100,"original_position":100,"commit_id":"6614e79dd8ffddf64c89f2914b25b38c903e4902","original_commit_id":"6614e79dd8ffddf64c89f2914b25b38c903e4902","user":{"login":"LK4D4","id":101445,"avatar_url":"https://avatars.githubusercontent.com/u/101445?v=3","gravatar_id":"","url":"https://api.github.com/users/LK4D4","html_url":"https://github.com/LK4D4","followers_url":"https://api.github.com/users/LK4D4/followers","following_url":"https://api.github.com/users/LK4D4/following{/other_user}","gists_url":"https://api.github.com/users/LK4D4/gists{/gist_id}","starred_url":"https://api.github.com/users/LK4D4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LK4D4/subscriptions","organizations_url":"https://api.github.com/users/LK4D4/orgs","repos_url":"https://api.github.com/users/LK4D4/repos","events_url":"https://api.github.com/users/LK4D4/events{/privacy}","received_events_url":"https://api.github.com/users/LK4D4/received_events","type":"User","site_admin":false},"body":"this comment is to hard for me :) Something like Paris Hilton + Optimus Prime?","created_at":"2015-08-27T01:04:33Z","updated_at":"2015-08-27T01:04:33Z","html_url":"https://github.com/docker/docker/pull/15845#discussion_r38053473","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/15845","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/38053473"},"html":{"href":"https://github.com/docker/docker/pull/15845#discussion_r38053473"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/15845"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/15845","id":43375497,"html_url":"https://github.com/docker/docker/pull/15845","diff_url":"https://github.com/docker/docker/pull/15845.diff","patch_url":"https://github.com/docker/docker/pull/15845.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/15845","number":15845,"state":"open","locked":false,"title":"Refactor daemon container list.","user":{"login":"calavera","id":1050,"avatar_url":"https://avatars.githubusercontent.com/u/1050?v=3","gravatar_id":"","url":"https://api.github.com/users/calavera","html_url":"https://github.com/calavera","followers_url":"https://api.github.com/users/calavera/followers","following_url":"https://api.github.com/users/calavera/following{/other_user}","gists_url":"https://api.github.com/users/calavera/gists{/gist_id}","starred_url":"https://api.github.com/users/calavera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calavera/subscriptions","organizations_url":"https://api.github.com/users/calavera/orgs","repos_url":"https://api.github.com/users/calavera/repos","events_url":"https://api.github.com/users/calavera/events{/privacy}","received_events_url":"https://api.github.com/users/calavera/received_events","type":"User","site_admin":false},"body":"Separate container iteration, filtering and reducing.\nThis will make easier in the future to improve the implementation of\ndocker ps as we know it.\n\nThe end goal is to unify the objects returned by the api for docker ps\nand docker inspect, leaving all docker ps transformations to the client.\n\nSigned-off-by: David Calavera <david.calavera@gmail.com>","created_at":"2015-08-26T08:20:17Z","updated_at":"2015-08-27T01:04:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"37b364f65f36edaf5bb144c353e83883329a9a29","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/docker/pulls/15845/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/15845/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/15845/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/6614e79dd8ffddf64c89f2914b25b38c903e4902","head":{"label":"calavera:refactor_daemon_list","ref":"refactor_daemon_list","sha":"6614e79dd8ffddf64c89f2914b25b38c903e4902","user":{"login":"calavera","id":1050,"avatar_url":"https://avatars.githubusercontent.com/u/1050?v=3","gravatar_id":"","url":"https://api.github.com/users/calavera","html_url":"https://github.com/calavera","followers_url":"https://api.github.com/users/calavera/followers","following_url":"https://api.github.com/users/calavera/following{/other_user}","gists_url":"https://api.github.com/users/calavera/gists{/gist_id}","starred_url":"https://api.github.com/users/calavera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calavera/subscriptions","organizations_url":"https://api.github.com/users/calavera/orgs","repos_url":"https://api.github.com/users/calavera/repos","events_url":"https://api.github.com/users/calavera/events{/privacy}","received_events_url":"https://api.github.com/users/calavera/received_events","type":"User","site_admin":false},"repo":{"id":11697698,"name":"docker","full_name":"calavera/docker","owner":{"login":"calavera","id":1050,"avatar_url":"https://avatars.githubusercontent.com/u/1050?v=3","gravatar_id":"","url":"https://api.github.com/users/calavera","html_url":"https://github.com/calavera","followers_url":"https://api.github.com/users/calavera/followers","following_url":"https://api.github.com/users/calavera/following{/other_user}","gists_url":"https://api.github.com/users/calavera/gists{/gist_id}","starred_url":"https://api.github.com/users/calavera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calavera/subscriptions","organizations_url":"https://api.github.com/users/calavera/orgs","repos_url":"https://api.github.com/users/calavera/repos","events_url":"https://api.github.com/users/calavera/events{/privacy}","received_events_url":"https://api.github.com/users/calavera/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/calavera/docker","description":"Docker - the Linux container runtime","fork":true,"url":"https://api.github.com/repos/calavera/docker","forks_url":"https://api.github.com/repos/calavera/docker/forks","keys_url":"https://api.github.com/repos/calavera/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/calavera/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/calavera/docker/teams","hooks_url":"https://api.github.com/repos/calavera/docker/hooks","issue_events_url":"https://api.github.com/repos/calavera/docker/issues/events{/number}","events_url":"https://api.github.com/repos/calavera/docker/events","assignees_url":"https://api.github.com/repos/calavera/docker/assignees{/user}","branches_url":"https://api.github.com/repos/calavera/docker/branches{/branch}","tags_url":"https://api.github.com/repos/calavera/docker/tags","blobs_url":"https://api.github.com/repos/calavera/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/calavera/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/calavera/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/calavera/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/calavera/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/calavera/docker/languages","stargazers_url":"https://api.github.com/repos/calavera/docker/stargazers","contributors_url":"https://api.github.com/repos/calavera/docker/contributors","subscribers_url":"https://api.github.com/repos/calavera/docker/subscribers","subscription_url":"https://api.github.com/repos/calavera/docker/subscription","commits_url":"https://api.github.com/repos/calavera/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/calavera/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/calavera/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/calavera/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/calavera/docker/contents/{+path}","compare_url":"https://api.github.com/repos/calavera/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/calavera/docker/merges","archive_url":"https://api.github.com/repos/calavera/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/calavera/docker/downloads","issues_url":"https://api.github.com/repos/calavera/docker/issues{/number}","pulls_url":"https://api.github.com/repos/calavera/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/calavera/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/calavera/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/calavera/docker/labels{/name}","releases_url":"https://api.github.com/repos/calavera/docker/releases{/id}","created_at":"2013-07-27T00:49:52Z","updated_at":"2014-07-24T21:22:23Z","pushed_at":"2015-08-26T17:42:21Z","git_url":"git://github.com/calavera/docker.git","ssh_url":"git@github.com:calavera/docker.git","clone_url":"https://github.com/calavera/docker.git","svn_url":"https://github.com/calavera/docker","homepage":"http://docker.io","size":69958,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"8720f71b522fd0a7abbd47374b27e11d7f1beb7d","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","created_at":"2013-01-18T18:10:57Z","updated_at":"2015-08-27T00:00:07Z","pushed_at":"2015-08-27T00:32:37Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":246314,"stargazers_count":24324,"watchers_count":24324,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6230,"mirror_url":null,"open_issues_count":1033,"forks":6230,"open_issues":1033,"watchers":24324,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/15845"},"html":{"href":"https://github.com/docker/docker/pull/15845"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/15845"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/15845/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/15845/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/15845/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/6614e79dd8ffddf64c89f2914b25b38c903e4902"}}}}