{"action":"created","comment":{"url":"https://api.github.com/repos/src-d/go-git/pulls/comments/86252089","pull_request_review_id":6919444,"id":86252089,"diff_hunk":"@@ -0,0 +1,333 @@\n+package memory\n+\n+import (\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\t\"gopkg.in/src-d/go-git.v4/utils/fs\"\n+)\n+\n+const separator = '/'\n+\n+// Memory a very convenient filesystem based on memory files\n+type Memory struct {\n+\tbase string\n+\ts    *storage\n+}\n+\n+//New returns a new Memory filesystem\n+func New() *Memory {\n+\treturn &Memory{\n+\t\tbase: \"/\",\n+\t\ts:    &storage{make(map[string]*file, 0)},\n+\t}\n+}\n+\n+func (fs *Memory) Create(filename string) (fs.File, error) {\n+\treturn fs.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)\n+}\n+\n+func (fs *Memory) Open(filename string) (fs.File, error) {\n+\treturn fs.OpenFile(filename, os.O_RDONLY, 0)\n+}\n+\n+func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (fs.File, error) {\n+\tfullpath := fs.Join(fs.base, filename)\n+\tf, ok := fs.s.files[fullpath]\n+\tif !ok && flag&os.O_CREATE == 0 {\n+\t\treturn nil, os.ErrNotExist\n+\t}\n+\n+\tif f == nil {\n+\t\tfs.s.files[fullpath] = newFile(fs.base, fullpath, flag)\n+\t\treturn fs.s.files[fullpath], nil\n+\t}\n+\n+\tn := newFile(fs.base, fullpath, flag)\n+\tn.c = f.c\n+\n+\tif flag&os.O_APPEND != 0 {\n+\t\tn.p = n.c.size\n+\t}\n+\n+\tif flag&os.O_TRUNC != 0 {\n+\t\tn.c.Truncate()\n+\t}\n+\n+\treturn n, nil\n+}\n+\n+func (fs *Memory) Stat(filename string) (fs.FileInfo, error) {\n+\tfullpath := fs.Join(fs.base, filename)\n+\n+\tif _, ok := fs.s.files[filename]; ok {\n+\t\treturn newFileInfo(fs.base, fullpath, fs.s.files[filename].c.size), nil\n+\t}\n+\n+\tinfo, err := fs.ReadDir(filename)\n+\tif err == nil && len(info) != 0 {\n+\t\treturn newFileInfo(fs.base, fullpath, int64(len(info))), nil\n+\t}\n+\n+\treturn nil, os.ErrNotExist\n+}\n+\n+func (fs *Memory) ReadDir(base string) (entries []fs.FileInfo, err error) {\n+\tbase = fs.Join(fs.base, base)\n+\n+\tdirs := make(map[string]bool, 0)\n+\tfor fullpath, f := range fs.s.files {\n+\t\tif !strings.HasPrefix(fullpath, base) {\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\tfullpath, _ = filepath.Rel(base, fullpath)\n+\t\tparts := strings.Split(fullpath, string(separator))\n+\n+\t\tif len(parts) != 1 {\n+\t\t\tdirs[parts[0]] = true\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\tentries = append(entries, newFileInfo(fs.base, fullpath, f.c.size))\n+\t}\n+\n+\tfor path := range dirs {\n+\t\tentries = append(entries, &fileInfo{\n+\t\t\tname:  path,\n+\t\t\tisDir: true,\n+\t\t})\n+\t}\n+\n+\treturn\n+}\n+\n+func (fs *Memory) TempFile(dir, prefix string) (fs.File, error) {\n+\tfilename := fmt.Sprintf(\"%s_%d\", prefix, time.Now().UnixNano())\n+\tfullpath := fs.Join(fs.base, dir, filename)\n+\treturn fs.Create(fullpath)","path":"utils/fs/memory/memory.go","position":113,"original_position":113,"commit_id":"df8e4887d905305cf8b61ea4d28093233e84cf06","original_commit_id":"df8e4887d905305cf8b61ea4d28093233e84cf06","user":{"login":"mcuadros","id":1573114,"avatar_url":"https://avatars.githubusercontent.com/u/1573114?v=3","gravatar_id":"","url":"https://api.github.com/users/mcuadros","html_url":"https://github.com/mcuadros","followers_url":"https://api.github.com/users/mcuadros/followers","following_url":"https://api.github.com/users/mcuadros/following{/other_user}","gists_url":"https://api.github.com/users/mcuadros/gists{/gist_id}","starred_url":"https://api.github.com/users/mcuadros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcuadros/subscriptions","organizations_url":"https://api.github.com/users/mcuadros/orgs","repos_url":"https://api.github.com/users/mcuadros/repos","events_url":"https://api.github.com/users/mcuadros/events{/privacy}","received_events_url":"https://api.github.com/users/mcuadros/received_events","type":"User","site_admin":false},"body":"I did another solution","created_at":"2016-11-02T21:58:25Z","updated_at":"2016-11-02T21:58:25Z","html_url":"https://github.com/src-d/go-git/pull/108#discussion_r86252089","pull_request_url":"https://api.github.com/repos/src-d/go-git/pulls/108","_links":{"self":{"href":"https://api.github.com/repos/src-d/go-git/pulls/comments/86252089"},"html":{"href":"https://github.com/src-d/go-git/pull/108#discussion_r86252089"},"pull_request":{"href":"https://api.github.com/repos/src-d/go-git/pulls/108"}}},"pull_request":{"url":"https://api.github.com/repos/src-d/go-git/pulls/108","id":91897100,"html_url":"https://github.com/src-d/go-git/pull/108","diff_url":"https://github.com/src-d/go-git/pull/108.diff","patch_url":"https://github.com/src-d/go-git/pull/108.patch","issue_url":"https://api.github.com/repos/src-d/go-git/issues/108","number":108,"state":"open","locked":false,"title":"utils: fs, new memory filesystem\t","user":{"login":"mcuadros","id":1573114,"avatar_url":"https://avatars.githubusercontent.com/u/1573114?v=3","gravatar_id":"","url":"https://api.github.com/users/mcuadros","html_url":"https://github.com/mcuadros","followers_url":"https://api.github.com/users/mcuadros/followers","following_url":"https://api.github.com/users/mcuadros/following{/other_user}","gists_url":"https://api.github.com/users/mcuadros/gists{/gist_id}","starred_url":"https://api.github.com/users/mcuadros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcuadros/subscriptions","organizations_url":"https://api.github.com/users/mcuadros/orgs","repos_url":"https://api.github.com/users/mcuadros/repos","events_url":"https://api.github.com/users/mcuadros/events{/privacy}","received_events_url":"https://api.github.com/users/mcuadros/received_events","type":"User","site_admin":false},"body":"This is a new `fs.Filesytem` based on memory.  take notice of is not thread-safe. \r\nAlso I renamed  os.NewOS` to `os.New`\r\n","created_at":"2016-11-02T02:00:22Z","updated_at":"2016-11-02T21:58:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8864cde6a8e39a8f2f6f45c2607a5a32bd2ee869","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/src-d/go-git/pulls/108/commits","review_comments_url":"https://api.github.com/repos/src-d/go-git/pulls/108/comments","review_comment_url":"https://api.github.com/repos/src-d/go-git/pulls/comments{/number}","comments_url":"https://api.github.com/repos/src-d/go-git/issues/108/comments","statuses_url":"https://api.github.com/repos/src-d/go-git/statuses/df8e4887d905305cf8b61ea4d28093233e84cf06","head":{"label":"mcuadros:fs-memory","ref":"fs-memory","sha":"df8e4887d905305cf8b61ea4d28093233e84cf06","user":{"login":"mcuadros","id":1573114,"avatar_url":"https://avatars.githubusercontent.com/u/1573114?v=3","gravatar_id":"","url":"https://api.github.com/users/mcuadros","html_url":"https://github.com/mcuadros","followers_url":"https://api.github.com/users/mcuadros/followers","following_url":"https://api.github.com/users/mcuadros/following{/other_user}","gists_url":"https://api.github.com/users/mcuadros/gists{/gist_id}","starred_url":"https://api.github.com/users/mcuadros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcuadros/subscriptions","organizations_url":"https://api.github.com/users/mcuadros/orgs","repos_url":"https://api.github.com/users/mcuadros/repos","events_url":"https://api.github.com/users/mcuadros/events{/privacy}","received_events_url":"https://api.github.com/users/mcuadros/received_events","type":"User","site_admin":false},"repo":{"id":71251853,"name":"go-git","full_name":"mcuadros/go-git","owner":{"login":"mcuadros","id":1573114,"avatar_url":"https://avatars.githubusercontent.com/u/1573114?v=3","gravatar_id":"","url":"https://api.github.com/users/mcuadros","html_url":"https://github.com/mcuadros","followers_url":"https://api.github.com/users/mcuadros/followers","following_url":"https://api.github.com/users/mcuadros/following{/other_user}","gists_url":"https://api.github.com/users/mcuadros/gists{/gist_id}","starred_url":"https://api.github.com/users/mcuadros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcuadros/subscriptions","organizations_url":"https://api.github.com/users/mcuadros/orgs","repos_url":"https://api.github.com/users/mcuadros/repos","events_url":"https://api.github.com/users/mcuadros/events{/privacy}","received_events_url":"https://api.github.com/users/mcuadros/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mcuadros/go-git","description":"A low level and highly extensible git client library","fork":true,"url":"https://api.github.com/repos/mcuadros/go-git","forks_url":"https://api.github.com/repos/mcuadros/go-git/forks","keys_url":"https://api.github.com/repos/mcuadros/go-git/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mcuadros/go-git/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mcuadros/go-git/teams","hooks_url":"https://api.github.com/repos/mcuadros/go-git/hooks","issue_events_url":"https://api.github.com/repos/mcuadros/go-git/issues/events{/number}","events_url":"https://api.github.com/repos/mcuadros/go-git/events","assignees_url":"https://api.github.com/repos/mcuadros/go-git/assignees{/user}","branches_url":"https://api.github.com/repos/mcuadros/go-git/branches{/branch}","tags_url":"https://api.github.com/repos/mcuadros/go-git/tags","blobs_url":"https://api.github.com/repos/mcuadros/go-git/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mcuadros/go-git/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mcuadros/go-git/git/refs{/sha}","trees_url":"https://api.github.com/repos/mcuadros/go-git/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mcuadros/go-git/statuses/{sha}","languages_url":"https://api.github.com/repos/mcuadros/go-git/languages","stargazers_url":"https://api.github.com/repos/mcuadros/go-git/stargazers","contributors_url":"https://api.github.com/repos/mcuadros/go-git/contributors","subscribers_url":"https://api.github.com/repos/mcuadros/go-git/subscribers","subscription_url":"https://api.github.com/repos/mcuadros/go-git/subscription","commits_url":"https://api.github.com/repos/mcuadros/go-git/commits{/sha}","git_commits_url":"https://api.github.com/repos/mcuadros/go-git/git/commits{/sha}","comments_url":"https://api.github.com/repos/mcuadros/go-git/comments{/number}","issue_comment_url":"https://api.github.com/repos/mcuadros/go-git/issues/comments{/number}","contents_url":"https://api.github.com/repos/mcuadros/go-git/contents/{+path}","compare_url":"https://api.github.com/repos/mcuadros/go-git/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mcuadros/go-git/merges","archive_url":"https://api.github.com/repos/mcuadros/go-git/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mcuadros/go-git/downloads","issues_url":"https://api.github.com/repos/mcuadros/go-git/issues{/number}","pulls_url":"https://api.github.com/repos/mcuadros/go-git/pulls{/number}","milestones_url":"https://api.github.com/repos/mcuadros/go-git/milestones{/number}","notifications_url":"https://api.github.com/repos/mcuadros/go-git/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mcuadros/go-git/labels{/name}","releases_url":"https://api.github.com/repos/mcuadros/go-git/releases{/id}","deployments_url":"https://api.github.com/repos/mcuadros/go-git/deployments","created_at":"2016-10-18T13:36:08Z","updated_at":"2016-10-18T13:36:09Z","pushed_at":"2016-11-02T01:57:51Z","git_url":"git://github.com/mcuadros/go-git.git","ssh_url":"git@github.com:mcuadros/go-git.git","clone_url":"https://github.com/mcuadros/go-git.git","svn_url":"https://github.com/mcuadros/go-git","homepage":"https://godoc.org/gopkg.in/src-d/go-git.v3","size":60169,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"src-d:master","ref":"master","sha":"1afef7e735cbd5950c32b3c320a8df89effcccab","user":{"login":"src-d","id":15128793,"avatar_url":"https://avatars.githubusercontent.com/u/15128793?v=3","gravatar_id":"","url":"https://api.github.com/users/src-d","html_url":"https://github.com/src-d","followers_url":"https://api.github.com/users/src-d/followers","following_url":"https://api.github.com/users/src-d/following{/other_user}","gists_url":"https://api.github.com/users/src-d/gists{/gist_id}","starred_url":"https://api.github.com/users/src-d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/src-d/subscriptions","organizations_url":"https://api.github.com/users/src-d/orgs","repos_url":"https://api.github.com/users/src-d/repos","events_url":"https://api.github.com/users/src-d/events{/privacy}","received_events_url":"https://api.github.com/users/src-d/received_events","type":"Organization","site_admin":false},"repo":{"id":44739044,"name":"go-git","full_name":"src-d/go-git","owner":{"login":"src-d","id":15128793,"avatar_url":"https://avatars.githubusercontent.com/u/15128793?v=3","gravatar_id":"","url":"https://api.github.com/users/src-d","html_url":"https://github.com/src-d","followers_url":"https://api.github.com/users/src-d/followers","following_url":"https://api.github.com/users/src-d/following{/other_user}","gists_url":"https://api.github.com/users/src-d/gists{/gist_id}","starred_url":"https://api.github.com/users/src-d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/src-d/subscriptions","organizations_url":"https://api.github.com/users/src-d/orgs","repos_url":"https://api.github.com/users/src-d/repos","events_url":"https://api.github.com/users/src-d/events{/privacy}","received_events_url":"https://api.github.com/users/src-d/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/src-d/go-git","description":"A low level and highly extensible git client library","fork":false,"url":"https://api.github.com/repos/src-d/go-git","forks_url":"https://api.github.com/repos/src-d/go-git/forks","keys_url":"https://api.github.com/repos/src-d/go-git/keys{/key_id}","collaborators_url":"https://api.github.com/repos/src-d/go-git/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/src-d/go-git/teams","hooks_url":"https://api.github.com/repos/src-d/go-git/hooks","issue_events_url":"https://api.github.com/repos/src-d/go-git/issues/events{/number}","events_url":"https://api.github.com/repos/src-d/go-git/events","assignees_url":"https://api.github.com/repos/src-d/go-git/assignees{/user}","branches_url":"https://api.github.com/repos/src-d/go-git/branches{/branch}","tags_url":"https://api.github.com/repos/src-d/go-git/tags","blobs_url":"https://api.github.com/repos/src-d/go-git/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/src-d/go-git/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/src-d/go-git/git/refs{/sha}","trees_url":"https://api.github.com/repos/src-d/go-git/git/trees{/sha}","statuses_url":"https://api.github.com/repos/src-d/go-git/statuses/{sha}","languages_url":"https://api.github.com/repos/src-d/go-git/languages","stargazers_url":"https://api.github.com/repos/src-d/go-git/stargazers","contributors_url":"https://api.github.com/repos/src-d/go-git/contributors","subscribers_url":"https://api.github.com/repos/src-d/go-git/subscribers","subscription_url":"https://api.github.com/repos/src-d/go-git/subscription","commits_url":"https://api.github.com/repos/src-d/go-git/commits{/sha}","git_commits_url":"https://api.github.com/repos/src-d/go-git/git/commits{/sha}","comments_url":"https://api.github.com/repos/src-d/go-git/comments{/number}","issue_comment_url":"https://api.github.com/repos/src-d/go-git/issues/comments{/number}","contents_url":"https://api.github.com/repos/src-d/go-git/contents/{+path}","compare_url":"https://api.github.com/repos/src-d/go-git/compare/{base}...{head}","merges_url":"https://api.github.com/repos/src-d/go-git/merges","archive_url":"https://api.github.com/repos/src-d/go-git/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/src-d/go-git/downloads","issues_url":"https://api.github.com/repos/src-d/go-git/issues{/number}","pulls_url":"https://api.github.com/repos/src-d/go-git/pulls{/number}","milestones_url":"https://api.github.com/repos/src-d/go-git/milestones{/number}","notifications_url":"https://api.github.com/repos/src-d/go-git/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/src-d/go-git/labels{/name}","releases_url":"https://api.github.com/repos/src-d/go-git/releases{/id}","deployments_url":"https://api.github.com/repos/src-d/go-git/deployments","created_at":"2015-10-22T10:43:33Z","updated_at":"2016-11-02T20:16:35Z","pushed_at":"2016-11-02T09:14:15Z","git_url":"git://github.com/src-d/go-git.git","ssh_url":"git@github.com:src-d/go-git.git","clone_url":"https://github.com/src-d/go-git.git","svn_url":"https://github.com/src-d/go-git","homepage":"https://godoc.org/gopkg.in/src-d/go-git.v3","size":60612,"stargazers_count":958,"watchers_count":958,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":6,"forks":44,"open_issues":6,"watchers":958,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/src-d/go-git/pulls/108"},"html":{"href":"https://github.com/src-d/go-git/pull/108"},"issue":{"href":"https://api.github.com/repos/src-d/go-git/issues/108"},"comments":{"href":"https://api.github.com/repos/src-d/go-git/issues/108/comments"},"review_comments":{"href":"https://api.github.com/repos/src-d/go-git/pulls/108/comments"},"review_comment":{"href":"https://api.github.com/repos/src-d/go-git/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/src-d/go-git/pulls/108/commits"},"statuses":{"href":"https://api.github.com/repos/src-d/go-git/statuses/df8e4887d905305cf8b61ea4d28093233e84cf06"}}}}
{"actor":{"display_login":"mcuadros"}}