GitHub PullRequestReviewCommentEvent at 2014-07-09 10:40:03
Repository: erlgit
Actor: mrjaros
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/gleber/erlgit/pulls/comments/14703187","id":14703187,"diff_hunk":"@@ -160,8 +160,8 @@ branch(Repo) ->\n         false ->\n             Refs = refs(Repo),\n             {value, {\"HEAD\", 'HEAD', H}, Refs2} = lists:keytake('HEAD', 2, Refs),\n-            [B] = [ N || {N, T, C} <- Refs2, T == head, C == H ],\n-            {ok, B};\n+            B = [ N || {N, T, C} <- Refs2, T == head, C == H ],\n+            {ok, list_join(B, \"; \")};","path":"src/git.erl","position":7,"original_position":7,"commit_id":"d5103a445892e5d6f3d893a16637368765b112db","original_commit_id":"d5103a445892e5d6f3d893a16637368765b112db","user":{"login":"mrjaros","id":3167907,"avatar_url":"https://avatars.githubusercontent.com/u/3167907?","gravatar_id":"5cc77bf5e8984bd4ab089623128f513d","url":"https://api.github.com/users/mrjaros","html_url":"https://github.com/mrjaros","followers_url":"https://api.github.com/users/mrjaros/followers","following_url":"https://api.github.com/users/mrjaros/following{/other_user}","gists_url":"https://api.github.com/users/mrjaros/gists{/gist_id}","starred_url":"https://api.github.com/users/mrjaros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrjaros/subscriptions","organizations_url":"https://api.github.com/users/mrjaros/orgs","repos_url":"https://api.github.com/users/mrjaros/repos","events_url":"https://api.github.com/users/mrjaros/events{/privacy}","received_events_url":"https://api.github.com/users/mrjaros/received_events","type":"User","site_admin":false},"body":"But when we're operating on refs, we can't suppose to have distinct ref's sha. By doing \r\n[B] = [ N || {N, T, C} <- Refs2, T == head, C == H ], \r\nyou are matching one-element list to refs having tag 'head' and specific sha, while refs list doesn't guarantee this. Let's take a look step-by-step. In this example, I'm on branch 'mstr', but 'master' is in the same place:\r\n29> {ok, Repo} = file:get_cwd().\r\n{ok,\"/home/jarek/erlgit\"}\r\n30> Refs = git:refs(Repo).      \r\n[{\"HEAD\",'HEAD',\"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n {\"master\",head,\"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n {\"mstr\",head,\"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n {\"origin/HEAD\",remote,\r\n  \"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n {\"origin/master\",remote,\r\n  \"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n {\"v0.3.0\",tag,\"be3b0ade881666286801ee8b218ecbf29da97558\"},\r\n {\"v0.3.1\",tag,\"89f2d81be12f6034db52fd6d71d8a4b96f4ee9de\"},\r\n {\"v0.3.2\",tag,\"3dc42981d9e4677654370614888ec3f368421240\"},\r\n {\"v0.5.0\",tag,\"da21ef41b800d1fd0c08d7d8f05b4489a0c3d2a8\"},\r\n {\"v0.7.0\",tag,\"172e570f39020637d1e98326c746ad776242417f\"},\r\n {\"v0.7.5\",tag,\"ef40ae01bf0ad7c1f6b5564940d5426b1c082b4a\"}]\r\n\r\nAs you can see, there are branches 'master' and 'mstr' with the same tag ('head') and sha. Let's get going:\r\n31> {value, {\"HEAD\", 'HEAD', H}, Refs2} = lists:keytake('HEAD', 2, Refs).\r\n{value,{\"HEAD\",'HEAD',\r\n        \"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n       [{\"master\",head,\"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n        {\"mstr\",head,\"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n        {\"origin/HEAD\",remote,\r\n         \"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n        {\"origin/master\",remote,\r\n         \"d5103a445892e5d6f3d893a16637368765b112db\"},\r\n        {\"v0.3.0\",tag,\"be3b0ade881666286801ee8b218ecbf29da97558\"},\r\n        {\"v0.3.1\",tag,\"89f2d81be12f6034db52fd6d71d8a4b96f4ee9de\"},\r\n        {\"v0.3.2\",tag,\"3dc42981d9e4677654370614888ec3f368421240\"},\r\n        {\"v0.5.0\",tag,\"da21ef41b800d1fd0c08d7d8f05b4489a0c3d2a8\"},\r\n        {\"v0.7.0\",tag,\"172e570f39020637d1e98326c746ad776242417f\"},\r\n        {\"v0.7.5\",tag,\"ef40ae01bf0ad7c1f6b5564940d5426b1c082b4a\"}]}\r\n\r\nWe assign our head's sha to variable H. It's okay, but when we go a little bit forward:\r\n32> [B] = [ N || {N, T, C} <- Refs2, T == head, C == H ].\r\n** exception error: no match of right hand side value [\"master\",\"mstr\"]\r\n\r\nThat's because we have two tuples with same tag and sha, and trying to assign its branches to one-element list.\r\n\r\nWith my fix, we get just list of these branches. Function list_join becomes handy when we want to return list of branches, while we can't determine which one is active.","created_at":"2014-07-09T10:40:03Z","updated_at":"2014-07-09T10:40:03Z","html_url":"https://github.com/gleber/erlgit/pull/7#discussion_r14703187","pull_request_url":"https://api.github.com/repos/gleber/erlgit/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/gleber/erlgit/pulls/comments/14703187"},"html":{"href":"https://github.com/gleber/erlgit/pull/7#discussion_r14703187"},"pull_request":{"href":"https://api.github.com/repos/gleber/erlgit/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/gleber/erlgit/pulls/7","id":18090356,"html_url":"https://github.com/gleber/erlgit/pull/7","diff_url":"https://github.com/gleber/erlgit/pull/7.diff","patch_url":"https://github.com/gleber/erlgit/pull/7.patch","issue_url":"https://api.github.com/repos/gleber/erlgit/issues/7","number":7,"state":"open","title":"Fix git:branch bug when there is more than one branch with equal SHA-ID","user":{"login":"mrjaros","id":3167907,"avatar_url":"https://avatars.githubusercontent.com/u/3167907?","gravatar_id":"5cc77bf5e8984bd4ab089623128f513d","url":"https://api.github.com/users/mrjaros","html_url":"https://github.com/mrjaros","followers_url":"https://api.github.com/users/mrjaros/followers","following_url":"https://api.github.com/users/mrjaros/following{/other_user}","gists_url":"https://api.github.com/users/mrjaros/gists{/gist_id}","starred_url":"https://api.github.com/users/mrjaros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrjaros/subscriptions","organizations_url":"https://api.github.com/users/mrjaros/orgs","repos_url":"https://api.github.com/users/mrjaros/repos","events_url":"https://api.github.com/users/mrjaros/events{/privacy}","received_events_url":"https://api.github.com/users/mrjaros/received_events","type":"User","site_admin":false},"body":"This fixes badmatch error when we have more than one branch with equal sha-id. In such case, you tried to match one-element list ([B]) with list of branches ([\"branchA\", \"branchB\"]). Now we just return list of branches, separated with \"; \", ex. \"branchA; branchB\"","created_at":"2014-07-08T09:04:22Z","updated_at":"2014-07-09T10:40:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f75768067830385d7ef899c217d8becb572cacbd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gleber/erlgit/pulls/7/commits","review_comments_url":"https://api.github.com/repos/gleber/erlgit/pulls/7/comments","review_comment_url":"https://api.github.com/repos/gleber/erlgit/pulls/comments/{number}","comments_url":"https://api.github.com/repos/gleber/erlgit/issues/7/comments","statuses_url":"https://api.github.com/repos/gleber/erlgit/statuses/d5103a445892e5d6f3d893a16637368765b112db","head":{"label":"mrjaros:master","ref":"master","sha":"d5103a445892e5d6f3d893a16637368765b112db","user":{"login":"mrjaros","id":3167907,"avatar_url":"https://avatars.githubusercontent.com/u/3167907?","gravatar_id":"5cc77bf5e8984bd4ab089623128f513d","url":"https://api.github.com/users/mrjaros","html_url":"https://github.com/mrjaros","followers_url":"https://api.github.com/users/mrjaros/followers","following_url":"https://api.github.com/users/mrjaros/following{/other_user}","gists_url":"https://api.github.com/users/mrjaros/gists{/gist_id}","starred_url":"https://api.github.com/users/mrjaros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrjaros/subscriptions","organizations_url":"https://api.github.com/users/mrjaros/orgs","repos_url":"https://api.github.com/users/mrjaros/repos","events_url":"https://api.github.com/users/mrjaros/events{/privacy}","received_events_url":"https://api.github.com/users/mrjaros/received_events","type":"User","site_admin":false},"repo":{"id":21605329,"name":"erlgit","full_name":"mrjaros/erlgit","owner":{"login":"mrjaros","id":3167907,"avatar_url":"https://avatars.githubusercontent.com/u/3167907?","gravatar_id":"5cc77bf5e8984bd4ab089623128f513d","url":"https://api.github.com/users/mrjaros","html_url":"https://github.com/mrjaros","followers_url":"https://api.github.com/users/mrjaros/followers","following_url":"https://api.github.com/users/mrjaros/following{/other_user}","gists_url":"https://api.github.com/users/mrjaros/gists{/gist_id}","starred_url":"https://api.github.com/users/mrjaros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrjaros/subscriptions","organizations_url":"https://api.github.com/users/mrjaros/orgs","repos_url":"https://api.github.com/users/mrjaros/repos","events_url":"https://api.github.com/users/mrjaros/events{/privacy}","received_events_url":"https://api.github.com/users/mrjaros/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mrjaros/erlgit","description":"Erlang convenience wrapper around git executable","fork":true,"url":"https://api.github.com/repos/mrjaros/erlgit","forks_url":"https://api.github.com/repos/mrjaros/erlgit/forks","keys_url":"https://api.github.com/repos/mrjaros/erlgit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mrjaros/erlgit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mrjaros/erlgit/teams","hooks_url":"https://api.github.com/repos/mrjaros/erlgit/hooks","issue_events_url":"https://api.github.com/repos/mrjaros/erlgit/issues/events{/number}","events_url":"https://api.github.com/repos/mrjaros/erlgit/events","assignees_url":"https://api.github.com/repos/mrjaros/erlgit/assignees{/user}","branches_url":"https://api.github.com/repos/mrjaros/erlgit/branches{/branch}","tags_url":"https://api.github.com/repos/mrjaros/erlgit/tags","blobs_url":"https://api.github.com/repos/mrjaros/erlgit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mrjaros/erlgit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mrjaros/erlgit/git/refs{/sha}","trees_url":"https://api.github.com/repos/mrjaros/erlgit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mrjaros/erlgit/statuses/{sha}","languages_url":"https://api.github.com/repos/mrjaros/erlgit/languages","stargazers_url":"https://api.github.com/repos/mrjaros/erlgit/stargazers","contributors_url":"https://api.github.com/repos/mrjaros/erlgit/contributors","subscribers_url":"https://api.github.com/repos/mrjaros/erlgit/subscribers","subscription_url":"https://api.github.com/repos/mrjaros/erlgit/subscription","commits_url":"https://api.github.com/repos/mrjaros/erlgit/commits{/sha}","git_commits_url":"https://api.github.com/repos/mrjaros/erlgit/git/commits{/sha}","comments_url":"https://api.github.com/repos/mrjaros/erlgit/comments{/number}","issue_comment_url":"https://api.github.com/repos/mrjaros/erlgit/issues/comments/{number}","contents_url":"https://api.github.com/repos/mrjaros/erlgit/contents/{+path}","compare_url":"https://api.github.com/repos/mrjaros/erlgit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mrjaros/erlgit/merges","archive_url":"https://api.github.com/repos/mrjaros/erlgit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mrjaros/erlgit/downloads","issues_url":"https://api.github.com/repos/mrjaros/erlgit/issues{/number}","pulls_url":"https://api.github.com/repos/mrjaros/erlgit/pulls{/number}","milestones_url":"https://api.github.com/repos/mrjaros/erlgit/milestones{/number}","notifications_url":"https://api.github.com/repos/mrjaros/erlgit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mrjaros/erlgit/labels{/name}","releases_url":"https://api.github.com/repos/mrjaros/erlgit/releases{/id}","created_at":"2014-07-08T08:37:56Z","updated_at":"2014-07-08T08:59:52Z","pushed_at":"2014-07-08T08:59:52Z","git_url":"git://github.com/mrjaros/erlgit.git","ssh_url":"git@github.com:mrjaros/erlgit.git","clone_url":"https://github.com/mrjaros/erlgit.git","svn_url":"https://github.com/mrjaros/erlgit","homepage":null,"size":138,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"gleber:master","ref":"master","sha":"ffdeb1e260eb2c546e9cd366b954aeedf993d042","user":{"login":"gleber","id":33185,"avatar_url":"https://avatars.githubusercontent.com/u/33185?","gravatar_id":"8f148931813913491327a6312b48282a","url":"https://api.github.com/users/gleber","html_url":"https://github.com/gleber","followers_url":"https://api.github.com/users/gleber/followers","following_url":"https://api.github.com/users/gleber/following{/other_user}","gists_url":"https://api.github.com/users/gleber/gists{/gist_id}","starred_url":"https://api.github.com/users/gleber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gleber/subscriptions","organizations_url":"https://api.github.com/users/gleber/orgs","repos_url":"https://api.github.com/users/gleber/repos","events_url":"https://api.github.com/users/gleber/events{/privacy}","received_events_url":"https://api.github.com/users/gleber/received_events","type":"User","site_admin":false},"repo":{"id":5521180,"name":"erlgit","full_name":"gleber/erlgit","owner":{"login":"gleber","id":33185,"avatar_url":"https://avatars.githubusercontent.com/u/33185?","gravatar_id":"8f148931813913491327a6312b48282a","url":"https://api.github.com/users/gleber","html_url":"https://github.com/gleber","followers_url":"https://api.github.com/users/gleber/followers","following_url":"https://api.github.com/users/gleber/following{/other_user}","gists_url":"https://api.github.com/users/gleber/gists{/gist_id}","starred_url":"https://api.github.com/users/gleber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gleber/subscriptions","organizations_url":"https://api.github.com/users/gleber/orgs","repos_url":"https://api.github.com/users/gleber/repos","events_url":"https://api.github.com/users/gleber/events{/privacy}","received_events_url":"https://api.github.com/users/gleber/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gleber/erlgit","description":"Erlang convenience wrapper around git executable","fork":false,"url":"https://api.github.com/repos/gleber/erlgit","forks_url":"https://api.github.com/repos/gleber/erlgit/forks","keys_url":"https://api.github.com/repos/gleber/erlgit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gleber/erlgit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gleber/erlgit/teams","hooks_url":"https://api.github.com/repos/gleber/erlgit/hooks","issue_events_url":"https://api.github.com/repos/gleber/erlgit/issues/events{/number}","events_url":"https://api.github.com/repos/gleber/erlgit/events","assignees_url":"https://api.github.com/repos/gleber/erlgit/assignees{/user}","branches_url":"https://api.github.com/repos/gleber/erlgit/branches{/branch}","tags_url":"https://api.github.com/repos/gleber/erlgit/tags","blobs_url":"https://api.github.com/repos/gleber/erlgit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gleber/erlgit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gleber/erlgit/git/refs{/sha}","trees_url":"https://api.github.com/repos/gleber/erlgit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gleber/erlgit/statuses/{sha}","languages_url":"https://api.github.com/repos/gleber/erlgit/languages","stargazers_url":"https://api.github.com/repos/gleber/erlgit/stargazers","contributors_url":"https://api.github.com/repos/gleber/erlgit/contributors","subscribers_url":"https://api.github.com/repos/gleber/erlgit/subscribers","subscription_url":"https://api.github.com/repos/gleber/erlgit/subscription","commits_url":"https://api.github.com/repos/gleber/erlgit/commits{/sha}","git_commits_url":"https://api.github.com/repos/gleber/erlgit/git/commits{/sha}","comments_url":"https://api.github.com/repos/gleber/erlgit/comments{/number}","issue_comment_url":"https://api.github.com/repos/gleber/erlgit/issues/comments/{number}","contents_url":"https://api.github.com/repos/gleber/erlgit/contents/{+path}","compare_url":"https://api.github.com/repos/gleber/erlgit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gleber/erlgit/merges","archive_url":"https://api.github.com/repos/gleber/erlgit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gleber/erlgit/downloads","issues_url":"https://api.github.com/repos/gleber/erlgit/issues{/number}","pulls_url":"https://api.github.com/repos/gleber/erlgit/pulls{/number}","milestones_url":"https://api.github.com/repos/gleber/erlgit/milestones{/number}","notifications_url":"https://api.github.com/repos/gleber/erlgit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gleber/erlgit/labels{/name}","releases_url":"https://api.github.com/repos/gleber/erlgit/releases{/id}","created_at":"2012-08-23T07:48:15Z","updated_at":"2014-07-08T22:19:47Z","pushed_at":"2013-10-02T11:56:26Z","git_url":"git://github.com/gleber/erlgit.git","ssh_url":"git@github.com:gleber/erlgit.git","clone_url":"https://github.com/gleber/erlgit.git","svn_url":"https://github.com/gleber/erlgit","homepage":null,"size":140,"stargazers_count":17,"watchers_count":17,"language":"Erlang","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":13,"mirror_url":null,"open_issues_count":3,"forks":13,"open_issues":3,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gleber/erlgit/pulls/7"},"html":{"href":"https://github.com/gleber/erlgit/pull/7"},"issue":{"href":"https://api.github.com/repos/gleber/erlgit/issues/7"},"comments":{"href":"https://api.github.com/repos/gleber/erlgit/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/gleber/erlgit/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/gleber/erlgit/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/gleber/erlgit/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/gleber/erlgit/statuses/d5103a445892e5d6f3d893a16637368765b112db"}}}}