{"action":"created","comment":{"url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/comments/31267633","id":31267633,"diff_hunk":"@@ -238,6 +239,16 @@ func scan(pkgPatterns []string) ([]*unit.SourceUnit, error) {\n \t\t// compare results in tests more easily.\n \t\tpkg.Root = \"\"\n \n+\t\tif strings.HasPrefix(pkg.ImportPath, \"_\") {\n+\t\t\twd, err := os.Getwd()\n+\t\t\tif err != nil {\n+\t\t\t\treturn nil, err\n+\t\t\t}\n+\t\t\tpkg.ImportPath = repo + pkg.ImportPath[1+len(wd):]","path":"scan.go","position":35,"original_position":35,"commit_id":"72d1057dfe36c60a876102a142755eb38684c04f","original_commit_id":"72d1057dfe36c60a876102a142755eb38684c04f","user":{"login":"beyang","id":1646931,"avatar_url":"https://avatars.githubusercontent.com/u/1646931?v=3","gravatar_id":"","url":"https://api.github.com/users/beyang","html_url":"https://github.com/beyang","followers_url":"https://api.github.com/users/beyang/followers","following_url":"https://api.github.com/users/beyang/following{/other_user}","gists_url":"https://api.github.com/users/beyang/gists{/gist_id}","starred_url":"https://api.github.com/users/beyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beyang/subscriptions","organizations_url":"https://api.github.com/users/beyang/orgs","repos_url":"https://api.github.com/users/beyang/repos","events_url":"https://api.github.com/users/beyang/events{/privacy}","received_events_url":"https://api.github.com/users/beyang/received_events","type":"User","site_admin":false},"body":"It seems fragile to modify `pkg` here. For example, what if some other field in `pkg` needs to change (potentially one that gets added down the road in the future). An alternative approach would be:\r\n\r\n1. Detect if we're outside the GOPATH\r\n2. Modify GOPATH to include `srclibGopath`\r\n3. run `scan(pkgPatterns)` as normal with the modified GOPATH\r\n\r\nI.e., the `scan` function is not responsible for detecting whether we're outside the GOPATH. That's done at the top leve of `ScanCmd`\r\n\r\nThis way, if `pkg` is created successfully, we have much more confidence in the correctness of its fields than if we modified them ourselves.","created_at":"2015-05-28T19:14:04Z","updated_at":"2015-05-28T19:14:04Z","html_url":"https://github.com/sourcegraph/srclib-go/pull/39#discussion_r31267633","pull_request_url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/comments/31267633"},"html":{"href":"https://github.com/sourcegraph/srclib-go/pull/39#discussion_r31267633"},"pull_request":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39","id":36435690,"html_url":"https://github.com/sourcegraph/srclib-go/pull/39","diff_url":"https://github.com/sourcegraph/srclib-go/pull/39.diff","patch_url":"https://github.com/sourcegraph/srclib-go/pull/39.patch","issue_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues/39","number":39,"state":"open","locked":false,"title":"support for building repos outside of gopath","user":{"login":"beyang","id":1646931,"avatar_url":"https://avatars.githubusercontent.com/u/1646931?v=3","gravatar_id":"","url":"https://api.github.com/users/beyang","html_url":"https://github.com/beyang","followers_url":"https://api.github.com/users/beyang/followers","following_url":"https://api.github.com/users/beyang/following{/other_user}","gists_url":"https://api.github.com/users/beyang/gists{/gist_id}","starred_url":"https://api.github.com/users/beyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beyang/subscriptions","organizations_url":"https://api.github.com/users/beyang/orgs","repos_url":"https://api.github.com/users/beyang/repos","events_url":"https://api.github.com/users/beyang/events{/privacy}","received_events_url":"https://api.github.com/users/beyang/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-28T18:21:08Z","updated_at":"2015-05-28T19:14:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39/commits","review_comments_url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39/comments","review_comment_url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues/39/comments","statuses_url":"https://api.github.com/repos/sourcegraph/srclib-go/statuses/72d1057dfe36c60a876102a142755eb38684c04f","head":{"label":"sourcegraph:not-in-gopath","ref":"not-in-gopath","sha":"72d1057dfe36c60a876102a142755eb38684c04f","user":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":22002175,"name":"srclib-go","full_name":"sourcegraph/srclib-go","owner":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sourcegraph/srclib-go","description":"Go toolchain for srclib","fork":false,"url":"https://api.github.com/repos/sourcegraph/srclib-go","forks_url":"https://api.github.com/repos/sourcegraph/srclib-go/forks","keys_url":"https://api.github.com/repos/sourcegraph/srclib-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sourcegraph/srclib-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sourcegraph/srclib-go/teams","hooks_url":"https://api.github.com/repos/sourcegraph/srclib-go/hooks","issue_events_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues/events{/number}","events_url":"https://api.github.com/repos/sourcegraph/srclib-go/events","assignees_url":"https://api.github.com/repos/sourcegraph/srclib-go/assignees{/user}","branches_url":"https://api.github.com/repos/sourcegraph/srclib-go/branches{/branch}","tags_url":"https://api.github.com/repos/sourcegraph/srclib-go/tags","blobs_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sourcegraph/srclib-go/statuses/{sha}","languages_url":"https://api.github.com/repos/sourcegraph/srclib-go/languages","stargazers_url":"https://api.github.com/repos/sourcegraph/srclib-go/stargazers","contributors_url":"https://api.github.com/repos/sourcegraph/srclib-go/contributors","subscribers_url":"https://api.github.com/repos/sourcegraph/srclib-go/subscribers","subscription_url":"https://api.github.com/repos/sourcegraph/srclib-go/subscription","commits_url":"https://api.github.com/repos/sourcegraph/srclib-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/sourcegraph/srclib-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/sourcegraph/srclib-go/contents/{+path}","compare_url":"https://api.github.com/repos/sourcegraph/srclib-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sourcegraph/srclib-go/merges","archive_url":"https://api.github.com/repos/sourcegraph/srclib-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sourcegraph/srclib-go/downloads","issues_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues{/number}","pulls_url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls{/number}","milestones_url":"https://api.github.com/repos/sourcegraph/srclib-go/milestones{/number}","notifications_url":"https://api.github.com/repos/sourcegraph/srclib-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sourcegraph/srclib-go/labels{/name}","releases_url":"https://api.github.com/repos/sourcegraph/srclib-go/releases{/id}","created_at":"2014-07-19T04:47:45Z","updated_at":"2015-05-01T21:28:14Z","pushed_at":"2015-05-28T18:21:08Z","git_url":"git://github.com/sourcegraph/srclib-go.git","ssh_url":"git@github.com:sourcegraph/srclib-go.git","clone_url":"https://github.com/sourcegraph/srclib-go.git","svn_url":"https://github.com/sourcegraph/srclib-go","homepage":"https://sourcegraph.com/sourcegraph/srclib-go","size":3221,"stargazers_count":10,"watchers_count":10,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":9,"forks":7,"open_issues":9,"watchers":10,"default_branch":"master"}},"base":{"label":"sourcegraph:master","ref":"master","sha":"8c1516cb3d20993182c632d39c0cf5b3000ad4bd","user":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":22002175,"name":"srclib-go","full_name":"sourcegraph/srclib-go","owner":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sourcegraph/srclib-go","description":"Go toolchain for srclib","fork":false,"url":"https://api.github.com/repos/sourcegraph/srclib-go","forks_url":"https://api.github.com/repos/sourcegraph/srclib-go/forks","keys_url":"https://api.github.com/repos/sourcegraph/srclib-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sourcegraph/srclib-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sourcegraph/srclib-go/teams","hooks_url":"https://api.github.com/repos/sourcegraph/srclib-go/hooks","issue_events_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues/events{/number}","events_url":"https://api.github.com/repos/sourcegraph/srclib-go/events","assignees_url":"https://api.github.com/repos/sourcegraph/srclib-go/assignees{/user}","branches_url":"https://api.github.com/repos/sourcegraph/srclib-go/branches{/branch}","tags_url":"https://api.github.com/repos/sourcegraph/srclib-go/tags","blobs_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sourcegraph/srclib-go/statuses/{sha}","languages_url":"https://api.github.com/repos/sourcegraph/srclib-go/languages","stargazers_url":"https://api.github.com/repos/sourcegraph/srclib-go/stargazers","contributors_url":"https://api.github.com/repos/sourcegraph/srclib-go/contributors","subscribers_url":"https://api.github.com/repos/sourcegraph/srclib-go/subscribers","subscription_url":"https://api.github.com/repos/sourcegraph/srclib-go/subscription","commits_url":"https://api.github.com/repos/sourcegraph/srclib-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/sourcegraph/srclib-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/sourcegraph/srclib-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/sourcegraph/srclib-go/contents/{+path}","compare_url":"https://api.github.com/repos/sourcegraph/srclib-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sourcegraph/srclib-go/merges","archive_url":"https://api.github.com/repos/sourcegraph/srclib-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sourcegraph/srclib-go/downloads","issues_url":"https://api.github.com/repos/sourcegraph/srclib-go/issues{/number}","pulls_url":"https://api.github.com/repos/sourcegraph/srclib-go/pulls{/number}","milestones_url":"https://api.github.com/repos/sourcegraph/srclib-go/milestones{/number}","notifications_url":"https://api.github.com/repos/sourcegraph/srclib-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sourcegraph/srclib-go/labels{/name}","releases_url":"https://api.github.com/repos/sourcegraph/srclib-go/releases{/id}","created_at":"2014-07-19T04:47:45Z","updated_at":"2015-05-01T21:28:14Z","pushed_at":"2015-05-28T18:21:08Z","git_url":"git://github.com/sourcegraph/srclib-go.git","ssh_url":"git@github.com:sourcegraph/srclib-go.git","clone_url":"https://github.com/sourcegraph/srclib-go.git","svn_url":"https://github.com/sourcegraph/srclib-go","homepage":"https://sourcegraph.com/sourcegraph/srclib-go","size":3221,"stargazers_count":10,"watchers_count":10,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":9,"forks":7,"open_issues":9,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39"},"html":{"href":"https://github.com/sourcegraph/srclib-go/pull/39"},"issue":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/issues/39"},"comments":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/sourcegraph/srclib-go/statuses/72d1057dfe36c60a876102a142755eb38684c04f"}}}}