{"action":"created","comment":{"url":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments/52904347","id":52904347,"diff_hunk":"@@ -5,40 +5,71 @@ defmodule System do\n   with the VM or the host system.\n   \"\"\"\n \n-  defp strip_re(iodata, pattern) do\n-    :re.replace(iodata, pattern, \"\", [return: :binary])\n+  @base_dir           Path.join([__DIR__, \"..\", \"..\", \"..\"])\n+  @version_file       Path.join(@base_dir, \"VERSION\")\n+  @git_dir            Path.join(@base_dir, \".git\")\n+  @git_head_file      Path.join(@git_dir, \"HEAD\")\n+\n+  @spec strip(iodata) :: String.t\n+  defp strip(iodata) do\n+    iodata\n+    |> :re.replace(\"^[\\s\\r\\n\\t]+\", \"\", [return: :binary])\n+    |> :re.replace(\"[\\s\\r\\n\\t]+$\", \"\", [return: :binary])\n   end\n \n+  @spec read_stripped(String.t) :: String.t\n   defp read_stripped(path) do\n-    case :file.read_file(path) do\n+    case File.read(path) do\n       {:ok, binary} ->\n-        strip_re(binary, \"^\\s+|\\s+$\")\n-      _ -> \"\"\n+        strip(binary)\n+      _ ->\n+        \"\"\n     end\n   end\n \n   # Read and strip the version from the VERSION file.\n+  @spec get_version :: String.t\n   defmacrop get_version do\n-    case read_stripped(:filename.join(__DIR__, \"../../../VERSION\")) do\n+    case read_stripped(@version_file) do\n       \"\"   -> raise RuntimeError, message: \"could not read the version number from VERSION\"\n       data -> data\n     end\n   end\n \n-  # Tries to run \"git rev-parse --short HEAD\". In the case of success returns\n-  # the short revision hash. If that is not available, tries to read the commit hash\n+  # Tries to run \"git rev-parse HEAD\". In the case of success returns\n+  # the revision hash. If that is not available, tries to read the commit hash\n   # from .git/HEAD. If that fails, returns an empty string.\n+  @spec get_revision :: String.t\n   defmacrop get_revision do\n-    dirpath = :filename.join(__DIR__, \"../../../.git\")\n-    case :file.read_file_info(dirpath) do\n+    case :file.read_file_info(@git_dir) do\n       {:ok, _} ->\n         if :os.find_executable('git') do\n-          data = :os.cmd('git rev-parse --short HEAD')\n-          strip_re(data, \"\\n\")\n+          :os.cmd('git rev-parse HEAD') |> strip\n+        else\n+          read_stripped(@git_head_file)\n+        end\n+\n+      _ ->\n+        \"\"\n+    end\n+  end\n+\n+  @spec get_tag :: String.t\n+  defmacrop get_tag do","path":"lib/elixir/lib/system.ex","position":68,"original_position":66,"commit_id":"c4d5744bf8bc6ade89262448994f6dbb80741faa","original_commit_id":"6c2fb37654079ed31433d9b0c890daf0936660a2","user":{"login":"eksperimental","id":9133420,"avatar_url":"https://avatars.githubusercontent.com/u/9133420?v=3","gravatar_id":"","url":"https://api.github.com/users/eksperimental","html_url":"https://github.com/eksperimental","followers_url":"https://api.github.com/users/eksperimental/followers","following_url":"https://api.github.com/users/eksperimental/following{/other_user}","gists_url":"https://api.github.com/users/eksperimental/gists{/gist_id}","starred_url":"https://api.github.com/users/eksperimental/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eksperimental/subscriptions","organizations_url":"https://api.github.com/users/eksperimental/orgs","repos_url":"https://api.github.com/users/eksperimental/repos","events_url":"https://api.github.com/users/eksperimental/events{/privacy}","received_events_url":"https://api.github.com/users/eksperimental/received_events","type":"User","site_admin":false},"body":"you guys are definitely right.","created_at":"2016-02-15T14:29:19Z","updated_at":"2016-02-15T14:29:19Z","html_url":"https://github.com/elixir-lang/elixir/pull/4296#discussion_r52904347","pull_request_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296","_links":{"self":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments/52904347"},"html":{"href":"https://github.com/elixir-lang/elixir/pull/4296#discussion_r52904347"},"pull_request":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296"}}},"pull_request":{"url":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296","id":59233610,"html_url":"https://github.com/elixir-lang/elixir/pull/4296","diff_url":"https://github.com/elixir-lang/elixir/pull/4296.diff","patch_url":"https://github.com/elixir-lang/elixir/pull/4296.patch","issue_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4296","number":4296,"state":"open","locked":false,"title":"[WIP] Improve use of git revision","user":{"login":"eksperimental","id":9133420,"avatar_url":"https://avatars.githubusercontent.com/u/9133420?v=3","gravatar_id":"","url":"https://api.github.com/users/eksperimental","html_url":"https://github.com/eksperimental","followers_url":"https://api.github.com/users/eksperimental/followers","following_url":"https://api.github.com/users/eksperimental/following{/other_user}","gists_url":"https://api.github.com/users/eksperimental/gists{/gist_id}","starred_url":"https://api.github.com/users/eksperimental/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eksperimental/subscriptions","organizations_url":"https://api.github.com/users/eksperimental/orgs","repos_url":"https://api.github.com/users/eksperimental/repos","events_url":"https://api.github.com/users/eksperimental/events{/privacy}","received_events_url":"https://api.github.com/users/eksperimental/received_events","type":"User","site_admin":false},"body":"This PR does a few things all related to the git version that is shown in the elixir version\r\n\r\n- \"mix --version\" shows the hash id, same as elixir and iex\r\n- A new a function added (System.build_info/1) retrieves the string to display in \"elixir --version\" and friends.\r\n- System.read_stripped/1 fixed to properly deal with \\r, \\n and \\t (not only with white spaces). This solves the problem that VERSION cannot end in a new line\r\n- System.get_revision/0 returns the long hash now (instead of the short one)\r\nI think it's better to return the original one, and then when we display it shortening it, as it may be needed, for example linking to the github commit_id which uses the long one.\r\nthis could be considered a backward incompatible change.\r\n- System.get_revision/0 also returns the git tag.\r\n- Make file, functions created to retrieve the git tag and revision\r\n- Makefile: in the current version `git` is a requirement if we want to build docs (when it should not), and if git is not installed, Makefile will complain. With these changes, git will fail silently if not installed.","created_at":"2016-02-12T21:29:12Z","updated_at":"2016-02-15T14:29:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"54c7f5fc1184e4c88d5ee660cef6e61167a0033f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296/commits","review_comments_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296/comments","review_comment_url":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4296/comments","statuses_url":"https://api.github.com/repos/elixir-lang/elixir/statuses/c4d5744bf8bc6ade89262448994f6dbb80741faa","head":{"label":"eksperimental:git_revision","ref":"git_revision","sha":"c4d5744bf8bc6ade89262448994f6dbb80741faa","user":{"login":"eksperimental","id":9133420,"avatar_url":"https://avatars.githubusercontent.com/u/9133420?v=3","gravatar_id":"","url":"https://api.github.com/users/eksperimental","html_url":"https://github.com/eksperimental","followers_url":"https://api.github.com/users/eksperimental/followers","following_url":"https://api.github.com/users/eksperimental/following{/other_user}","gists_url":"https://api.github.com/users/eksperimental/gists{/gist_id}","starred_url":"https://api.github.com/users/eksperimental/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eksperimental/subscriptions","organizations_url":"https://api.github.com/users/eksperimental/orgs","repos_url":"https://api.github.com/users/eksperimental/repos","events_url":"https://api.github.com/users/eksperimental/events{/privacy}","received_events_url":"https://api.github.com/users/eksperimental/received_events","type":"User","site_admin":false},"repo":{"id":25033185,"name":"elixir","full_name":"eksperimental/elixir","owner":{"login":"eksperimental","id":9133420,"avatar_url":"https://avatars.githubusercontent.com/u/9133420?v=3","gravatar_id":"","url":"https://api.github.com/users/eksperimental","html_url":"https://github.com/eksperimental","followers_url":"https://api.github.com/users/eksperimental/followers","following_url":"https://api.github.com/users/eksperimental/following{/other_user}","gists_url":"https://api.github.com/users/eksperimental/gists{/gist_id}","starred_url":"https://api.github.com/users/eksperimental/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eksperimental/subscriptions","organizations_url":"https://api.github.com/users/eksperimental/orgs","repos_url":"https://api.github.com/users/eksperimental/repos","events_url":"https://api.github.com/users/eksperimental/events{/privacy}","received_events_url":"https://api.github.com/users/eksperimental/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eksperimental/elixir","description":"Elixir is a dynamic, functional language designed for building scalable and maintainable applications","fork":true,"url":"https://api.github.com/repos/eksperimental/elixir","forks_url":"https://api.github.com/repos/eksperimental/elixir/forks","keys_url":"https://api.github.com/repos/eksperimental/elixir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eksperimental/elixir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eksperimental/elixir/teams","hooks_url":"https://api.github.com/repos/eksperimental/elixir/hooks","issue_events_url":"https://api.github.com/repos/eksperimental/elixir/issues/events{/number}","events_url":"https://api.github.com/repos/eksperimental/elixir/events","assignees_url":"https://api.github.com/repos/eksperimental/elixir/assignees{/user}","branches_url":"https://api.github.com/repos/eksperimental/elixir/branches{/branch}","tags_url":"https://api.github.com/repos/eksperimental/elixir/tags","blobs_url":"https://api.github.com/repos/eksperimental/elixir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eksperimental/elixir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eksperimental/elixir/git/refs{/sha}","trees_url":"https://api.github.com/repos/eksperimental/elixir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eksperimental/elixir/statuses/{sha}","languages_url":"https://api.github.com/repos/eksperimental/elixir/languages","stargazers_url":"https://api.github.com/repos/eksperimental/elixir/stargazers","contributors_url":"https://api.github.com/repos/eksperimental/elixir/contributors","subscribers_url":"https://api.github.com/repos/eksperimental/elixir/subscribers","subscription_url":"https://api.github.com/repos/eksperimental/elixir/subscription","commits_url":"https://api.github.com/repos/eksperimental/elixir/commits{/sha}","git_commits_url":"https://api.github.com/repos/eksperimental/elixir/git/commits{/sha}","comments_url":"https://api.github.com/repos/eksperimental/elixir/comments{/number}","issue_comment_url":"https://api.github.com/repos/eksperimental/elixir/issues/comments{/number}","contents_url":"https://api.github.com/repos/eksperimental/elixir/contents/{+path}","compare_url":"https://api.github.com/repos/eksperimental/elixir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eksperimental/elixir/merges","archive_url":"https://api.github.com/repos/eksperimental/elixir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eksperimental/elixir/downloads","issues_url":"https://api.github.com/repos/eksperimental/elixir/issues{/number}","pulls_url":"https://api.github.com/repos/eksperimental/elixir/pulls{/number}","milestones_url":"https://api.github.com/repos/eksperimental/elixir/milestones{/number}","notifications_url":"https://api.github.com/repos/eksperimental/elixir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eksperimental/elixir/labels{/name}","releases_url":"https://api.github.com/repos/eksperimental/elixir/releases{/id}","deployments_url":"https://api.github.com/repos/eksperimental/elixir/deployments","created_at":"2014-10-10T11:48:55Z","updated_at":"2015-02-14T08:24:55Z","pushed_at":"2016-02-15T05:10:54Z","git_url":"git://github.com/eksperimental/elixir.git","ssh_url":"git@github.com:eksperimental/elixir.git","clone_url":"https://github.com/eksperimental/elixir.git","svn_url":"https://github.com/eksperimental/elixir","homepage":"http://elixir-lang.org/","size":33521,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"elixir-lang:master","ref":"master","sha":"0407ddc386d7e066f6a57830988881e0a48a8141","user":{"login":"elixir-lang","id":1481354,"avatar_url":"https://avatars.githubusercontent.com/u/1481354?v=3","gravatar_id":"","url":"https://api.github.com/users/elixir-lang","html_url":"https://github.com/elixir-lang","followers_url":"https://api.github.com/users/elixir-lang/followers","following_url":"https://api.github.com/users/elixir-lang/following{/other_user}","gists_url":"https://api.github.com/users/elixir-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/elixir-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elixir-lang/subscriptions","organizations_url":"https://api.github.com/users/elixir-lang/orgs","repos_url":"https://api.github.com/users/elixir-lang/repos","events_url":"https://api.github.com/users/elixir-lang/events{/privacy}","received_events_url":"https://api.github.com/users/elixir-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":1234714,"name":"elixir","full_name":"elixir-lang/elixir","owner":{"login":"elixir-lang","id":1481354,"avatar_url":"https://avatars.githubusercontent.com/u/1481354?v=3","gravatar_id":"","url":"https://api.github.com/users/elixir-lang","html_url":"https://github.com/elixir-lang","followers_url":"https://api.github.com/users/elixir-lang/followers","following_url":"https://api.github.com/users/elixir-lang/following{/other_user}","gists_url":"https://api.github.com/users/elixir-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/elixir-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elixir-lang/subscriptions","organizations_url":"https://api.github.com/users/elixir-lang/orgs","repos_url":"https://api.github.com/users/elixir-lang/repos","events_url":"https://api.github.com/users/elixir-lang/events{/privacy}","received_events_url":"https://api.github.com/users/elixir-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elixir-lang/elixir","description":"Elixir is a dynamic, functional language designed for building scalable and maintainable applications","fork":false,"url":"https://api.github.com/repos/elixir-lang/elixir","forks_url":"https://api.github.com/repos/elixir-lang/elixir/forks","keys_url":"https://api.github.com/repos/elixir-lang/elixir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elixir-lang/elixir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elixir-lang/elixir/teams","hooks_url":"https://api.github.com/repos/elixir-lang/elixir/hooks","issue_events_url":"https://api.github.com/repos/elixir-lang/elixir/issues/events{/number}","events_url":"https://api.github.com/repos/elixir-lang/elixir/events","assignees_url":"https://api.github.com/repos/elixir-lang/elixir/assignees{/user}","branches_url":"https://api.github.com/repos/elixir-lang/elixir/branches{/branch}","tags_url":"https://api.github.com/repos/elixir-lang/elixir/tags","blobs_url":"https://api.github.com/repos/elixir-lang/elixir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elixir-lang/elixir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elixir-lang/elixir/git/refs{/sha}","trees_url":"https://api.github.com/repos/elixir-lang/elixir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elixir-lang/elixir/statuses/{sha}","languages_url":"https://api.github.com/repos/elixir-lang/elixir/languages","stargazers_url":"https://api.github.com/repos/elixir-lang/elixir/stargazers","contributors_url":"https://api.github.com/repos/elixir-lang/elixir/contributors","subscribers_url":"https://api.github.com/repos/elixir-lang/elixir/subscribers","subscription_url":"https://api.github.com/repos/elixir-lang/elixir/subscription","commits_url":"https://api.github.com/repos/elixir-lang/elixir/commits{/sha}","git_commits_url":"https://api.github.com/repos/elixir-lang/elixir/git/commits{/sha}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/comments{/number}","issue_comment_url":"https://api.github.com/repos/elixir-lang/elixir/issues/comments{/number}","contents_url":"https://api.github.com/repos/elixir-lang/elixir/contents/{+path}","compare_url":"https://api.github.com/repos/elixir-lang/elixir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elixir-lang/elixir/merges","archive_url":"https://api.github.com/repos/elixir-lang/elixir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elixir-lang/elixir/downloads","issues_url":"https://api.github.com/repos/elixir-lang/elixir/issues{/number}","pulls_url":"https://api.github.com/repos/elixir-lang/elixir/pulls{/number}","milestones_url":"https://api.github.com/repos/elixir-lang/elixir/milestones{/number}","notifications_url":"https://api.github.com/repos/elixir-lang/elixir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elixir-lang/elixir/labels{/name}","releases_url":"https://api.github.com/repos/elixir-lang/elixir/releases{/id}","deployments_url":"https://api.github.com/repos/elixir-lang/elixir/deployments","created_at":"2011-01-09T08:43:57Z","updated_at":"2016-02-15T13:58:31Z","pushed_at":"2016-02-15T11:42:15Z","git_url":"git://github.com/elixir-lang/elixir.git","ssh_url":"git@github.com:elixir-lang/elixir.git","clone_url":"https://github.com/elixir-lang/elixir.git","svn_url":"https://github.com/elixir-lang/elixir","homepage":"http://elixir-lang.org/","size":41710,"stargazers_count":6266,"watchers_count":6266,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":859,"mirror_url":null,"open_issues_count":46,"forks":859,"open_issues":46,"watchers":6266,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296"},"html":{"href":"https://github.com/elixir-lang/elixir/pull/4296"},"issue":{"href":"https://api.github.com/repos/elixir-lang/elixir/issues/4296"},"comments":{"href":"https://api.github.com/repos/elixir-lang/elixir/issues/4296/comments"},"review_comments":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296/comments"},"review_comment":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elixir-lang/elixir/pulls/4296/commits"},"statuses":{"href":"https://api.github.com/repos/elixir-lang/elixir/statuses/c4d5744bf8bc6ade89262448994f6dbb80741faa"}}}}