{"action":"created","comment":{"url":"https://api.github.com/repos/chromium/axiom/pulls/comments/29714393","id":29714393,"diff_hunk":"@@ -0,0 +1,319 @@\n+// Copyright 2015 Google Inc. All rights reserved.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+// Run a local proxy server to inject CORS headers.\n+// TODO(grv): Host a live server on app engine.\n+var PROXY_SERVER_URL = 'pepper_http://localhost:8080/';\n+var GIT_NMF_FILE_PATH = 'scripts/resources/git';\n+\n+// The subject field sent with each message to identify it.\n+var messageId = 1;\n+\n+document.currentScript.ready(function(cx) {\n+  var GIT_CMD_USAGE_STRING = 'usage: git [options]';\n+\n+  /**\n+   * @return {void}\n+   */\n+  var gitMain = function(cx) {\n+    cx.ready();\n+\n+    /** @type {Array<string>} */\n+    var list = cx.getArg('_', []);\n+    if (list.length != 3 || cx.getArg('help')) {\n+      cx.stdout.write(GIT_CMD_USAGE_STRING + '\\n');\n+      return cx.closeOk();\n+    }\n+\n+    createMessage(cx).then(function(message) {\n+      /** @type {GitSalt} */\n+      var git = new GitSalt();\n+\n+      git.loadPlugin('git_salt', GIT_NMF_FILE_PATH).then(function() {\n+        var cb = createMessageCallback(cx, message);\n+        git.postMessage(message, cb);\n+      }).catch(function(e) {\n+        cx.closeError(e);\n+      });\n+    });\n+  };\n+\n+  gitMain.signature = {\n+    'help|h': '?',\n+    '_': '@'\n+  };\n+\n+  var installGit = function(cx) {\n+    var path = new axiom.fs.path.Path('jsfs:/exe');\n+    var jsDir = cx.jsfs.resolve(path).entry;\n+    jsDir.install({\n+      'git': gitMain\n+    });\n+  };\n+  installGit(cx);\n+});\n+\n+function genMessageId() {\n+ messageId++;\n+ return messageId.toString();\n+}\n+\n+function createMessage(cx) {\n+  var message = {};\n+  var args = {};\n+  var list = cx.getArg('_', []);\n+  var command = list.shift();\n+  var path;\n+\n+  // TODO(grv): Make the check case insensitive.\n+  if (command == 'clone' && list.length == 2) {\n+    message['name'] = 'clone';\n+    args['url'] = PROXY_SERVER_URL + list.shift();\n+\n+    // TODO(grv): resolve path using pwd instead of taking as argument.\n+    path = new axiom.fs.path.Path(list.shift());\n+  } else {\n+    throw new axiom.core.error.AxiomError.Invalid(\n+        'Invalid arguments to git.', []);\n+  }\n+\n+  return cx.fileSystemManager.mkdir(path).then(function(dir) {\n+    args['filesystem'] = dir.filesystem;\n+    args['fullPath'] = dir.fullPath;\n+    message['subject'] = genMessageId();\n+    message.arg = args;\n+    return message;\n+  });\n+}\n+\n+function createMessageCallback(cx, message) {\n+  var cb = function(result) {\n+    console.log(message['name'] + ' command successful!');\n+    cx.closeOk();\n+  };\n+  return cb;\n+}\n+\n+/**\n+ *@constructor\n+ */\n+var GitSalt = function() {\n+  this.callbacks = new Object();\n+};\n+\n+GitSalt.prototype.listenerDiv = null;\n+\n+GitSalt.prototype.loadPromise = null;\n+\n+GitSalt.prototype.callbacks = {};\n+\n+/**\n+ * Create the Native Client <embed> element as a child of the DOM element\n+ * named \"listener\".\n+ *\n+ * @param {string} name The name of the example.\n+ * @param {string} path Directory name where .nmf file can be found.\n+ */\n+GitSalt.prototype.createNaClModule = function(name, path) {\n+  return new Promise(function(resolve, reject) {\n+    this.loadPromise = resolve;\n+    var moduleEl = document.createElement('embed');\n+    moduleEl.setAttribute('width', 0);\n+    moduleEl.setAttribute('height', 0);\n+    moduleEl.setAttribute('path', path);\n+    moduleEl.setAttribute('src', path + '/' + name + '.nmf');\n+\n+    moduleEl.setAttribute('type', \"application/x-pnacl\");\n+    this.naclModule = moduleEl;\n+\n+    // The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'\n+    // and a 'message' event listener attached.  This wrapping method is used\n+    // instead of attaching the event listeners directly to the <EMBED> element\n+    // to ensure that the listeners are active before the NaCl module 'load'\n+    // event fires.\n+    this.listenerDiv.appendChild(moduleEl);\n+  }.bind(this));\n+};\n+\n+GitSalt.prototype.statusText = 'NO-STATUSES';\n+\n+GitSalt.prototype.updateStatus = function(opt_message) {\n+  if (opt_message) {\n+    statusText = opt_message;\n+  }\n+}\n+\n+/**\n+ * Add the default \"load\" and \"message\" event listeners to the element with\n+ * id \"listener\".\n+ *\n+ * The \"load\" event is sent when the module is successfully loaded. The\n+ * \"message\" event is sent when the naclModule posts a message using\n+ * PPB_Messaging.PostMessage() (in C) or pp::Instance().PostMessage() (in\n+ * C++).\n+ */\n+GitSalt.prototype.attachDefaultListeners = function() {\n+  this.listenerDiv.addEventListener('load', this.moduleDidLoad.bind(this), true);\n+  this.listenerDiv.addEventListener('message', this.handleMessage.bind(this), true);\n+  this.listenerDiv.addEventListener('error', this.handleError.bind(this), true);\n+  this.listenerDiv.addEventListener('crash', this.handleCrash.bind(this), true);\n+};\n+\n+/**\n+ * Called when the NaCl module fails to load.\n+ *\n+ * This event listener is registered in createNaClModule above.\n+ */\n+GitSalt.prototype.handleError = function(event) {","path":"samples/web_shell/scripts/git.js","position":178,"original_position":178,"commit_id":"3c59045ff01ae190787faca0b4693a743c50e465","original_commit_id":"3c59045ff01ae190787faca0b4693a743c50e465","user":{"login":"rpaquay","id":1087507,"avatar_url":"https://avatars.githubusercontent.com/u/1087507?v=3","gravatar_id":"","url":"https://api.github.com/users/rpaquay","html_url":"https://github.com/rpaquay","followers_url":"https://api.github.com/users/rpaquay/followers","following_url":"https://api.github.com/users/rpaquay/following{/other_user}","gists_url":"https://api.github.com/users/rpaquay/gists{/gist_id}","starred_url":"https://api.github.com/users/rpaquay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpaquay/subscriptions","organizations_url":"https://api.github.com/users/rpaquay/orgs","repos_url":"https://api.github.com/users/rpaquay/repos","events_url":"https://api.github.com/users/rpaquay/events{/privacy}","received_events_url":"https://api.github.com/users/rpaquay/received_events","type":"User","site_admin":false},"body":"Shouldn't we propagate (somehow) the error to cx so we display an error in the wash window?","created_at":"2015-05-05T21:21:04Z","updated_at":"2015-05-05T21:21:04Z","html_url":"https://github.com/chromium/axiom/pull/242#discussion_r29714393","pull_request_url":"https://api.github.com/repos/chromium/axiom/pulls/242","_links":{"self":{"href":"https://api.github.com/repos/chromium/axiom/pulls/comments/29714393"},"html":{"href":"https://github.com/chromium/axiom/pull/242#discussion_r29714393"},"pull_request":{"href":"https://api.github.com/repos/chromium/axiom/pulls/242"}}},"pull_request":{"url":"https://api.github.com/repos/chromium/axiom/pulls/242","id":34211787,"html_url":"https://github.com/chromium/axiom/pull/242","diff_url":"https://github.com/chromium/axiom/pull/242.diff","patch_url":"https://github.com/chromium/axiom/pull/242.patch","issue_url":"https://api.github.com/repos/chromium/axiom/issues/242","number":242,"state":"open","locked":false,"title":"Add git-salt lib and git script ","user":{"login":"gaurave","id":2711803,"avatar_url":"https://avatars.githubusercontent.com/u/2711803?v=3","gravatar_id":"","url":"https://api.github.com/users/gaurave","html_url":"https://github.com/gaurave","followers_url":"https://api.github.com/users/gaurave/followers","following_url":"https://api.github.com/users/gaurave/following{/other_user}","gists_url":"https://api.github.com/users/gaurave/gists{/gist_id}","starred_url":"https://api.github.com/users/gaurave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaurave/subscriptions","organizations_url":"https://api.github.com/users/gaurave/orgs","repos_url":"https://api.github.com/users/gaurave/repos","events_url":"https://api.github.com/users/gaurave/events{/privacy}","received_events_url":"https://api.github.com/users/gaurave/received_events","type":"User","site_admin":false},"body":"* Adds git-salt library to axiom\r\n* Adds a git script to axiom which should act like git command line.\r\n\r\nTODO\r\n* Add parsing in `git` script and route the commands to appropriate API.\r\n* Re-factor code into classes\r\n* Route `stdio` and `stderr` correctly.\r\n\r\n@rpaquay ","created_at":"2015-04-27T21:22:30Z","updated_at":"2015-05-05T21:21:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"28e3b3fc93dbd854bcbbfc3fae51d6febb27ff09","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chromium/axiom/pulls/242/commits","review_comments_url":"https://api.github.com/repos/chromium/axiom/pulls/242/comments","review_comment_url":"https://api.github.com/repos/chromium/axiom/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chromium/axiom/issues/242/comments","statuses_url":"https://api.github.com/repos/chromium/axiom/statuses/3c59045ff01ae190787faca0b4693a743c50e465","head":{"label":"gaurave:git_in_web","ref":"git_in_web","sha":"3c59045ff01ae190787faca0b4693a743c50e465","user":{"login":"gaurave","id":2711803,"avatar_url":"https://avatars.githubusercontent.com/u/2711803?v=3","gravatar_id":"","url":"https://api.github.com/users/gaurave","html_url":"https://github.com/gaurave","followers_url":"https://api.github.com/users/gaurave/followers","following_url":"https://api.github.com/users/gaurave/following{/other_user}","gists_url":"https://api.github.com/users/gaurave/gists{/gist_id}","starred_url":"https://api.github.com/users/gaurave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaurave/subscriptions","organizations_url":"https://api.github.com/users/gaurave/orgs","repos_url":"https://api.github.com/users/gaurave/repos","events_url":"https://api.github.com/users/gaurave/events{/privacy}","received_events_url":"https://api.github.com/users/gaurave/received_events","type":"User","site_admin":false},"repo":{"id":32954785,"name":"axiom-1","full_name":"gaurave/axiom-1","owner":{"login":"gaurave","id":2711803,"avatar_url":"https://avatars.githubusercontent.com/u/2711803?v=3","gravatar_id":"","url":"https://api.github.com/users/gaurave","html_url":"https://github.com/gaurave","followers_url":"https://api.github.com/users/gaurave/followers","following_url":"https://api.github.com/users/gaurave/following{/other_user}","gists_url":"https://api.github.com/users/gaurave/gists{/gist_id}","starred_url":"https://api.github.com/users/gaurave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaurave/subscriptions","organizations_url":"https://api.github.com/users/gaurave/orgs","repos_url":"https://api.github.com/users/gaurave/repos","events_url":"https://api.github.com/users/gaurave/events{/privacy}","received_events_url":"https://api.github.com/users/gaurave/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gaurave/axiom-1","description":"Axiom Project","fork":true,"url":"https://api.github.com/repos/gaurave/axiom-1","forks_url":"https://api.github.com/repos/gaurave/axiom-1/forks","keys_url":"https://api.github.com/repos/gaurave/axiom-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gaurave/axiom-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gaurave/axiom-1/teams","hooks_url":"https://api.github.com/repos/gaurave/axiom-1/hooks","issue_events_url":"https://api.github.com/repos/gaurave/axiom-1/issues/events{/number}","events_url":"https://api.github.com/repos/gaurave/axiom-1/events","assignees_url":"https://api.github.com/repos/gaurave/axiom-1/assignees{/user}","branches_url":"https://api.github.com/repos/gaurave/axiom-1/branches{/branch}","tags_url":"https://api.github.com/repos/gaurave/axiom-1/tags","blobs_url":"https://api.github.com/repos/gaurave/axiom-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gaurave/axiom-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gaurave/axiom-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/gaurave/axiom-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gaurave/axiom-1/statuses/{sha}","languages_url":"https://api.github.com/repos/gaurave/axiom-1/languages","stargazers_url":"https://api.github.com/repos/gaurave/axiom-1/stargazers","contributors_url":"https://api.github.com/repos/gaurave/axiom-1/contributors","subscribers_url":"https://api.github.com/repos/gaurave/axiom-1/subscribers","subscription_url":"https://api.github.com/repos/gaurave/axiom-1/subscription","commits_url":"https://api.github.com/repos/gaurave/axiom-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/gaurave/axiom-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/gaurave/axiom-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/gaurave/axiom-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/gaurave/axiom-1/contents/{+path}","compare_url":"https://api.github.com/repos/gaurave/axiom-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gaurave/axiom-1/merges","archive_url":"https://api.github.com/repos/gaurave/axiom-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gaurave/axiom-1/downloads","issues_url":"https://api.github.com/repos/gaurave/axiom-1/issues{/number}","pulls_url":"https://api.github.com/repos/gaurave/axiom-1/pulls{/number}","milestones_url":"https://api.github.com/repos/gaurave/axiom-1/milestones{/number}","notifications_url":"https://api.github.com/repos/gaurave/axiom-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gaurave/axiom-1/labels{/name}","releases_url":"https://api.github.com/repos/gaurave/axiom-1/releases{/id}","created_at":"2015-03-26T22:16:30Z","updated_at":"2015-03-26T22:16:30Z","pushed_at":"2015-05-05T00:22:38Z","git_url":"git://github.com/gaurave/axiom-1.git","ssh_url":"git@github.com:gaurave/axiom-1.git","clone_url":"https://github.com/gaurave/axiom-1.git","svn_url":"https://github.com/gaurave/axiom-1","homepage":"","size":12738,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"chromium:master","ref":"master","sha":"7c022681dace763c5574dc9395bce00350053a47","user":{"login":"chromium","id":30044,"avatar_url":"https://avatars.githubusercontent.com/u/30044?v=3","gravatar_id":"","url":"https://api.github.com/users/chromium","html_url":"https://github.com/chromium","followers_url":"https://api.github.com/users/chromium/followers","following_url":"https://api.github.com/users/chromium/following{/other_user}","gists_url":"https://api.github.com/users/chromium/gists{/gist_id}","starred_url":"https://api.github.com/users/chromium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chromium/subscriptions","organizations_url":"https://api.github.com/users/chromium/orgs","repos_url":"https://api.github.com/users/chromium/repos","events_url":"https://api.github.com/users/chromium/events{/privacy}","received_events_url":"https://api.github.com/users/chromium/received_events","type":"Organization","site_admin":false},"repo":{"id":29257259,"name":"axiom","full_name":"chromium/axiom","owner":{"login":"chromium","id":30044,"avatar_url":"https://avatars.githubusercontent.com/u/30044?v=3","gravatar_id":"","url":"https://api.github.com/users/chromium","html_url":"https://github.com/chromium","followers_url":"https://api.github.com/users/chromium/followers","following_url":"https://api.github.com/users/chromium/following{/other_user}","gists_url":"https://api.github.com/users/chromium/gists{/gist_id}","starred_url":"https://api.github.com/users/chromium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chromium/subscriptions","organizations_url":"https://api.github.com/users/chromium/orgs","repos_url":"https://api.github.com/users/chromium/repos","events_url":"https://api.github.com/users/chromium/events{/privacy}","received_events_url":"https://api.github.com/users/chromium/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chromium/axiom","description":"Axiom Project","fork":false,"url":"https://api.github.com/repos/chromium/axiom","forks_url":"https://api.github.com/repos/chromium/axiom/forks","keys_url":"https://api.github.com/repos/chromium/axiom/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chromium/axiom/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chromium/axiom/teams","hooks_url":"https://api.github.com/repos/chromium/axiom/hooks","issue_events_url":"https://api.github.com/repos/chromium/axiom/issues/events{/number}","events_url":"https://api.github.com/repos/chromium/axiom/events","assignees_url":"https://api.github.com/repos/chromium/axiom/assignees{/user}","branches_url":"https://api.github.com/repos/chromium/axiom/branches{/branch}","tags_url":"https://api.github.com/repos/chromium/axiom/tags","blobs_url":"https://api.github.com/repos/chromium/axiom/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chromium/axiom/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chromium/axiom/git/refs{/sha}","trees_url":"https://api.github.com/repos/chromium/axiom/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chromium/axiom/statuses/{sha}","languages_url":"https://api.github.com/repos/chromium/axiom/languages","stargazers_url":"https://api.github.com/repos/chromium/axiom/stargazers","contributors_url":"https://api.github.com/repos/chromium/axiom/contributors","subscribers_url":"https://api.github.com/repos/chromium/axiom/subscribers","subscription_url":"https://api.github.com/repos/chromium/axiom/subscription","commits_url":"https://api.github.com/repos/chromium/axiom/commits{/sha}","git_commits_url":"https://api.github.com/repos/chromium/axiom/git/commits{/sha}","comments_url":"https://api.github.com/repos/chromium/axiom/comments{/number}","issue_comment_url":"https://api.github.com/repos/chromium/axiom/issues/comments{/number}","contents_url":"https://api.github.com/repos/chromium/axiom/contents/{+path}","compare_url":"https://api.github.com/repos/chromium/axiom/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chromium/axiom/merges","archive_url":"https://api.github.com/repos/chromium/axiom/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chromium/axiom/downloads","issues_url":"https://api.github.com/repos/chromium/axiom/issues{/number}","pulls_url":"https://api.github.com/repos/chromium/axiom/pulls{/number}","milestones_url":"https://api.github.com/repos/chromium/axiom/milestones{/number}","notifications_url":"https://api.github.com/repos/chromium/axiom/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chromium/axiom/labels{/name}","releases_url":"https://api.github.com/repos/chromium/axiom/releases{/id}","created_at":"2015-01-14T17:48:53Z","updated_at":"2015-05-05T00:22:12Z","pushed_at":"2015-05-05T21:04:47Z","git_url":"git://github.com/chromium/axiom.git","ssh_url":"git@github.com:chromium/axiom.git","clone_url":"https://github.com/chromium/axiom.git","svn_url":"https://github.com/chromium/axiom","homepage":"https://chromium.github.io/axiom/web_shell/","size":15951,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":6,"mirror_url":null,"open_issues_count":44,"forks":6,"open_issues":44,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chromium/axiom/pulls/242"},"html":{"href":"https://github.com/chromium/axiom/pull/242"},"issue":{"href":"https://api.github.com/repos/chromium/axiom/issues/242"},"comments":{"href":"https://api.github.com/repos/chromium/axiom/issues/242/comments"},"review_comments":{"href":"https://api.github.com/repos/chromium/axiom/pulls/242/comments"},"review_comment":{"href":"https://api.github.com/repos/chromium/axiom/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chromium/axiom/pulls/242/commits"},"statuses":{"href":"https://api.github.com/repos/chromium/axiom/statuses/3c59045ff01ae190787faca0b4693a743c50e465"}}}}