Skip to content

Commit e30cc6f

Browse files
committed
Tidied blob
1 parent db07c63 commit e30cc6f

2 files changed

Lines changed: 28 additions & 165 deletions

File tree

include/blob.h

Lines changed: 10 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -20,177 +20,44 @@ using namespace v8;
2020
using namespace node;
2121

2222
/**
23-
* Class: GitBlob
2423
* Wrapper for libgit2 git_blob.
2524
*/
2625
class GitBlob : public ObjectWrap {
2726
public:
28-
/**
29-
* Variable: constructor_template
30-
* Used to create Node.js constructor.
31-
*/
27+
3228
static Persistent<Function> constructor_template;
33-
/**
34-
* Function: Initialize
35-
* Used to intialize the EventEmitter from Node.js
36-
*
37-
* Parameters:
38-
* target - Object the Node.js global module object
39-
*/
29+
4030
static void Initialize(Handle<Object> target);
41-
/**
42-
* Accessor for GitBlob
43-
*
44-
* @return the internal git_blob reference
45-
*/
31+
4632
git_blob* GetValue();
47-
/**
48-
* Mutator for Object
49-
*
50-
* @param obj a git_object object
51-
*/
5233
void SetValue(git_blob* blob);
53-
/**
54-
* Function: Lookup
55-
* Lookup a blob object from a repository.
56-
*
57-
* Parameters:
58-
* repo the repo to use when locating the blob.
59-
* id identity of the blob to locate.
60-
*
61-
* Returns:
62-
* 0 on success; error code otherwise
63-
*/
34+
6435
int Lookup(git_repository* repo, const git_oid *id);
65-
/**
66-
*
67-
* Function: Close
68-
* Free a blob object.
69-
*/
70-
void Close();
71-
/**
72-
*
73-
* Function: CreateFromFile
74-
* Read a file into the ODB.
75-
*
76-
* Returns:
77-
* 0 on success, error code otherwise
78-
*/
36+
7937
int CreateFromFile(git_oid* oid, git_repository* repo, const char* path);
80-
/**
81-
*
82-
* Function: CreateFromBuffer
83-
* Read a buffer into the ODB.
84-
*
85-
* Returns:
86-
* 0 on success, error code otherwise
87-
*/
8838
int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len);
8939

9040
protected:
91-
/**
92-
* Constructor: GitBlob
93-
*/
9441
GitBlob() {};
95-
/**
96-
* Deconstructor: GitBlob
97-
*/
9842
~GitBlob() {};
99-
/**
100-
* Function: New
101-
*
102-
* Parameters:
103-
* args Arguments function call
104-
*
105-
* Returns:
106-
* Object args.This()
107-
*/
43+
10844
static Handle<Value> New(const Arguments& args);
109-
/**
110-
* Function: Lookup
111-
*
112-
* Parameters:
113-
* args Arguments function call
114-
*
115-
* Returns:
116-
* Object args.This()
117-
*/
45+
46+
static Handle<Value> CreateFromFile(const Arguments& args);
47+
11848
static Handle<Value> Lookup(const Arguments& args);
119-
/**
120-
* Function: LookupWork
121-
*
122-
* Parameters:
123-
* req - an uv_work_t pointer
124-
*
125-
*/
12649
static void LookupWork(uv_work_t* req);
127-
/**
128-
* Function: LookupAfterWork
129-
*
130-
* Parameters:
131-
* req - an uv_work_t pointer
132-
*/
13350
static void LookupAfterWork(uv_work_t* req);
13451

135-
/**
136-
* Function: RawContent
137-
*
138-
* Parameters:
139-
* args Arguments function call
140-
*
141-
* Returns:
142-
* Object args.This()
143-
*/
14452
static Handle<Value> RawContent(const Arguments& args);
14553
static void RawContentWork(uv_work_t* req);
14654
static void RawContentAfterWork(uv_work_t* req);
14755

