Skip to content

Commit 5915582

Browse files
committed
Basic support for arrays
1 parent eebd0ea commit 5915582

23 files changed

+403
-114
lines changed

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
- codegen documentation
2-
- array handling

example/general.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
128128
// parents. Here we're creating oid objects to create the commit with,
129129
// but you can also use existing ones:
130130

131-
var treeId = git.Oid.fromString("28873d96b4e8f4e33ea30f4c682fd325f7ba56ac");
132-
var parentId = git.Oid.fromString("f0877d0b841d75172ec404fc9370173dfffc20d1");
131+
var treeId = git.Oid.fromString("4170d10f19600b9cb086504e8e05fe7d863358a2");
132+
var parentId = git.Oid.fromString("eebd0ead15d62eaf0ba276da53af43bbc3ce43ab");
133133

134134
repo.getTree(treeId, function(error, tree) {
135+
if (error) throw error;
136+
135137
repo.getCommit(parentId, function(error, parent) {
136-
return "Not yet working!";
138+
if (error) throw error;
137139
// Here we actually create the commit object with a single call with all
138140
// the values we need to create the commit. The SHA key is written to the
139141
// `commit_id` variable here.
@@ -144,8 +146,8 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
144146
"example commit",
145147
tree,
146148
[parent],
147-
function (error, commitOid) {
148-
console.log("New Commit:", commitOid.sha());
149+
function (error, oid) {
150+
console.log("New Commit:", oid.sha());
149151
});
150152
});
151153
});
@@ -306,16 +308,19 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
306308
// references such as branches, tags and remote references (everything in
307309
// the .git/refs directory).
308310

