Skip to content

Commit 54a656e

Browse files
committed
Updated blob, added new commit methods and updated convenience api
1 parent 5312b22 commit 54a656e

7 files changed

Lines changed: 72 additions & 8 deletions

File tree

example/convenience-repo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ git.repo( './dummyrepo/.git', function( err, repo ) {
44
if( err ) { throw err; }
55

66
// Read a commit when you know the sha1
7-
repo.commit( '2f6cbe055f1a6ca0a3ba524ba88a7806ba507a89', function( err, commit ) {
8-
console.log( commit.author().name );
7+
repo.commit( 'd29b7fecf71d0ef4887071ac18dc87f40c2fd4e1', function( err, commit ) {
8+
console.log( commit.time() );
99
});
1010

1111
// Read a commit when you know the name

example/dummyrepo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 2f6cbe055f1a6ca0a3ba524ba88a7806ba507a89
1+
Subproject commit d29b7fecf71d0ef4887071ac18dc87f40c2fd4e1

lib/commit.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ var _Commit = function( obj ) {
2929
return self.commit.message();
3030
};
3131

32+
self.time = function() {
33+
return new Date( self.commit.time() * 1000 );
34+
};
35+
3236
self.author = function() {
3337
var sig = new git.git2.Sig();
3438

src/blob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Blob : public EventEmitter {
2020
public:
2121
static Persistent<FunctionTemplate> constructor_template;
2222
static void Initialize(Handle<v8::Object> target);
23-
// Synchronous
23+
2424
int New(git_repository *repo);
2525
git_blob* GetValue();
2626
void SetValue(git_blob* blob);

src/commit.cc

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ void Commit::Initialize(Handle<Object> target) {
2727
constructor_template->SetClassName(String::NewSymbol("Commit"));
2828

2929
NODE_SET_PROTOTYPE_METHOD(constructor_template, "lookup", Lookup);
30+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "id", Id);
3031
NODE_SET_PROTOTYPE_METHOD(constructor_template, "messageShort", MessageShort);
3132
NODE_SET_PROTOTYPE_METHOD(constructor_template, "message", Message);
33+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "time", Time);
3234
NODE_SET_PROTOTYPE_METHOD(constructor_template, "timeOffset", TimeOffset);
3335
NODE_SET_PROTOTYPE_METHOD(constructor_template, "author", Author);
3436

@@ -43,12 +45,16 @@ void Commit::SetValue(git_commit* commit) {
4345
this->commit = commit;
4446
}
4547

48+
int Commit::Lookup(git_repository* repo, git_oid* oid) {
49+
return git_commit_lookup(&this->commit, repo, oid);
50+
}
51+
4652
int Commit::New(git_repository* repo) {
4753
return git_commit_new(&this->commit, repo);
4854
}
4955

50-
int Commit::Lookup(git_repository* repo, git_oid* oid) {
51-
return git_commit_lookup(&this->commit, repo, oid);
56+
const git_oid* Commit::Id() {
57+
return git_commit_id(this->commit);
5258
}
5359

5460
const char* Commit::MessageShort() {
@@ -59,10 +65,18 @@ const char* Commit::Message() {
5965
return git_commit_message(this->commit);
6066
}
6167

68+
time_t Commit::Time() {
69+
return git_commit_time(this->commit);
70+
}
71+
6272
int Commit::TimeOffset() {
6373
return git_commit_time_offset(this->commit);
6474
}
6575

76+
const git_signature* Commit::Committer() {
77+
return git_commit_author(this->commit);
78+
}
79+
6680
const git_signature* Commit::Author() {
6781
return git_commit_author(this->commit);
6882
}
@@ -153,6 +167,22 @@ int Commit::EIO_AfterLookup(eio_req *req) {
153167
return 0;
154168
}
155169

170+
Handle<Value> Commit::Id(const Arguments& args) {
171+
Commit *commit = ObjectWrap::Unwrap<Commit>(args.This());
172+
173+
HandleScope scope;
174+
175+
if(args.Length() == 0 || !args[0]->IsObject()) {
176+
return ThrowException(Exception::Error(String::New("Oid is required and must be an Object.")));
177+
}
178+
179+
Oid *oid = ObjectWrap::Unwrap<Oid>(args[0]->ToObject());
180+
181+
oid->SetValue(const_cast<git_oid *>(commit->Id()));
182+
183+
return Undefined();
184+
}
185+
156186
Handle<Value> Commit::MessageShort(const Arguments& args) {
157187
Commit *commit = ObjectWrap::Unwrap<Commit>(args.This());
158188

@@ -169,6 +199,14 @@ Handle<Value> Commit::Message(const Arguments& args) {
169199
return String::New(commit->Message());
170200
}
171201

202+
Handle<Value> Commit::Time(const Arguments& args) {
203+
Commit *commit = ObjectWrap::Unwrap<Commit>(args.This());
204+
205+
HandleScope scope;
206+
207+
return Integer::New(commit->Time());
208+
}
209+
172210
Handle<Value> Commit::TimeOffset(const Arguments& args) {
173211
Commit *commit = ObjectWrap::Unwrap<Commit>(args.This());
174212

@@ -177,6 +215,22 @@ Handle<Value> Commit::TimeOffset(const Arguments& args) {
177215
return Integer::New(commit->TimeOffset());
178216
}
179217

218+
Handle<Value> Commit::Committer(const Arguments& args) {
219+
Commit *commit = ObjectWrap::Unwrap<Commit>(args.This());
220+
221+
HandleScope scope;
222+
223+
if(args.Length() == 0 || !args[0]->IsObject()) {
224+
return ThrowException(Exception::Error(String::New("Signature is required and must be an Object.")));
225+
}
226+
227+
Sig *sig = ObjectWrap::Unwrap<Sig>(args[0]->ToObject());
228+
229+
sig->SetValue(const_cast<git_signature *>(commit->Committer()));
230+
231+
return Undefined();
232+
}
233+
180234
Handle<Value> Commit::Author(const Arguments& args) {
181235
Commit *commit = ObjectWrap::Unwrap<Commit>(args.This());
182236

src/commit.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ class Commit : public EventEmitter {
2525

2626
git_commit* GetValue();
2727
void SetValue(git_commit* commit);
28-
int New(git_repository *repo);
2928
int Lookup(git_repository* repo, git_oid* oid);
29+
int New(git_repository *repo);
30+
const git_oid* Id();
3031
const char* MessageShort();
3132
const char* Message();
33+
time_t Time();
3234
int TimeOffset();
35+
const git_signature* Committer();
3336
const git_signature* Author();
3437

3538
protected:
@@ -42,9 +45,12 @@ class Commit : public EventEmitter {
4245
static int EIO_Lookup(eio_req *req);
4346
static int EIO_AfterLookup(eio_req *req);
4447

48+
static Handle<Value> Id(const Arguments& args);
4549
static Handle<Value> MessageShort(const Arguments& args);
4650
static Handle<Value> Message(const Arguments& args);
51+
static Handle<Value> Time(const Arguments& args);
4752
static Handle<Value> TimeOffset(const Arguments& args);
53+
static Handle<Value> Committer(const Arguments& args);
4854
static Handle<Value> Author(const Arguments& args);
4955

5056
private:

test/dummyrepo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit cb09e99e91d41705197e0fb60823fdc7df776691
1+
Subproject commit 978feacee2432e67051f2714ec7d28ad80e16908

0 commit comments

Comments
 (0)