148-
/**
149-
* Function: RawSize
150-
*
151-
* Parameters:
152-
* args Arguments function call
153-
*
154-
* Returns:
155-
* Object args.This()
156-
*/
157-
static Handle<Value> RawSize(const Arguments& args);
158-
/**
159-
* Function: Close
160-
*
161-
* Parameters:
162-
* args Arguments function call
163-
*
164-
* Returns:
165-
* Object args.This()
166-
*/
167-
static Handle<Value> Close(const Arguments& args);
168-
/**
169-
* Function: CreateFromFile
170-
*
171-
* Parameters:
172-
* args Arguments function call
173-
*
174-
* Returns:
175-
* Object args.This()
176-
*/
17756
static Handle<Value> CreateFromFile(const Arguments& args);
178-
/**
179-
* Function: CreateFromBuffer
180-
*
181-
* Parameters:
182-
* args Arguments function call
183-
*
184-
* Returns:
185-
* Object args.This()
186-
*/
18757
static Handle<Value> CreateFromBuffer(const Arguments& args);
18858

18959
private:
190-
/**
191-
* Variable: blob
192-
* Internal reference to git_blob object
193-
*/
60+
19461
git_blob* blob;
19562

19663
struct LookupBaton {

src/blob.cc

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void GitBlob::Initialize (Handle<v8::Object> target) {
2828

2929
NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup);
3030
NODE_SET_PROTOTYPE_METHOD(tpl, "rawContent", RawContent);
31-
NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close);
31+
NODE_SET_PROTOTYPE_METHOD(tpl, "free", Free);
3232
NODE_SET_PROTOTYPE_METHOD(tpl, "createFromFile", CreateFromFile);
3333
NODE_SET_PROTOTYPE_METHOD(tpl, "createFromBuffer", CreateFromBuffer);
3434

@@ -43,17 +43,6 @@ void GitBlob::SetValue(git_blob* blob) {
4343
this->blob = blob;
4444
}
4545

46-
void GitBlob::Close() {
47-
git_blob_free(this->blob);
48-
}
49-
50-
int CreateFromFile(git_oid* oid, git_repository* repo, const char* path) {
51-
return git_blob_create_fromdisk(oid, repo, path);
52-
}
53-
int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len) {
54-
return git_blob_create_frombuffer(oid, repo, buffer, len);
55-
}
56-
5746
Handle<Value> GitBlob::New(const Arguments& args) {
5847
HandleScope scope;
5948

@@ -63,6 +52,23 @@ Handle<Value> GitBlob::New(const Arguments& args) {
6352
return scope.Close( args.This() );
6453
}
6554

55+
Handle<Value> GitBlob::Free(const Arguments& args) {
56+
HandleScope scope;
57+
58+
GitBlob* blob = ObjectWrap::Unwrap<GitBlob>(args.This());
59+
git_blob_free(blob->blob);
60+
61+
return scope.Close( Undefined() );
62+
}
63+
64+
65+
int CreateFromFile(git_oid* oid, git_repository* repo, const char* path) {
66+
return git_blob_create_fromdisk(oid, repo, path);
67+
}
68+
int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len) {
69+
return git_blob_create_frombuffer(oid, repo, buffer, len);
70+
}
71+
6672
Handle<Value> GitBlob::Lookup(const Arguments& args) {
6773
HandleScope scope;
6874

@@ -162,16 +168,6 @@ void GitBlob::RawContentAfterWork(uv_work_t* req) {
162168
delete req;
163169
}
164170

165-
Handle<Value> GitBlob::Close(const Arguments& args) {
166-
HandleScope scope;
167-
168-
GitBlob* blob = ObjectWrap::Unwrap<GitBlob>(args.This());
169-
170-
blob->Close();
171-
172-
return scope.Close( Undefined() );
173-
}
174-
175171
Handle<Value> GitBlob::CreateFromFile(const Arguments& args) {
176172
HandleScope scope;
177173

0 commit comments

Comments
 (0)