| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,18 @@ Commit.prototype.lookup = function(oid, callback) { | |||
| 42 | 42 | }); | |
| 43 | 43 | }; | |
| 44 | 44 | ||
| 45 | + Commit.prototype.oid = function(callback) { | ||
| 46 | + callback(null, new git.oid(this.rawCommit.oid())); | ||
| 47 | + }; | ||
| 48 | + | ||
| 49 | + Commit.prototype.sha = function(callback) { | ||
| 50 | + this.rawCommit.sha(function(error, sha) { | ||
| 51 | + if (success(error, callback)) { | ||
| 52 | + callback(null, sha); | ||
| 53 | + } | ||
| 54 | + }); | ||
| 55 | + }; | ||
| 56 | + | ||
| 45 | 57 | /** | |
| 46 | 58 | * Retrieve the tree for this commit. | |
| 47 | 59 | * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,9 @@ void GitCommit::Initialize(Handle<Object> target) { | |||
| 35 | 35 | tpl->SetClassName(String::NewSymbol("Commit")); | |
| 36 | 36 | ||
| 37 | 37 | NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); | |
| 38 | + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); | ||
| 39 | + NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha); | ||
| 40 | + | ||
| 38 | 41 | NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); | |
| 39 | 42 | ||
| 40 | 43 | NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); | |
@@ -212,17 +215,16 @@ Handle<Value> GitCommit::Lookup(const Arguments& args) { | |||
| 212 | 215 | void GitCommit::LookupWork(uv_work_t *req) { | |
| 213 | 216 | LookupBaton *baton = static_cast<LookupBaton *>(req->data); | |
| 214 | 217 | ||
| 215 | - git_oid rawOid = baton->rawOid; | ||
| 216 | 218 | if (!baton->sha.empty()) { | |
| 217 | - int returnCode = git_oid_fromstr(&rawOid, baton->sha.c_str()); | ||
| 219 | + int returnCode = git_oid_fromstr(&baton->rawOid, baton->sha.c_str()); | ||
| 218 | 220 | if (returnCode != GIT_OK) { | |
| 219 | 221 | baton->error = giterr_last(); | |
| 220 | 222 | return; | |
| 221 | 223 | } | |
| 222 | 224 | } | |
| 223 | 225 | ||
| 224 | 226 | baton->rawCommit = NULL; | |
| 225 | - int returnCode = git_commit_lookup(&baton->rawCommit, baton->repo, &rawOid); | ||
| 227 | + int returnCode = git_commit_lookup(&baton->rawCommit, baton->repo, &baton->rawOid); | ||
| 226 | 228 | if (returnCode != GIT_OK) { | |
| 227 | 229 | baton->error = giterr_last(); | |
| 228 | 230 | } | |
@@ -231,23 +233,11 @@ void GitCommit::LookupAfterWork(uv_work_t *req) { | |||
| 231 | 233 | HandleScope scope; | |
| 232 | 234 | LookupBaton *baton = static_cast<LookupBaton *>(req->data); | |
| 233 | 235 | ||
| 234 | - if (baton->error) { | ||
| 235 | - Local<Value> argv[1] = { | ||
| 236 | - GitError::WrapError(baton->error) | ||
| 237 | - }; | ||
| 238 | - | ||
| 239 | - TryCatch try_catch; | ||
| 240 | - | ||
| 241 | - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); | ||
| 242 | - | ||
| 243 | - if (try_catch.HasCaught()) { | ||
| 244 | - node::FatalException(try_catch); | ||
| 245 | - } | ||
| 246 | - } else { | ||
| 247 | - | ||
| 236 | + if (success(baton->error, baton->callback)) { | ||
| 248 | 237 | Local<Object> commit = GitCommit::constructor_template->NewInstance(); | |
| 249 | 238 | GitCommit *commitInstance = ObjectWrap::Unwrap<GitCommit>(commit); | |
| 250 | 239 | commitInstance->SetValue(baton->rawCommit); | |
| 240 | + commitInstance->oid = &baton->rawOid; | ||
| 251 | 241 | ||
| 252 | 242 | Handle<Value> argv[2] = { | |
| 253 | 243 | Local<Value>::New(Null()), | |
@@ -263,6 +253,56 @@ void GitCommit::LookupAfterWork(uv_work_t *req) { | |||
| 263 | 253 | delete req; | |
| 264 | 254 | } | |
| 265 | 255 | ||
| 256 | + Handle<Value> GitCommit::Oid(const Arguments& args) { | ||
| 257 | + HandleScope scope; | ||
| 258 | + | ||
| 259 | + Local<Object> oid = GitOid::constructor_template->NewInstance(); | ||
| 260 | + GitOid *oidInstance = ObjectWrap::Unwrap<GitOid>(oid); | ||
| 261 | + oidInstance->SetValue(*const_cast<git_oid *>(ObjectWrap::Unwrap<GitCommit>(args.This())->oid)); | ||
| 262 | + | ||
| 263 | + return scope.Close(oid); | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + Handle<Value> GitCommit::Sha(const Arguments& args) { | ||
| 267 | + HandleScope scope; | ||
| 268 | + | ||
| 269 | + if(args.Length() == 0 || !args[0]->IsFunction()) { | ||
| 270 | + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + ShaBaton* baton = new ShaBaton; | ||
| 274 | + baton->request.data = baton; | ||
| 275 | + baton->rawOid = ObjectWrap::Unwrap<GitCommit>(args.This())->oid; | ||
| 276 | + baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[0])); | ||
| 277 | + | ||
| 278 | + uv_queue_work(uv_default_loop(), &baton->request, ShaWork, (uv_after_work_cb)ShaAfterWork); | ||
| 279 | + | ||
| 280 | + return Undefined(); | ||
| 281 | + } | ||
| 282 | + void GitCommit::ShaWork(uv_work_t* req) { | ||
| 283 | + ShaBaton *baton = static_cast<ShaBaton *>(req->data); | ||
| 284 | + | ||
| 285 | + baton->sha[GIT_OID_HEXSZ] = '\0'; | ||
| 286 | + | ||
| 287 | + git_oid_fmt(baton->sha, baton->rawOid); | ||
| 288 | + } | ||
| 289 | + void GitCommit::ShaAfterWork(uv_work_t* req) { | ||
| 290 | + HandleScope scope; | ||
| 291 | + ShaBaton *baton = static_cast<ShaBaton *>(req->data); | ||
| 292 | + | ||
| 293 | + Handle<Value> argv[2] = { | ||
| 294 | + Local<Value>::New(Null()), | ||
| 295 | + String::New(baton->sha) | ||
| 296 | + }; | ||
| 297 | + | ||
| 298 | + TryCatch try_catch; | ||
| 299 | + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); | ||
| 300 | + if (try_catch.HasCaught()) { | ||
| 301 | + node::FatalException(try_catch); | ||
| 302 | + } | ||
| 303 | + delete req; | ||
| 304 | + } | ||
| 305 | + | ||
| 266 | 306 | Handle<Value> GitCommit::Close(const Arguments& args) { | |
| 267 | 307 | HandleScope scope; | |
| 268 | 308 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments