{"action":"created","comment":{"url":"https://api.github.com/repos/libgit2/rugged/pulls/comments/52684594","id":52684594,"diff_hunk":"@@ -0,0 +1,263 @@\n+/*\n+ * The MIT License\n+ *\n+ * Copyright (c) 2016 GitHub, Inc\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+\n+#include \"rugged.h\"\n+\n+extern VALUE rb_mRugged;\n+extern VALUE rb_cRuggedTagAnnotation;\n+extern VALUE rb_cRuggedTree;\n+extern VALUE rb_cRuggedCommit;\n+extern VALUE rb_cRuggedBlob;\n+extern VALUE rb_cRuggedRepo;\n+\n+VALUE rb_cRuggedRebase;\n+VALUE rb_cRuggedRebaseOperation;\n+\n+VALUE ruged_rebase_operation_new(git_rebase_operation *operation, VALUE owner);\n+\n+static void parse_rebase_options(git_rebase_options *ret, VALUE rb_options)\n+{\n+\tVALUE val;\n+\n+\tif (NIL_P(rb_options))\n+\t\treturn;\n+\n+\tval = rb_hash_aref(rb_options, CSTR2SYM(\"quiet\"));\n+\tif (RTEST(val))\n+\t\tret->quiet = 1;\n+\n+\tval = rb_hash_aref(rb_options, CSTR2SYM(\"rewrite_notes_ref\"));\n+\tif (!NIL_P(val)) {\n+\t\tCheck_Type(val, T_STRING);\n+\t\tret->rewrite_notes_ref = StringValueCStr(val);\n+\t}\n+\n+\trugged_parse_checkout_options(&ret->checkout_options, rb_options);\n+}\n+\n+void rb_git_rebase__free(git_rebase *rebase)\n+{\n+\tgit_rebase_free(rebase);\n+}\n+\n+VALUE rugged_rebase_new(VALUE klass, VALUE owner, git_rebase *rebase)\n+{\n+\tVALUE rb_rebase = Data_Wrap_Struct(klass, NULL, &rb_git_rebase__free, rebase);\n+\trugged_set_owner(rb_rebase, owner);\n+\treturn rb_rebase;\n+}\n+\n+static VALUE rb_git_rebase_new(int argc, VALUE* argv, VALUE klass)\n+{\n+\tint error;\n+\tgit_rebase *rebase;\n+\tgit_repository *repo;\n+\tgit_annotated_commit *branch = NULL, *upstream = NULL, *onto = NULL;\n+\tgit_oid id;\n+\tVALUE rb_repo, rb_branch, rb_upstream, rb_onto, rb_options;\n+\tgit_rebase_options options = GIT_REBASE_OPTIONS_INIT;\n+\n+\trb_scan_args(argc, argv, \"31:\", &rb_repo, &rb_branch, &rb_upstream, &rb_onto, &rb_options);\n+\tData_Get_Struct(rb_repo, git_repository, repo);\n+\tCheck_Type(rb_branch, T_STRING);\n+\tCheck_Type(rb_upstream, T_STRING);\n+\n+\tif ((error = git_oid_fromstr(&id, StringValueCStr(rb_branch))) < 0 ||\n+\t    (error = git_annotated_commit_lookup(&branch, repo, &id)) < 0 ||\n+\t    (error = git_oid_fromstr(&id, StringValueCStr(rb_upstream))) < 0 ||\n+\t    (error = git_annotated_commit_lookup(&upstream, repo, &id)) < 0)\n+\t\tgoto cleanup;\n+\n+\tif (!NIL_P(rb_onto)) {\n+\t\tCheck_Type(rb_onto, T_STRING);\n+\t\tif ((error = git_oid_fromstr(&id, StringValueCStr(rb_onto))) < 0 ||\n+\t\t    (error = git_annotated_commit_lookup(&onto, repo, &id)) < 0)\n+\t\t\tgoto cleanup;\n+\t}\n+\n+\tparse_rebase_options(&options, rb_options);\n+\terror = git_rebase_init(&rebase, repo, branch, upstream, onto, &options);\n+\n+cleanup:\n+\tgit_annotated_commit_free(branch);\n+\tgit_annotated_commit_free(upstream);\n+\tgit_annotated_commit_free(onto);\n+\n+\trugged_exception_check(error);\n+\n+\treturn rugged_rebase_new(klass, rb_repo, rebase);\n+}\n+\n+static VALUE rb_git_rebase_next(VALUE self)\n+{\n+\tint error;\n+\tgit_rebase *rebase;\n+\tgit_rebase_operation *operation;\n+\n+\tData_Get_Struct(self, git_rebase, rebase);\n+\terror = git_rebase_next(&operation, rebase);\n+\tif (error == GIT_ITEROVER)\n+\t\treturn Qnil;\n+\n+\trugged_exception_check(error);\n+\n+\treturn ruged_rebase_operation_new(operation, self);\n+}\n+\n+static VALUE rb_git_rebase_commit(VALUE self, VALUE rb_author, VALUE rb_committer, VALUE rb_message)\n+{\n+\tint error;\n+\tgit_oid id;\n+\tgit_rebase *rebase;\n+\tgit_signature *author = NULL, *committer;\n+\tconst char *message = NULL;\n+\n+\tData_Get_Struct(self, git_rebase, rebase);\n+\tif (!NIL_P(rb_message)) {\n+\t\tCheck_Type(rb_message, T_STRING);\n+\t\tmessage = StringValueCStr(rb_message);\n+\t}\n+\n+\tif (NIL_P(rb_committer))\n+\t\trb_raise(rb_eArgError, \"Expected non-nil committer\");\n+\telse\n+\t\tcommitter = rugged_signature_get(rb_committer, NULL);\n+\n+\tif (!NIL_P(rb_author))\n+\t\tauthor = rugged_signature_get(rb_author, NULL);","path":"ext/rugged/rugged_rebase.c","position":150,"original_position":148,"commit_id":"b96f82297842840726fc15cef7040337553f734a","original_commit_id":"0c2e9b29db8a04a6eec7b117d921e3f70bc9c043","user":{"login":"arthurschreiber","id":2195,"avatar_url":"https://avatars.githubusercontent.com/u/2195?v=3","gravatar_id":"","url":"https://api.github.com/users/arthurschreiber","html_url":"https://github.com/arthurschreiber","followers_url":"https://api.github.com/users/arthurschreiber/followers","following_url":"https://api.github.com/users/arthurschreiber/following{/other_user}","gists_url":"https://api.github.com/users/arthurschreiber/gists{/gist_id}","starred_url":"https://api.github.com/users/arthurschreiber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arthurschreiber/subscriptions","organizations_url":"https://api.github.com/users/arthurschreiber/orgs","repos_url":"https://api.github.com/users/arthurschreiber/repos","events_url":"https://api.github.com/users/arthurschreiber/events{/privacy}","received_events_url":"https://api.github.com/users/arthurschreiber/received_events","type":"User","site_admin":false},"body":"Yes, I've been thinking about this today after my first comment. If you want to catch a Ruby Exception in C-Land, you need to wrap the call using `VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*);`.\r\n\r\nWe could add wrapper functions for things like `rugged_signature_get` that take all arguments, stash them into a struct, pass this down `rb_protect` with another function that unwraps that struct and calls the original `rugged_signature_get` again.\r\n\r\nBut that feels really convoluted and wasteful. You might apply some macro magic to make this look nicer, but the wrapping/unwrapping would still be there.\r\n\r\nAnother approach would be to split functions like `rugged_signature_get` into 2 separate functions like `rugged_signature_check` (which performs all the checks) and `rugged_signature_get` (which performs none of the checks and only handles conversion).\r\n\r\nI think I favor the latter approach.","created_at":"2016-02-11T23:23:36Z","updated_at":"2016-02-11T23:23:36Z","html_url":"https://github.com/libgit2/rugged/pull/572#discussion_r52684594","pull_request_url":"https://api.github.com/repos/libgit2/rugged/pulls/572","_links":{"self":{"href":"https://api.github.com/repos/libgit2/rugged/pulls/comments/52684594"},"html":{"href":"https://github.com/libgit2/rugged/pull/572#discussion_r52684594"},"pull_request":{"href":"https://api.github.com/repos/libgit2/rugged/pulls/572"}}},"pull_request":{"url":"https://api.github.com/repos/libgit2/rugged/pulls/572","id":59014561,"html_url":"https://github.com/libgit2/rugged/pull/572","diff_url":"https://github.com/libgit2/rugged/pull/572.diff","patch_url":"https://github.com/libgit2/rugged/pull/572.patch","issue_url":"https://api.github.com/repos/libgit2/rugged/issues/572","number":572,"state":"open","locked":false,"title":"[WIP] Introduce rebasing","user":{"login":"carlosmn","id":335443,"avatar_url":"https://avatars.githubusercontent.com/u/335443?v=3","gravatar_id":"","url":"https://api.github.com/users/carlosmn","html_url":"https://github.com/carlosmn","followers_url":"https://api.github.com/users/carlosmn/followers","following_url":"https://api.github.com/users/carlosmn/following{/other_user}","gists_url":"https://api.github.com/users/carlosmn/gists{/gist_id}","starred_url":"https://api.github.com/users/carlosmn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlosmn/subscriptions","organizations_url":"https://api.github.com/users/carlosmn/orgs","repos_url":"https://api.github.com/users/carlosmn/repos","events_url":"https://api.github.com/users/carlosmn/events{/privacy}","received_events_url":"https://api.github.com/users/carlosmn/received_events","type":"User","site_admin":true},"body":"Introduce the Rugged::Rebase and Rugged::RebaseOperation types to expose\r\nthe library's rebasing capabilities.\r\n\r\n---\r\n\r\nNo tests yet, just wanna get the overall feature out there, since I think this is the first time I'm not just tweaking the existing types.\r\n\r\nOne thing I'm not quite sure about is what to do with `git_rebase_operation`. It's a very simple struct, so maybe we can put that into ruby code and initialize it from the C code. Does that work? Does MRI memoize the symbols I'm returning for the type or should we store them? Should we use subclassing here instead of a type?","created_at":"2016-02-11T10:53:01Z","updated_at":"2016-02-11T23:23:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0ceedc8a34691729baaf3185166c57c455504879","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/libgit2/rugged/pulls/572/commits","review_comments_url":"https://api.github.com/repos/libgit2/rugged/pulls/572/comments","review_comment_url":"https://api.github.com/repos/libgit2/rugged/pulls/comments{/number}","comments_url":"https://api.github.com/repos/libgit2/rugged/issues/572/comments","statuses_url":"https://api.github.com/repos/libgit2/rugged/statuses/b96f82297842840726fc15cef7040337553f734a","head":{"label":"libgit2:cmn/rebase","ref":"cmn/rebase","sha":"b96f82297842840726fc15cef7040337553f734a","user":{"login":"libgit2","id":394745,"avatar_url":"https://avatars.githubusercontent.com/u/394745?v=3","gravatar_id":"","url":"https://api.github.com/users/libgit2","html_url":"https://github.com/libgit2","followers_url":"https://api.github.com/users/libgit2/followers","following_url":"https://api.github.com/users/libgit2/following{/other_user}","gists_url":"https://api.github.com/users/libgit2/gists{/gist_id}","starred_url":"https://api.github.com/users/libgit2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libgit2/subscriptions","organizations_url":"https://api.github.com/users/libgit2/orgs","repos_url":"https://api.github.com/users/libgit2/repos","events_url":"https://api.github.com/users/libgit2/events{/privacy}","received_events_url":"https://api.github.com/users/libgit2/received_events","type":"Organization","site_admin":false},"repo":{"id":901663,"name":"rugged","full_name":"libgit2/rugged","owner":{"login":"libgit2","id":394745,"avatar_url":"https://avatars.githubusercontent.com/u/394745?v=3","gravatar_id":"","url":"https://api.github.com/users/libgit2","html_url":"https://github.com/libgit2","followers_url":"https://api.github.com/users/libgit2/followers","following_url":"https://api.github.com/users/libgit2/following{/other_user}","gists_url":"https://api.github.com/users/libgit2/gists{/gist_id}","starred_url":"https://api.github.com/users/libgit2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libgit2/subscriptions","organizations_url":"https://api.github.com/users/libgit2/orgs","repos_url":"https://api.github.com/users/libgit2/repos","events_url":"https://api.github.com/users/libgit2/events{/privacy}","received_events_url":"https://api.github.com/users/libgit2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/libgit2/rugged","description":"ruby bindings to libgit2","fork":false,"url":"https://api.github.com/repos/libgit2/rugged","forks_url":"https://api.github.com/repos/libgit2/rugged/forks","keys_url":"https://api.github.com/repos/libgit2/rugged/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libgit2/rugged/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libgit2/rugged/teams","hooks_url":"https://api.github.com/repos/libgit2/rugged/hooks","issue_events_url":"https://api.github.com/repos/libgit2/rugged/issues/events{/number}","events_url":"https://api.github.com/repos/libgit2/rugged/events","assignees_url":"https://api.github.com/repos/libgit2/rugged/assignees{/user}","branches_url":"https://api.github.com/repos/libgit2/rugged/branches{/branch}","tags_url":"https://api.github.com/repos/libgit2/rugged/tags","blobs_url":"https://api.github.com/repos/libgit2/rugged/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libgit2/rugged/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libgit2/rugged/git/refs{/sha}","trees_url":"https://api.github.com/repos/libgit2/rugged/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libgit2/rugged/statuses/{sha}","languages_url":"https://api.github.com/repos/libgit2/rugged/languages","stargazers_url":"https://api.github.com/repos/libgit2/rugged/stargazers","contributors_url":"https://api.github.com/repos/libgit2/rugged/contributors","subscribers_url":"https://api.github.com/repos/libgit2/rugged/subscribers","subscription_url":"https://api.github.com/repos/libgit2/rugged/subscription","commits_url":"https://api.github.com/repos/libgit2/rugged/commits{/sha}","git_commits_url":"https://api.github.com/repos/libgit2/rugged/git/commits{/sha}","comments_url":"https://api.github.com/repos/libgit2/rugged/comments{/number}","issue_comment_url":"https://api.github.com/repos/libgit2/rugged/issues/comments{/number}","contents_url":"https://api.github.com/repos/libgit2/rugged/contents/{+path}","compare_url":"https://api.github.com/repos/libgit2/rugged/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libgit2/rugged/merges","archive_url":"https://api.github.com/repos/libgit2/rugged/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libgit2/rugged/downloads","issues_url":"https://api.github.com/repos/libgit2/rugged/issues{/number}","pulls_url":"https://api.github.com/repos/libgit2/rugged/pulls{/number}","milestones_url":"https://api.github.com/repos/libgit2/rugged/milestones{/number}","notifications_url":"https://api.github.com/repos/libgit2/rugged/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libgit2/rugged/labels{/name}","releases_url":"https://api.github.com/repos/libgit2/rugged/releases{/id}","deployments_url":"https://api.github.com/repos/libgit2/rugged/deployments","created_at":"2010-09-10T16:18:17Z","updated_at":"2016-02-11T17:46:44Z","pushed_at":"2016-02-11T22:51:12Z","git_url":"git://github.com/libgit2/rugged.git","ssh_url":"git@github.com:libgit2/rugged.git","clone_url":"https://github.com/libgit2/rugged.git","svn_url":"https://github.com/libgit2/rugged","homepage":"","size":19821,"stargazers_count":1596,"watchers_count":1596,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":207,"mirror_url":null,"open_issues_count":30,"forks":207,"open_issues":30,"watchers":1596,"default_branch":"master"}},"base":{"label":"libgit2:master","ref":"master","sha":"8544b4faa3b6b0daa96a91121443db2dcbb95996","user":{"login":"libgit2","id":394745,"avatar_url":"https://avatars.githubusercontent.com/u/394745?v=3","gravatar_id":"","url":"https://api.github.com/users/libgit2","html_url":"https://github.com/libgit2","followers_url":"https://api.github.com/users/libgit2/followers","following_url":"https://api.github.com/users/libgit2/following{/other_user}","gists_url":"https://api.github.com/users/libgit2/gists{/gist_id}","starred_url":"https://api.github.com/users/libgit2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libgit2/subscriptions","organizations_url":"https://api.github.com/users/libgit2/orgs","repos_url":"https://api.github.com/users/libgit2/repos","events_url":"https://api.github.com/users/libgit2/events{/privacy}","received_events_url":"https://api.github.com/users/libgit2/received_events","type":"Organization","site_admin":false},"repo":{"id":901663,"name":"rugged","full_name":"libgit2/rugged","owner":{"login":"libgit2","id":394745,"avatar_url":"https://avatars.githubusercontent.com/u/394745?v=3","gravatar_id":"","url":"https://api.github.com/users/libgit2","html_url":"https://github.com/libgit2","followers_url":"https://api.github.com/users/libgit2/followers","following_url":"https://api.github.com/users/libgit2/following{/other_user}","gists_url":"https://api.github.com/users/libgit2/gists{/gist_id}","starred_url":"https://api.github.com/users/libgit2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libgit2/subscriptions","organizations_url":"https://api.github.com/users/libgit2/orgs","repos_url":"https://api.github.com/users/libgit2/repos","events_url":"https://api.github.com/users/libgit2/events{/privacy}","received_events_url":"https://api.github.com/users/libgit2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/libgit2/rugged","description":"ruby bindings to libgit2","fork":false,"url":"https://api.github.com/repos/libgit2/rugged","forks_url":"https://api.github.com/repos/libgit2/rugged/forks","keys_url":"https://api.github.com/repos/libgit2/rugged/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libgit2/rugged/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libgit2/rugged/teams","hooks_url":"https://api.github.com/repos/libgit2/rugged/hooks","issue_events_url":"https://api.github.com/repos/libgit2/rugged/issues/events{/number}","events_url":"https://api.github.com/repos/libgit2/rugged/events","assignees_url":"https://api.github.com/repos/libgit2/rugged/assignees{/user}","branches_url":"https://api.github.com/repos/libgit2/rugged/branches{/branch}","tags_url":"https://api.github.com/repos/libgit2/rugged/tags","blobs_url":"https://api.github.com/repos/libgit2/rugged/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libgit2/rugged/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libgit2/rugged/git/refs{/sha}","trees_url":"https://api.github.com/repos/libgit2/rugged/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libgit2/rugged/statuses/{sha}","languages_url":"https://api.github.com/repos/libgit2/rugged/languages","stargazers_url":"https://api.github.com/repos/libgit2/rugged/stargazers","contributors_url":"https://api.github.com/repos/libgit2/rugged/contributors","subscribers_url":"https://api.github.com/repos/libgit2/rugged/subscribers","subscription_url":"https://api.github.com/repos/libgit2/rugged/subscription","commits_url":"https://api.github.com/repos/libgit2/rugged/commits{/sha}","git_commits_url":"https://api.github.com/repos/libgit2/rugged/git/commits{/sha}","comments_url":"https://api.github.com/repos/libgit2/rugged/comments{/number}","issue_comment_url":"https://api.github.com/repos/libgit2/rugged/issues/comments{/number}","contents_url":"https://api.github.com/repos/libgit2/rugged/contents/{+path}","compare_url":"https://api.github.com/repos/libgit2/rugged/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libgit2/rugged/merges","archive_url":"https://api.github.com/repos/libgit2/rugged/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libgit2/rugged/downloads","issues_url":"https://api.github.com/repos/libgit2/rugged/issues{/number}","pulls_url":"https://api.github.com/repos/libgit2/rugged/pulls{/number}","milestones_url":"https://api.github.com/repos/libgit2/rugged/milestones{/number}","notifications_url":"https://api.github.com/repos/libgit2/rugged/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libgit2/rugged/labels{/name}","releases_url":"https://api.github.com/repos/libgit2/rugged/releases{/id}","deployments_url":"https://api.github.com/repos/libgit2/rugged/deployments","created_at":"2010-09-10T16:18:17Z","updated_at":"2016-02-11T17:46:44Z","pushed_at":"2016-02-11T22:51:12Z","git_url":"git://github.com/libgit2/rugged.git","ssh_url":"git@github.com:libgit2/rugged.git","clone_url":"https://github.com/libgit2/rugged.git","svn_url":"https://github.com/libgit2/rugged","homepage":"","size":19821,"stargazers_count":1596,"watchers_count":1596,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":207,"mirror_url":null,"open_issues_count":30,"forks":207,"open_issues":30,"watchers":1596,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/libgit2/rugged/pulls/572"},"html":{"href":"https://github.com/libgit2/rugged/pull/572"},"issue":{"href":"https://api.github.com/repos/libgit2/rugged/issues/572"},"comments":{"href":"https://api.github.com/repos/libgit2/rugged/issues/572/comments"},"review_comments":{"href":"https://api.github.com/repos/libgit2/rugged/pulls/572/comments"},"review_comment":{"href":"https://api.github.com/repos/libgit2/rugged/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/libgit2/rugged/pulls/572/commits"},"statuses":{"href":"https://api.github.com/repos/libgit2/rugged/statuses/b96f82297842840726fc15cef7040337553f734a"}}}}