{"action":"created","comment":{"url":"https://api.github.com/repos/atom/atom/pulls/comments/24512364","id":24512364,"diff_hunk":"@@ -111,7 +116,14 @@ class GitRepository\n       @repo.release()\n       @repo = null\n \n-    @subscriptions.dispose()\n+    if @subscriptions?\n+      @subscriptions.dispose()\n+      @subscriptions = null\n+\n+  # Public: Invoke the given callback when this GitRepository's destroy() method\n+  # is invoked.\n+  onDestroy: (callback) ->","path":"src/git-repository.coffee","position":26,"original_position":26,"commit_id":"e04f17fe5f9677b9f6f50520449baee5a24eaeff","original_commit_id":"e04f17fe5f9677b9f6f50520449baee5a24eaeff","user":{"login":"bolinfest","id":655869,"avatar_url":"https://avatars.githubusercontent.com/u/655869?v=3","gravatar_id":"","url":"https://api.github.com/users/bolinfest","html_url":"https://github.com/bolinfest","followers_url":"https://api.github.com/users/bolinfest/followers","following_url":"https://api.github.com/users/bolinfest/following{/other_user}","gists_url":"https://api.github.com/users/bolinfest/gists{/gist_id}","starred_url":"https://api.github.com/users/bolinfest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolinfest/subscriptions","organizations_url":"https://api.github.com/users/bolinfest/orgs","repos_url":"https://api.github.com/users/bolinfest/repos","events_url":"https://api.github.com/users/bolinfest/events{/privacy}","received_events_url":"https://api.github.com/users/bolinfest/received_events","type":"User","site_admin":false},"body":"That's fine: works for me.","created_at":"2015-02-11T17:09:53Z","updated_at":"2015-02-11T17:09:53Z","html_url":"https://github.com/atom/atom/pull/5491#discussion_r24512364","pull_request_url":"https://api.github.com/repos/atom/atom/pulls/5491","_links":{"self":{"href":"https://api.github.com/repos/atom/atom/pulls/comments/24512364"},"html":{"href":"https://github.com/atom/atom/pull/5491#discussion_r24512364"},"pull_request":{"href":"https://api.github.com/repos/atom/atom/pulls/5491"}}},"pull_request":{"url":"https://api.github.com/repos/atom/atom/pulls/5491","id":29065570,"html_url":"https://github.com/atom/atom/pull/5491","diff_url":"https://github.com/atom/atom/pull/5491.diff","patch_url":"https://github.com/atom/atom/pull/5491.patch","issue_url":"https://api.github.com/repos/atom/atom/issues/5491","number":5491,"state":"open","locked":false,"title":"Set up the atom.repository-provider service and implement GitRepositoryP...","user":{"login":"bolinfest","id":655869,"avatar_url":"https://avatars.githubusercontent.com/u/655869?v=3","gravatar_id":"","url":"https://api.github.com/users/bolinfest","html_url":"https://github.com/bolinfest","followers_url":"https://api.github.com/users/bolinfest/followers","following_url":"https://api.github.com/users/bolinfest/following{/other_user}","gists_url":"https://api.github.com/users/bolinfest/gists{/gist_id}","starred_url":"https://api.github.com/users/bolinfest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolinfest/subscriptions","organizations_url":"https://api.github.com/users/bolinfest/orgs","repos_url":"https://api.github.com/users/bolinfest/repos","events_url":"https://api.github.com/users/bolinfest/events{/privacy}","received_events_url":"https://api.github.com/users/bolinfest/received_events","type":"User","site_admin":false},"body":"...rovider.\r\n\r\nI tested this by creating a dummy implementation of an `HgRepositoryProvider`\r\n(with the optional `createRepositorySync()` method implemented) and an `HgRepository`\r\nin an Atom package with the following stanza in the `package.json`:\r\n\r\n```\r\n  \"providedServices\": {\r\n    \"atom.repository-provider\": {\r\n      \"versions\": {\r\n        \"0.1.0\": \"createHgRepositoryProvider\"\r\n      }\r\n    }\r\n  },\r\n```\r\n\r\nI opened a path with an Hg repository from the command line using Atom.\r\nI verified that `atom.project.repositoryProviders` contains both a\r\n`GitRepositoryProvider` and an `HgRepositoryProvider`.\r\n\r\nI also verified that running the following printed out an `HgRepository`:\r\n\r\n```\r\nvar Directory = require('pathwatcher').Directory;\r\natom.project.repositoryForDirectory(\r\n    new Directory(atom.project.getPath(), /* symlink */ false)).then(\r\n        function(repo) { console.log('repo: %o', repo); });\r\n```\r\n\r\nOne thing that stands out to me about the current API for the\r\natom.repository-provider service is that the function used to create\r\na `RepositoryProvider` does not receive any arguments. If the creation\r\nof the `GitRepositoryProvider` were done via the service, this would\r\nbe a problem because it needs a reference to `atom.project`, which is\r\nnot defined when it is created. (We work around this because it is\r\ncreated in `Project`'s constructor, so it can pass `this` to\r\n`new GitRepositoryProvider()`.)\r\n\r\nWe would have to create a `RepositoryProviderFactory` or something if\r\nwe wanted to specify arguments when creating a `RepositoryProvider`,\r\nin general. Maybe that's too crazy / not an issue, in practice.\r\n\r\nThough note that `GitRepository` cannot access `atom.project` lazily\r\nbecause it uses it in its constructor to do the following:\r\n\r\n```\r\nif @project?\r\n  @subscriptions.add @project.eachBuffer (buffer) => @subscribeToBuffer(buffer)\r\n```\r\n\r\nSo long as we can guarantee that `atom.project` is defined before the\r\nother providers are initialized, I think we should be OK.\r\n\r\nFollow-up work:\r\n* Replace the use of `RepositoryProvider.createRepositorySync()` with\r\n`RepositoryProvider.repositoryForDirectory()` in `Project.setPaths()`.\r\n* Replace all uses of `Project.getRepositories()` with\r\n`Project.repositoryForDirectory()` in packages that are bundled with Atom\r\nby default.\r\n* Implement `Directory.exists()` and/or `Directory.existsSync()` and update\r\n`git-repositor-provider.coffee`, as appropriate.\r\n* Eliminate `GitRepositoryProvider.repositoryForDirectory()`'s use of\r\nsynchronous methods.\r\n* Somewhat orthogonal to this diff, but the following fields need to be\r\nremoved from `Project` because they enforce the idea of a single root:\r\n`path`, `rootDirectory`, and `repo`. This has implications around the\r\nexisting use of `@rootDirectory?.off()` and `@destroyRepo()`.","created_at":"2015-02-11T03:12:06Z","updated_at":"2015-02-11T17:09:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a97bde5d6675617ddecf7c23a5bf47aa3ce5b56c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/atom/atom/pulls/5491/commits","review_comments_url":"https://api.github.com/repos/atom/atom/pulls/5491/comments","review_comment_url":"https://api.github.com/repos/atom/atom/pulls/comments/{number}","comments_url":"https://api.github.com/repos/atom/atom/issues/5491/comments","statuses_url":"https://api.github.com/repos/atom/atom/statuses/e04f17fe5f9677b9f6f50520449baee5a24eaeff","head":{"label":"bolinfest:repository-provider","ref":"repository-provider","sha":"e04f17fe5f9677b9f6f50520449baee5a24eaeff","user":{"login":"bolinfest","id":655869,"avatar_url":"https://avatars.githubusercontent.com/u/655869?v=3","gravatar_id":"","url":"https://api.github.com/users/bolinfest","html_url":"https://github.com/bolinfest","followers_url":"https://api.github.com/users/bolinfest/followers","following_url":"https://api.github.com/users/bolinfest/following{/other_user}","gists_url":"https://api.github.com/users/bolinfest/gists{/gist_id}","starred_url":"https://api.github.com/users/bolinfest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolinfest/subscriptions","organizations_url":"https://api.github.com/users/bolinfest/orgs","repos_url":"https://api.github.com/users/bolinfest/repos","events_url":"https://api.github.com/users/bolinfest/events{/privacy}","received_events_url":"https://api.github.com/users/bolinfest/received_events","type":"User","site_admin":false},"repo":{"id":21920222,"name":"atom","full_name":"bolinfest/atom","owner":{"login":"bolinfest","id":655869,"avatar_url":"https://avatars.githubusercontent.com/u/655869?v=3","gravatar_id":"","url":"https://api.github.com/users/bolinfest","html_url":"https://github.com/bolinfest","followers_url":"https://api.github.com/users/bolinfest/followers","following_url":"https://api.github.com/users/bolinfest/following{/other_user}","gists_url":"https://api.github.com/users/bolinfest/gists{/gist_id}","starred_url":"https://api.github.com/users/bolinfest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolinfest/subscriptions","organizations_url":"https://api.github.com/users/bolinfest/orgs","repos_url":"https://api.github.com/users/bolinfest/repos","events_url":"https://api.github.com/users/bolinfest/events{/privacy}","received_events_url":"https://api.github.com/users/bolinfest/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bolinfest/atom","description":"The hackable editor","fork":true,"url":"https://api.github.com/repos/bolinfest/atom","forks_url":"https://api.github.com/repos/bolinfest/atom/forks","keys_url":"https://api.github.com/repos/bolinfest/atom/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bolinfest/atom/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bolinfest/atom/teams","hooks_url":"https://api.github.com/repos/bolinfest/atom/hooks","issue_events_url":"https://api.github.com/repos/bolinfest/atom/issues/events{/number}","events_url":"https://api.github.com/repos/bolinfest/atom/events","assignees_url":"https://api.github.com/repos/bolinfest/atom/assignees{/user}","branches_url":"https://api.github.com/repos/bolinfest/atom/branches{/branch}","tags_url":"https://api.github.com/repos/bolinfest/atom/tags","blobs_url":"https://api.github.com/repos/bolinfest/atom/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bolinfest/atom/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bolinfest/atom/git/refs{/sha}","trees_url":"https://api.github.com/repos/bolinfest/atom/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bolinfest/atom/statuses/{sha}","languages_url":"https://api.github.com/repos/bolinfest/atom/languages","stargazers_url":"https://api.github.com/repos/bolinfest/atom/stargazers","contributors_url":"https://api.github.com/repos/bolinfest/atom/contributors","subscribers_url":"https://api.github.com/repos/bolinfest/atom/subscribers","subscription_url":"https://api.github.com/repos/bolinfest/atom/subscription","commits_url":"https://api.github.com/repos/bolinfest/atom/commits{/sha}","git_commits_url":"https://api.github.com/repos/bolinfest/atom/git/commits{/sha}","comments_url":"https://api.github.com/repos/bolinfest/atom/comments{/number}","issue_comment_url":"https://api.github.com/repos/bolinfest/atom/issues/comments/{number}","contents_url":"https://api.github.com/repos/bolinfest/atom/contents/{+path}","compare_url":"https://api.github.com/repos/bolinfest/atom/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bolinfest/atom/merges","archive_url":"https://api.github.com/repos/bolinfest/atom/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bolinfest/atom/downloads","issues_url":"https://api.github.com/repos/bolinfest/atom/issues{/number}","pulls_url":"https://api.github.com/repos/bolinfest/atom/pulls{/number}","milestones_url":"https://api.github.com/repos/bolinfest/atom/milestones{/number}","notifications_url":"https://api.github.com/repos/bolinfest/atom/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bolinfest/atom/labels{/name}","releases_url":"https://api.github.com/repos/bolinfest/atom/releases{/id}","created_at":"2014-07-16T22:20:25Z","updated_at":"2014-07-16T20:48:28Z","pushed_at":"2015-02-11T05:48:24Z","git_url":"git://github.com/bolinfest/atom.git","ssh_url":"git@github.com:bolinfest/atom.git","clone_url":"https://github.com/bolinfest/atom.git","svn_url":"https://github.com/bolinfest/atom","homepage":"atom.io","size":262425,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"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":"atom:master","ref":"master","sha":"090561eb00fe3fe885dedc866821eb6bd44e96a8","user":{"login":"atom","id":1089146,"avatar_url":"https://avatars.githubusercontent.com/u/1089146?v=3","gravatar_id":"","url":"https://api.github.com/users/atom","html_url":"https://github.com/atom","followers_url":"https://api.github.com/users/atom/followers","following_url":"https://api.github.com/users/atom/following{/other_user}","gists_url":"https://api.github.com/users/atom/gists{/gist_id}","starred_url":"https://api.github.com/users/atom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atom/subscriptions","organizations_url":"https://api.github.com/users/atom/orgs","repos_url":"https://api.github.com/users/atom/repos","events_url":"https://api.github.com/users/atom/events{/privacy}","received_events_url":"https://api.github.com/users/atom/received_events","type":"Organization","site_admin":false},"repo":{"id":3228505,"name":"atom","full_name":"atom/atom","owner":{"login":"atom","id":1089146,"avatar_url":"https://avatars.githubusercontent.com/u/1089146?v=3","gravatar_id":"","url":"https://api.github.com/users/atom","html_url":"https://github.com/atom","followers_url":"https://api.github.com/users/atom/followers","following_url":"https://api.github.com/users/atom/following{/other_user}","gists_url":"https://api.github.com/users/atom/gists{/gist_id}","starred_url":"https://api.github.com/users/atom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atom/subscriptions","organizations_url":"https://api.github.com/users/atom/orgs","repos_url":"https://api.github.com/users/atom/repos","events_url":"https://api.github.com/users/atom/events{/privacy}","received_events_url":"https://api.github.com/users/atom/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/atom/atom","description":"The hackable editor","fork":false,"url":"https://api.github.com/repos/atom/atom","forks_url":"https://api.github.com/repos/atom/atom/forks","keys_url":"https://api.github.com/repos/atom/atom/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atom/atom/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atom/atom/teams","hooks_url":"https://api.github.com/repos/atom/atom/hooks","issue_events_url":"https://api.github.com/repos/atom/atom/issues/events{/number}","events_url":"https://api.github.com/repos/atom/atom/events","assignees_url":"https://api.github.com/repos/atom/atom/assignees{/user}","branches_url":"https://api.github.com/repos/atom/atom/branches{/branch}","tags_url":"https://api.github.com/repos/atom/atom/tags","blobs_url":"https://api.github.com/repos/atom/atom/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atom/atom/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atom/atom/git/refs{/sha}","trees_url":"https://api.github.com/repos/atom/atom/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atom/atom/statuses/{sha}","languages_url":"https://api.github.com/repos/atom/atom/languages","stargazers_url":"https://api.github.com/repos/atom/atom/stargazers","contributors_url":"https://api.github.com/repos/atom/atom/contributors","subscribers_url":"https://api.github.com/repos/atom/atom/subscribers","subscription_url":"https://api.github.com/repos/atom/atom/subscription","commits_url":"https://api.github.com/repos/atom/atom/commits{/sha}","git_commits_url":"https://api.github.com/repos/atom/atom/git/commits{/sha}","comments_url":"https://api.github.com/repos/atom/atom/comments{/number}","issue_comment_url":"https://api.github.com/repos/atom/atom/issues/comments/{number}","contents_url":"https://api.github.com/repos/atom/atom/contents/{+path}","compare_url":"https://api.github.com/repos/atom/atom/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atom/atom/merges","archive_url":"https://api.github.com/repos/atom/atom/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atom/atom/downloads","issues_url":"https://api.github.com/repos/atom/atom/issues{/number}","pulls_url":"https://api.github.com/repos/atom/atom/pulls{/number}","milestones_url":"https://api.github.com/repos/atom/atom/milestones{/number}","notifications_url":"https://api.github.com/repos/atom/atom/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atom/atom/labels{/name}","releases_url":"https://api.github.com/repos/atom/atom/releases{/id}","created_at":"2012-01-20T18:18:21Z","updated_at":"2015-02-11T16:51:04Z","pushed_at":"2015-02-11T16:47:44Z","git_url":"git://github.com/atom/atom.git","ssh_url":"git@github.com:atom/atom.git","clone_url":"https://github.com/atom/atom.git","svn_url":"https://github.com/atom/atom","homepage":"https://atom.io/","size":340004,"stargazers_count":12431,"watchers_count":12431,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2076,"mirror_url":null,"open_issues_count":844,"forks":2076,"open_issues":844,"watchers":12431,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/atom/atom/pulls/5491"},"html":{"href":"https://github.com/atom/atom/pull/5491"},"issue":{"href":"https://api.github.com/repos/atom/atom/issues/5491"},"comments":{"href":"https://api.github.com/repos/atom/atom/issues/5491/comments"},"review_comments":{"href":"https://api.github.com/repos/atom/atom/pulls/5491/comments"},"review_comment":{"href":"https://api.github.com/repos/atom/atom/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/atom/atom/pulls/5491/commits"},"statuses":{"href":"https://api.github.com/repos/atom/atom/statuses/e04f17fe5f9677b9f6f50520449baee5a24eaeff"}}}}