309-
return "this doesn't yet work";
310-
repo.getReferences(function(error, references) {
311+
repo.getReferences(git.Reference.Type.Oid | git.Reference.Type.Symbolic, function(error, referenceNames) {
311312
if (error) throw error;
312313

313-
references.forEach(function(reference) {
314-
if (reference.type() == git.Reference.Oid) {
315-
console.log(oid.sha());
316-
} else if (reference.type() == git.Reference.Symbolic) {
317-
console.log(reference.symbolicTarget());
318-
}
314+
referenceNames.forEach(function(referenceName) {
315+
repo.getReference(referenceName, function(error, reference) {
316+
if (error) throw error;
317+
318+
if (reference.isOid()) {
319+
console.log("Reference:", referenceName, reference.oid());
320+
} else if (reference.isSymbolic()) {
321+
console.log("Reference:", referenceName, reference.symbolicTarget());
322+
}
323+
});
319324
});
320325
});
321326
});

include/repo.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ class GitRepo : public ObjectWrap {
105105
const git_oid * id;
106106
Persistent<Function> callback;
107107
};
108+
static Handle<Value> CreateCommit(const Arguments& args);
109+
static void CreateCommitWork(uv_work_t* req);
110+
static void CreateCommitAfterWork(uv_work_t* req);
111+
112+
struct CreateCommitBaton {
113+
uv_work_t request;
114+
int error_code;
115+
const git_error* error;
116+
git_oid * id;
117+
Persistent<Value> repoReference;
118+
git_repository * repo;
119+
Persistent<Value> update_refReference;
120+
const char * update_ref;
121+
Persistent<Value> authorReference;
122+
const git_signature * author;
123+
Persistent<Value> committerReference;
124+
const git_signature * committer;
125+
Persistent<Value> message_encodingReference;
126+
const char * message_encoding;
127+
Persistent<Value> messageReference;
128+
const char * message;
129+
Persistent<Value> treeReference;
130+
const git_tree * tree;
131+
Persistent<Value> parent_countReference;
132+
int parent_count;
133+
Persistent<Value> parentsReference;
134+
const git_commit ** parents;
135+
Persistent<Function> callback;
136+
};
108137
static Handle<Value> GetObject(const Arguments& args);
109138
static void GetObjectWork(uv_work_t* req);
110139
static void GetObjectAfterWork(uv_work_t* req);
@@ -240,6 +269,21 @@ class GitRepo : public ObjectWrap {
240269
const char * tag_name;
241270
Persistent<Function> callback;
242271
};
272+
static Handle<Value> GetReferences(const Arguments& args);
273+
static void GetReferencesWork(uv_work_t* req);
274+
static void GetReferencesAfterWork(uv_work_t* req);
275+
276+
struct GetReferencesBaton {
277+
uv_work_t request;
278+
int error_code;
279+
const git_error* error;
280+
git_strarray * array;
281+
Persistent<Value> repoReference;
282+
git_repository * repo;
283+
Persistent<Value> list_flagsReference;
284+
unsigned int list_flags;
285+
Persistent<Function> callback;
286+
};
243287
git_repository *raw;
244288
};
245289

lib/object.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
var git = require('../'),
2-
Object = git.Object;
1+
var git = require('../');
32

4-
Object.Type = {
3+
git.Object.Type = {
54
Any: -2, /**< Object can be any of the following */
65
Bad: -1, /**< Object is invalid. */
76
Ext1: 0, /**< Reserved for future use. */
@@ -14,18 +13,18 @@ Object.Type = {
1413
OidDelta: 7 /**< A delta, base is given by object id. */
1514
};
1615

17-
Object.prototype.isCommit = function() {
16+
git.Object.prototype.isCommit = function() {
1817
return this.type() == Object.Type.Commit;
1918
};
2019

21-
Object.prototype.isTree = function() {
20+
git.Object.prototype.isTree = function() {
2221
return this.type() == Object.Type.Tree;
2322
};
2423

25-
Object.prototype.isBlob = function() {
24+
git.Object.prototype.isBlob = function() {
2625
return this.type() == Object.Type.Blob;
2726
};
2827

29-
Object.prototype.isTag = function() {
28+
git.Object.prototype.isTag = function() {
3029
return this.type() == Object.Type.Tag;
3130
};

lib/oid.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ var git = require('../'),
44
Oid.prototype.toString = function() {
55
return this.sha();
66
};
7+
8+
Oid.prototype.inspect = function() {
9+
return "[Oid " + this.sha() + "]";
10+
};

lib/reference.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ var git = require('../'),
22
Reference = git.Reference;
33

44
Reference.Type = {
5-
Oid: 0,
6-
Symbolic: 1
5+
Oid: 1,
6+
Symbolic: 2
7+
};
8+
9+
Reference.prototype.isOid = function() {
10+
return this.type() == Reference.Type.Oid;
11+
};
12+
13+
Reference.prototype.isSymbolic = function() {
14+
return this.type() == Reference.Type.Symbolic;
715
};

lib/util.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ exports.normalizeOid = function(object, key) {
1717
object[key] = function() {
1818
var oid = arguments[0];
1919
if (typeof oid === 'string') oid = git.Oid.fromString(oid);
20-
arguments[0] = oid;
21-
oldFn.apply(this, arguments);
20+
var newArguments = [oid];
21+
for (var i = 1; i < arguments.length; i++)
22+
newArguments[i] = arguments[i];
23+
oldFn.apply(this, newArguments);
2224
};
2325
};

src/branch.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Handle<Value> Branch::Create(const Arguments& args) {
100100
, from_target
101101
, from_force
102102
);
103-
delete from_branch_name;
103+
free((void *)from_branch_name);
104104
if (result != GIT_OK) {
105105
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
106106
}
@@ -185,7 +185,7 @@ Handle<Value> Branch::Move(const Arguments& args) {
185185
, from_new_branch_name
186186
, from_force
187187
);
188-
delete from_new_branch_name;
188+
free((void *)from_new_branch_name);
189189
if (result != GIT_OK) {
190190
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
191191
}
@@ -219,7 +219,7 @@ Handle<Value> Branch::Lookup(const Arguments& args) {
219219
, from_branch_name
220220
, from_branch_type
221221
);
222-
delete from_branch_name;
222+
free((void *)from_branch_name);
223223
if (result != GIT_OK) {
224224
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
225225
}
@@ -290,7 +290,7 @@ Handle<Value> Branch::SetUpstream(const Arguments& args) {
290290
from_branch
291291
, from_upstream_name
292292
);
293-
delete from_upstream_name;
293+
free((void *)from_upstream_name);
294294
if (result != GIT_OK) {
295295
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
296296
}
@@ -326,8 +326,8 @@ Handle<Value> Branch::UpstreamName(const Arguments& args) {
326326
, from_repo
327327
, from_canonical_branch_name
328328
);
329-
delete from_tracking_branch_name_out;
330-
delete from_canonical_branch_name;
329+
free((void *)from_tracking_branch_name_out);
330+
free((void *)from_canonical_branch_name);
331331
if (result != GIT_OK) {
332332
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
333333
}
@@ -381,8 +381,8 @@ Handle<Value> Branch::RemoteName(const Arguments& args) {
381381
, from_repo
382382
, from_canonical_branch_name
383383
);
384-
delete from_remote_name_out;
385-
delete from_canonical_branch_name;
384+
free((void *)from_remote_name_out);
385+
free((void *)from_canonical_branch_name);
386386
if (result != GIT_OK) {
387387
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
388388
}

src/index.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ Handle<Value> GitIndex::Remove(const Arguments& args) {
468468
, from_path
469469
, from_stage
470470
);
471-
delete from_path;
471+
free((void *)from_path);
472472
if (result != GIT_OK) {
473473
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
474474
}
@@ -494,7 +494,7 @@ Handle<Value> GitIndex::RemoveDirectory(const Arguments& args) {
494494
, from_dir
495495
, from_stage
496496
);
497-
delete from_dir;
497+
free((void *)from_dir);
498498
if (result != GIT_OK) {
499499
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
500500
}
@@ -586,7 +586,7 @@ Handle<Value> GitIndex::RemoveBypath(const Arguments& args) {
586586
ObjectWrap::Unwrap<GitIndex>(args.This())->GetValue()
587587
, from_path
588588
);
589-
delete from_path;
589+
free((void *)from_path);
590590
if (result != GIT_OK) {
591591
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
592592
}
@@ -612,7 +612,7 @@ Handle<Value> GitIndex::Find(const Arguments& args) {
612612
, ObjectWrap::Unwrap<GitIndex>(args.This())->GetValue()
613613
, from_path
614614
);
615-
delete from_path;
615+
free((void *)from_path);
616616

617617
Handle<Value> to;
618618
to = Int32::New(result);
@@ -632,7 +632,7 @@ Handle<Value> GitIndex::ConflictRemove(const Arguments& args) {
632632
ObjectWrap::Unwrap<GitIndex>(args.This())->GetValue()
633633
, from_path
634634
);
635-
delete from_path;
635+
free((void *)from_path);
636636
if (result != GIT_OK) {
637637
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
638638
}

src/odb.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Handle<Value> GitOdb::Open(const Arguments& args) {
105105
&out
106106
, from_objects_dir
107107
);
108-
delete from_objects_dir;
108+
free((void *)from_objects_dir);
109109
if (result != GIT_OK) {
110110
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
111111
}
@@ -128,7 +128,7 @@ Handle<Value> GitOdb::AddDiskAlternate(const Arguments& args) {
128128
ObjectWrap::Unwrap<GitOdb>(args.This())->GetValue()
129129
, from_path
130130
);
131-
delete from_path;
131+
free((void *)from_path);
132132
if (result != GIT_OK) {
133133
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
134134
}
@@ -446,7 +446,7 @@ Handle<Value> GitOdb::Hashfile(const Arguments& args) {
446446
, from_path
447447
, from_type
448448
);
449-
delete from_path;
449+
free((void *)from_path);
450450
if (result != GIT_OK) {
451451
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
452452
}

0 commit comments

Comments
 (0)