From 2055413b623bd836e935fda0eb4ad9eeeeb98f2d Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Wed, 9 Mar 2011 14:19:50 -0800 Subject: [PATCH 01/35] github generated gh-pages branch --- index.html | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 000000000..2a877a8e0 --- /dev/null +++ b/index.html @@ -0,0 +1,107 @@ + + + + + + tbranyen/nodegit @ GitHub + + + + + + Fork me on GitHub + +
+ +
+ + + + +
+ +

nodegit + by tbranyen

+ +
+ NodeJS libgit2 asynchronous native bindings +
+ +

A collection of non-blocking Node.js libgit2 bindings, that include

Dependencies

+

Node.js v0.4.2 or latest +Git

+

Install

+

sudo npm install nodegit

+

License

+

Copyright (c) 2011 Tim Branyen + +This file is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2, +as published by the Free Software Foundation. + +In addition to the permissions in the GNU General Public License, +the authors give you unlimited permission to link the compiled +version of this file into combinations with other programs, +and to distribute those combinations without any restriction +coming from the use of this file. (The General Public License +restrictions do apply in other respects; for example, they cover +modification of the file, and distribution when not linked into +a combined executable.) + +This file is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; see the file COPYING. If not, write to +the Free Software Foundation, 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA.

+

Authors

+

Tim Branyen (tim@tabdeveloper.com)

+

Contact

+

Tim Branyen (tim@tabdeveloper.com)

+ + +

Download

+

+ You can download this project in either + zip or + tar formats. +

+

You can also clone the project with Git + by running: +

$ git clone git://github.com/tbranyen/nodegit
+

+ + + +
+ + + + From 98854074920437659671333894fedff2ffc26b33 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Wed, 9 Mar 2011 17:41:44 -0500 Subject: [PATCH 02/35] initial --- index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/index.html b/index.html index 2a877a8e0..557cca021 100644 --- a/index.html +++ b/index.html @@ -102,6 +102,5 @@

Download

- From 4c29a23afc306b533d0338274af004ddf6ee863d Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 9 Mar 2011 21:14:03 -0500 Subject: [PATCH 03/35] removed license information and contact info --- index.html | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/index.html b/index.html index 557cca021..80cf469c3 100644 --- a/index.html +++ b/index.html @@ -49,40 +49,15 @@

nodegit NodeJS libgit2 asynchronous native bindings -

A collection of non-blocking Node.js libgit2 bindings, that include

Dependencies

-

Node.js v0.4.2 or latest -Git

-

Install

-

sudo npm install nodegit

-

License

-

Copyright (c) 2011 Tim Branyen - -This file is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License, version 2, -as published by the Free Software Foundation. - -In addition to the permissions in the GNU General Public License, -the authors give you unlimited permission to link the compiled -version of this file into combinations with other programs, -and to distribute those combinations without any restriction -coming from the use of this file. (The General Public License -restrictions do apply in other respects; for example, they cover -modification of the file, and distribution when not linked into -a combined executable.) - -This file is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; see the file COPYING. If not, write to -the Free Software Foundation, 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA.

-

Authors

-

Tim Branyen (tim@tabdeveloper.com)

-

Contact

-

Tim Branyen (tim@tabdeveloper.com)

+

A collection of non-blocking Node.js libgit2 bindings, which includes a full raw api and a convenience api.

Dependencies

+

Node.js v0.4.2 or latest + Git

+ +

Install

+

sudo npm install nodegit

+ +

Contact

+

Tim Branyen (tim@tabdeveloper.com)

Download

@@ -91,15 +66,12 @@

Download

zip or tar formats.

+

You can also clone the project with Git by running:

$ git clone git://github.com/tbranyen/nodegit

- - From 9a4084659fae154b5969cfe9ae51f788ce33a2ab Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 9 Mar 2011 22:26:19 -0500 Subject: [PATCH 04/35] Significant updates --- css/common.css | 47 +++++++++++ css/ir_black.css | 102 +++++++++++++++++++++++ index.html | 187 +++++++++++++++++++++++++++---------------- js/highlight.pack.js | 1 + 4 files changed, 270 insertions(+), 67 deletions(-) create mode 100644 css/common.css create mode 100644 css/ir_black.css create mode 100644 js/highlight.pack.js diff --git a/css/common.css b/css/common.css new file mode 100644 index 000000000..00352162d --- /dev/null +++ b/css/common.css @@ -0,0 +1,47 @@ +body { + font-family: Georgia, sans-serif; +} +.forkme { + position: absolute; + top: 0; + right: 0; + border: 0; +} + +a { + color: #333; +} + +a:hover { + color: #636363; +} + +pre { + margin: 0; +} + +#container { + width: 700px; + margin: 0 auto; +} + + #container .download img { + width: 90px; + border: 0; + float: right; + } + + #container .branding > a { + font-size: 400%; + } + + #container .branding .small { + padding-left: 10px; + font-size: 200%; + } + +#container .command { + padding: 10px; + background-color: #333; + color: #FFE; +} diff --git a/css/ir_black.css b/css/ir_black.css new file mode 100644 index 000000000..d5322786f --- /dev/null +++ b/css/ir_black.css @@ -0,0 +1,102 @@ +/* + IR_Black style (c) Vasily Mikhailitchenko +*/ + +pre code { + display: block; padding: 0.5em; + background: #333; color: #f8f8f8; +} + +pre .shebang, +pre .comment, +pre .template_comment, +pre .javadoc { + color: #7c7c7c; +} + +pre .keyword, +pre .tag, +pre .ruby .function .keyword, +pre .tex .command { + color: #96CBFE; +} + +pre .function .keyword, +pre .sub .keyword, +pre .method, +pre .list .title { + color: #FFFFB6; +} + +pre .string, +pre .tag .value, +pre .cdata, +pre .filter .argument, +pre .attr_selector, +pre .apache .cbracket, +pre .date { + color: #A8FF60; +} + +pre .subst { + color: #DAEFA3; +} + +pre .regexp { + color: #E9C062; +} + +pre .function .title, +pre .sub .identifier, +pre .pi, +pre .decorator, +pre .ini .title, +pre .tex .special { + color: #FFFFB6; +} + +pre .class .title, +pre .constant, +pre .smalltalk .class, +pre .javadoctag, +pre .yardoctag, +pre .phpdoc, +pre .nginx .built_in { + color: #FFFFB6; +} + +pre .symbol, +pre .ruby .symbol .string, +pre .ruby .symbol .keyword, +pre .ruby .symbol .keymethods, +pre .number, +pre .variable, +pre .vbscript, +pre .literal { + color: #C6C5FE; +} + +pre .css .keyword { + color: #96CBFE; +} + +pre .css .rule .keyword, +pre .css .id { + color: #FFFFB6; +} + +pre .css .class { + color: #FFF; +} + +pre .hexcolor { + color: #C6C5FE; +} + +pre .number { + color:#FF73FD; +} + +pre .tex .formula { + opacity: 0.7; +} diff --git a/index.html b/index.html index 80cf469c3..173f9b13a 100644 --- a/index.html +++ b/index.html @@ -1,78 +1,131 @@ - - - - - - tbranyen/nodegit @ GitHub - - - - - - Fork me on GitHub - -
- -
- - - - -
+ + + + + + + tbranyen/nodegit @ GitHub + + + + -

nodegit - by tbranyen

+ + + + Fork me on GitHub + -
- NodeJS libgit2 asynchronous native bindings -
+
+ + +
+ + + + +
+ + +
+ nodegit + by tbranyen +
-

A collection of non-blocking Node.js libgit2 bindings, which includes a full raw api and a convenience api.

Dependencies

-

Node.js v0.4.2 or latest - Git

+
+ Version 0.0.1 Node.js libgit2 asynchronous native bindings +
-

Install

-

sudo npm install nodegit

+

A collection of non-blocking Node.js libgit2 bindings, raw api, convenience api, unit tests, documentation and accomodations to make contributing easier.

+ +

dependencies

+

+

+

-

Contact

-

Tim Branyen (tim@tabdeveloper.com)

+

install

+

+

sudo npm install nodegit
+

+

use

+

+


+  // Load in the module
+  var git = require( 'nodegit' );
 
-    

Download

-

- You can download this project in either - zip or - tar formats. -

+ // Open a repository for reading + git.repo( '.git', function( err, repo ) { + // Success is always 0, failure is always an error string + if( err ) { throw err; } + // Use the master branch + repo.branch( 'master', function( err, branch ) { + if( err ) { throw err; } + // Iterate over the revision history + branch.history.each( function( i, commit ) { + // Print out `git log` emulation + console.log( 'commit ' + commit.sha ); + console.log( commit.author.name + '<' + commit.author.email + '>' ); + console.log( commit.time.toLocaleString() + ' ' + commit.timeOffset ); + console.log( '\n' ); + console.log( commit.message ); + }); + }); + }); +
+
+

-

You can also clone the project with Git - by running: -

$ git clone git://github.com/tbranyen/nodegit
-

-
+

download

+

+ You can download this project in either + zip or + tar formats. +

+ +

+ You can also clone the project with Git by running: +

$ git clone git://github.com/tbranyen/nodegit
+

+ +
- + + + + + diff --git a/js/highlight.pack.js b/js/highlight.pack.js new file mode 100644 index 000000000..6da5ed664 --- /dev/null +++ b/js/highlight.pack.js @@ -0,0 +1 @@ +var hljs=new function(){var p={};var a={};function n(c){return c.replace(/&/gm,"&").replace(//gm,">")}function k(s,r){if(!s){return false}for(var c=0;c"}function B(C){return""}while(z.length||A.length){var w=v().splice(0,1)[0];x+=n(y.substr(s,w.offset-s));s=w.offset;if(w.event=="start"){x+=t(w.node);u.push(w.node)}else{if(w.event=="stop"){var r=u.length;do{r--;var c=u[r];x+=B(c)}while(c!=w.node);u.splice(r,1);while(r'+n(M[0])+""}else{O+=n(M[0])}R=Q.lR.lastIndex;M=Q.lR.exec(N)}O+=n(N.substr(R,N.length-R));return O}function L(r,N){if(N.subLanguage&&a[N.subLanguage]){var M=g(N.subLanguage,r);u+=M.keyword_count;C+=M.r;return M.value}else{return G(r,N)}}function J(N,r){var M=N.nM?"":'';if(N.rB){s+=M;N.buffer=""}else{if(N.eB){s+=n(r)+M;N.buffer=""}else{s+=M;N.buffer=r}}D[D.length]=N}function F(M,O,R){var P=D[D.length-1];if(R){s+=L(P.buffer+M,P);return false}var S=A(O,P);if(S){s+=L(P.buffer+M,P);J(S,O);C+=S.r;return S.rB}var r=x(D.length-1,O);if(r){var T=P.nM?"":"";if(P.rE){s+=L(P.buffer+M,P)+T}else{if(P.eE){s+=L(P.buffer+M,P)+T+n(O)}else{s+=L(P.buffer+M+O,P)+T}}while(r>1){T=D[D.length-2].nM?"":"";s+=T;r--;D.length--}var Q=D[D.length-1];D.length--;D[D.length-1].buffer="";if(Q.starts){for(var N=0;N1){throw"Illegal"}return{language:K,r:C,keyword_count:u,value:s}}catch(H){if(H=="Illegal"){return{language:null,r:0,keyword_count:0,value:n(E)}}else{throw H}}}function i(){function r(y,x){if(y.compiled){return}if(y.b){y.bR=e(x,"^"+y.b)}if(y.e){y.eR=e(x,"^"+y.e)}if(y.i){y.iR=e(x,"^(?:"+y.i+")")}if(y.r==undefined){y.r=1}if(!y.displayClassName){y.displayClassName=y.cN}if(!y.cN){y.nM=true}for(var w in y.k){if(!y.k.hasOwnProperty(w)){continue}if(y.k[w] instanceof Object){y.keywordGroups=y.k}else{y.keywordGroups={keyword:y.k}}break}y.sm=[];if(y.c){for(var v=0;vz.keyword_count+z.r){z=w}if(w.keyword_count+w.r>y.keyword_count+y.r){z=y;y=w}}}var u=v.className;if(!u.match(y.language)){u=u?(u+" "+y.language):y.language}var c=d(v);if(c.length){var s=document.createElement("pre");s.innerHTML=y.value;y.value=m(c,d(s),C)}if(A){y.value=y.value.replace(/^((<[^>]+>|\t)+)/gm,function(D,G,F,E){return G.replace(/\t/g,A)})}if(r){y.value=y.value.replace(/\n/g,"
")}if(/MSIE [678]/.test(navigator.userAgent)&&v.tagName=="CODE"&&v.parentNode.tagName=="PRE"){var s=v.parentNode;var x=document.createElement("div");x.innerHTML="
"+y.value+"
";v=x.firstChild.firstChild;x.firstChild.cN=s.cN;s.parentNode.replaceChild(x.firstChild,s)}else{v.innerHTML=y.value}v.className=u;v.dataset={};v.dataset.result={language:y.language,kw:y.keyword_count,re:y.r};if(z&&z.language){v.dataset.second_best={language:z.language,kw:z.keyword_count,re:z.r}}}function l(){if(l.called){return}l.called=true;f();if(arguments.length){for(var c=0;c|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:["escape"],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:["escape"],r:0};this.BE={cN:"escape",b:"\\\\.",e:this.IMR,nM:true,r:0};this.CLCM={cN:"comment",b:"//",e:"$",r:0};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NUMBER_MODE={cN:"number",b:this.NR,e:this.IMR,r:0};this.CNM={cN:"number",b:this.CNR,e:this.IMR,r:0};this.inherit=function(c,t){var s={};for(var r in c){s[r]=c[r]}if(t){for(var r in t){s[r]=t[r]}}return s}}();var initHighlightingOnLoad=hljs.initHighlightingOnLoad;hljs.LANGUAGES.javascript={dM:{l:[hljs.UIR],c:["string","comment","number","regexp_container","function"],k:{keyword:{"in":1,"if":1,"for":1,"while":1,"finally":1,"var":1,"new":1,"function":1,"do":1,"return":1,"void":1,"else":1,"break":1,"catch":1,"instanceof":1,"with":1,"throw":1,"case":1,"default":1,"try":1,"this":1,"switch":1,"continue":1,"typeof":1,"delete":1},literal:{"true":1,"false":1,"null":1}}},m:[hljs.CLCM,hljs.CBLCLM,hljs.CNM,hljs.ASM,hljs.QSM,hljs.BE,{cN:"regexp_container",b:"("+hljs.RSR+"|case|return|throw)\\s*",e:hljs.IMR,nM:true,l:[hljs.IR],k:{"return":1,"throw":1,"case":1},c:["comment",{cN:"regexp",b:"/.*?[^\\\\/]/[gim]*",e:hljs.IMR}],r:0},{cN:"function",b:"\\bfunction\\b",e:"{",l:[hljs.UIR],k:{"function":1},c:[{cN:"title",b:"[A-Za-z$_][0-9A-Za-z$_]*",e:hljs.IMR},{cN:"params",b:"\\(",e:"\\)",c:["string","comment"]}]}]}; \ No newline at end of file From 61abc609b167d02104be7523ec80a2a4dba96272 Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 9 Mar 2011 22:30:33 -0500 Subject: [PATCH 05/35] Updated version style and some css --- css/common.css | 7 +++++++ index.html | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/css/common.css b/css/common.css index 00352162d..40023c345 100644 --- a/css/common.css +++ b/css/common.css @@ -1,6 +1,7 @@ body { font-family: Georgia, sans-serif; } + .forkme { position: absolute; top: 0; @@ -45,3 +46,9 @@ pre { background-color: #333; color: #FFE; } + +#container .version { + padding: 5px; + background-color: #333; + color: #FFE; +} diff --git a/index.html b/index.html index 173f9b13a..454164325 100644 --- a/index.html +++ b/index.html @@ -33,7 +33,7 @@
- Version 0.0.1 Node.js libgit2 asynchronous native bindings + Version 0.0.1 Node.js libgit2 asynchronous native bindings

A collection of non-blocking Node.js libgit2 bindings, raw api, convenience api, unit tests, documentation and accomodations to make contributing easier.

From 639a4c9513d87a685991e5fa439a9c64ef6cac10 Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 9 Mar 2011 22:36:20 -0500 Subject: [PATCH 06/35] formatted code --- index.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 454164325..4f4a45ac0 100644 --- a/index.html +++ b/index.html @@ -41,7 +41,7 @@

dependencies

@@ -53,6 +53,7 @@

install

use

+ emulate `git log`


   // Load in the module
   var git = require( 'nodegit' );
@@ -69,9 +70,10 @@ 

use

// Print out `git log` emulation console.log( 'commit ' + commit.sha ); console.log( commit.author.name + '<' + commit.author.email + '>' ); - console.log( commit.time.toLocaleString() + ' ' + commit.timeOffset ); + console.log( commit.time ); console.log( '\n' ); console.log( commit.message ); + console.log( '\n' ); }); }); }); From b70f53e501dcf7e840ec5a7234ed84d8661f2a13 Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 9 Mar 2011 22:36:53 -0500 Subject: [PATCH 07/35] formatted code --- index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/index.html b/index.html index 4f4a45ac0..65b4c18b4 100644 --- a/index.html +++ b/index.html @@ -57,7 +57,6 @@

use


   // Load in the module
   var git = require( 'nodegit' );
-
   // Open a repository for reading
   git.repo( '.git', function( err, repo ) {
       // Success is always 0, failure is always an error string

From 7b9db780235396d784f7680385045d86c0ef64fc Mon Sep 17 00:00:00 2001
From: tim 
Date: Wed, 9 Mar 2011 22:40:53 -0500
Subject: [PATCH 08/35] formatted code

---
 index.html | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/index.html b/index.html
index 65b4c18b4..68d3913f4 100644
--- a/index.html
+++ b/index.html
@@ -89,8 +89,19 @@ 

download

- You can also clone the project with Git by running: -

$ git clone git://github.com/tbranyen/nodegit
+ You can also clone and build the project with Git by running: +
$ git clone git://github.com/tbranyen/nodegit
+
+$ cd nodegit
+
+$ ./configure
+$ make
+$ make install
+
+update with
+
+$ make update
+        

From ceeae127cf3fed4940278e053928ea72297ee389 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Fri, 11 Mar 2011 01:34:24 -0500 Subject: [PATCH 09/35] several updates to add sigificant stablility and performance; removed v8 from eio thread pool --- src/blob.cc | 6 ++---- src/blob.h | 2 +- src/commit.cc | 5 ++--- src/commit.h | 2 +- src/repo.cc | 49 ++++++++++++++++++++++------------------------- src/repo.h | 43 +++++++++++++++++++++-------------------- src/revwalk.cc | 5 ++--- src/revwalk.h | 2 +- src/tree.cc | 10 +++++++++- src/tree.h | 29 +++++++++++++++++++++++++--- src/tree_entry.cc | 37 +++++++++++++++++++++++++++++++++++ src/tree_entry.h | 25 ++++++++++++++++++++++++ 12 files changed, 151 insertions(+), 64 deletions(-) create mode 100644 src/tree_entry.cc create mode 100644 src/tree_entry.h diff --git a/src/blob.cc b/src/blob.cc index 45da1c592..9ef6cdd61 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -116,8 +116,7 @@ Handle Blob::Lookup(const Arguments& args) { int Blob::EIO_Lookup(eio_req *req) { lookup_request *ar = static_cast(req->data); - int err = ar->blob->Lookup(ar->repo->GetValue(), ar->oid->GetValue()); - ar->err = Persistent::New(Integer::New(err)); + ar->err = ar->blob->Lookup(ar->repo->GetValue(), ar->oid->GetValue()); return 0; } @@ -130,7 +129,7 @@ int Blob::EIO_AfterLookup(eio_req *req) { ar->blob->Unref(); Local argv[1]; - argv[0] = Number::Cast(*ar->err); + argv[0] = Integer::New(ar->err); TryCatch try_catch; @@ -139,7 +138,6 @@ int Blob::EIO_AfterLookup(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - ar->err.Dispose(); ar->callback.Dispose(); delete ar; diff --git a/src/blob.h b/src/blob.h index 5f785f29d..8d9818e3e 100755 --- a/src/blob.h +++ b/src/blob.h @@ -105,7 +105,7 @@ class Blob : public EventEmitter { Blob *blob; Repo *repo; Oid *oid; - Persistent err; + int err; Persistent callback; }; }; diff --git a/src/commit.cc b/src/commit.cc index ca6e83606..45b10db26 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -151,7 +151,7 @@ Handle Commit::Lookup(const Arguments& args) { int Commit::EIO_Lookup(eio_req *req) { lookup_request *ar = static_cast(req->data); - ar->err = Persistent::New(Integer::New(ar->commit->Lookup(ar->repo->GetValue(), ar->oid->GetValue()))); + ar->err = ar->commit->Lookup(ar->repo->GetValue(), ar->oid->GetValue()); return 0; } @@ -166,7 +166,7 @@ int Commit::EIO_AfterLookup(eio_req *req) { git_commit *commit = ar->commit->GetValue(); Local argv[1]; - argv[0] = *ar->err; + argv[0] = Integer::New(ar->err); TryCatch try_catch; @@ -175,7 +175,6 @@ int Commit::EIO_AfterLookup(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - ar->err.Dispose(); ar->callback.Dispose(); delete ar; diff --git a/src/commit.h b/src/commit.h index efc60c9db..e3b820852 100755 --- a/src/commit.h +++ b/src/commit.h @@ -83,7 +83,7 @@ class Commit : public EventEmitter { Commit* commit; Repo* repo; Oid* oid; - Persistent err; + int err; Persistent callback; }; diff --git a/src/repo.cc b/src/repo.cc index b010f0c6f..afc779028 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -5,6 +5,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include #include #include +#include #include "../vendor/libgit2/src/git2.h" @@ -92,7 +93,10 @@ Handle Repo::Open(const Arguments& args) { open_request *ar = new open_request(); ar->repo = repo; - ar->path = Persistent::New(args[0]); + + String::Utf8Value path(args[0]); + ar->path = *path; + ar->callback = Persistent::New(callback); repo->Ref(); @@ -106,8 +110,7 @@ Handle Repo::Open(const Arguments& args) { int Repo::EIO_Open(eio_req *req) { open_request *ar = static_cast(req->data); - String::Utf8Value path(ar->path); - ar->err = Persistent::New( Integer::New(ar->repo->Open(*path)) ); + ar->err = ar->repo->Open(ar->path.c_str()); return 0; } @@ -120,7 +123,7 @@ int Repo::EIO_AfterOpen(eio_req *req) { ar->repo->Unref(); Local argv[1]; - argv[0] = Number::Cast(*ar->err); + argv[0] = Integer::New(ar->err); TryCatch try_catch; @@ -129,8 +132,6 @@ int Repo::EIO_AfterOpen(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - ar->err.Dispose(); - ar->path.Dispose(); ar->callback.Dispose(); delete ar; @@ -248,8 +249,11 @@ Handle Repo::Init(const Arguments& args) { init_request *ar = new init_request(); ar->repo = repo; - ar->path = Persistent::New( args[0] ); - ar->is_bare = Persistent::New( args[1]->ToBoolean() ); + + String::Utf8Value path(args[0]); + ar->path = *path; + + ar->is_bare = args[1]->ToBoolean()->Value(); ar->callback = Persistent::New(callback); repo->Ref(); @@ -263,9 +267,7 @@ Handle Repo::Init(const Arguments& args) { int Repo::EIO_Init(eio_req *req) { init_request *ar = static_cast(req->data); - String::Utf8Value path(ar->path); - Local is_bare = ar->is_bare->ToBoolean(); - ar->err = Persistent::New(Integer::New(ar->repo->Init(*path, *is_bare))); + ar->err = ar->repo->Init(ar->path.c_str(), ar->is_bare); return 0; } @@ -277,20 +279,16 @@ int Repo::EIO_AfterInit(eio_req *req) { ev_unref(EV_DEFAULT_UC); ar->repo->Unref(); - Local argv[3]; - argv[0] = Number::Cast(*ar->err); - argv[1] = *ar->is_bare; + Local argv[2]; + argv[0] = Integer::New(ar->err); TryCatch try_catch; - ar->callback->Call(Context::GetCurrent()->Global(), 2, argv); + ar->callback->Call(Context::GetCurrent()->Global(), 1, argv); if(try_catch.HasCaught()) FatalException(try_catch); - ar->err.Dispose(); - ar->path.Dispose(); - ar->is_bare.Dispose(); ar->callback.Dispose(); delete ar; @@ -321,7 +319,10 @@ Handle Repo::LookupRef(const Arguments& args) { lookupref_request *ar = new lookupref_request(); ar->repo = repo; ar->ref = ObjectWrap::Unwrap(args[0]->ToObject()); - ar->name = Persistent::New(args[1]->ToString()); + + String::Utf8Value name(args[1]); + ar->name = *name; + ar->callback = Persistent::New(callback); repo->Ref(); @@ -335,14 +336,12 @@ Handle Repo::LookupRef(const Arguments& args) { int Repo::EIO_LookupRef(eio_req *req) { lookupref_request *ar = static_cast(req->data); - String::Utf8Value name(ar->name); git_reference* ref = ar->ref->GetValue(); git_reference** out = &ref; - int err = ar->repo->LookupRef(out, *name); - ar->err = Persistent::New(Integer::New(err)); + ar->err = ar->repo->LookupRef(out, ar->name.c_str()); - if(Int32::Cast(*ar->err)->Value() == 0) { + if(ar->err == 0) { ar->ref->SetValue(*out); } @@ -357,7 +356,7 @@ int Repo::EIO_AfterLookupRef(eio_req *req) { ar->repo->Unref(); Local argv[1]; - argv[0] = Number::Cast(*ar->err); + argv[0] = Integer::New(ar->err); TryCatch try_catch; @@ -366,8 +365,6 @@ int Repo::EIO_AfterLookupRef(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - ar->err.Dispose(); - ar->name.Dispose(); ar->callback.Dispose(); delete ar; diff --git a/src/repo.h b/src/repo.h index a0f614c45..a1df1ab10 100755 --- a/src/repo.h +++ b/src/repo.h @@ -8,6 +8,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include #include #include +#include #include "../vendor/libgit2/src/git2.h" @@ -44,51 +45,51 @@ class Repo : public EventEmitter { static Handle New(const Arguments& args); static Handle Open(const Arguments& args); - static int EIO_Open(eio_req *req); - static int EIO_AfterOpen(eio_req *req); + static int EIO_Open(eio_req* req); + static int EIO_AfterOpen(eio_req* req); static Handle Lookup(const Arguments& args); - static int EIO_Lookup(eio_req *req); - static int EIO_AfterLookup(eio_req *req); + static int EIO_Lookup(eio_req* req); + static int EIO_AfterLookup(eio_req* req); static Handle Free(const Arguments& args); static Handle Init(const Arguments& args); - static int EIO_Init(eio_req *req); - static int EIO_AfterInit(eio_req *req); + static int EIO_Init(eio_req* req); + static int EIO_AfterInit(eio_req* req); static Handle LookupRef(const Arguments& args); - static int EIO_LookupRef(eio_req *req); - static int EIO_AfterLookupRef(eio_req *req); + static int EIO_LookupRef(eio_req* req); + static int EIO_AfterLookupRef(eio_req* req); private: - git_repository *repo; + git_repository* repo; struct open_request { - Repo *repo; - Persistent err; - Persistent path; + Repo* repo; + int err; + std::string path; Persistent callback; }; struct lookup_request { - Repo *repo; + Repo* repo; Persistent callback; }; struct init_request { - Repo *repo; - Persistent err; - Persistent path; - Persistent is_bare; + Repo* repo; + int err; + std::string path; + bool is_bare; Persistent callback; }; struct lookupref_request { - Repo *repo; - Reference *ref; - Persistent err; - Persistent name; + Repo* repo; + Reference* ref; + int err; + std::string name; Persistent callback; }; }; diff --git a/src/revwalk.cc b/src/revwalk.cc index 002009696..22eaac2e3 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -153,7 +153,7 @@ int RevWalk::EIO_Next(eio_req *req) { next_request *ar = static_cast(req->data); git_commit* ref = ar->commit->GetValue(); - ar->err = Persistent::New(Integer::New(ar->revwalk->Next(&ref))); + ar->err = ar->revwalk->Next(&ref); ar->commit->SetValue(ref); @@ -168,7 +168,7 @@ int RevWalk::EIO_AfterNext(eio_req *req) { ar->revwalk->Unref(); Local argv[1]; - argv[0] = *ar->err; + argv[0] = Integer::New(ar->err); TryCatch try_catch; @@ -177,7 +177,6 @@ int RevWalk::EIO_AfterNext(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - ar->err.Dispose(); ar->callback.Dispose(); delete ar; diff --git a/src/revwalk.h b/src/revwalk.h index 679f09aa7..d36114a22 100755 --- a/src/revwalk.h +++ b/src/revwalk.h @@ -55,7 +55,7 @@ class RevWalk : public EventEmitter { struct next_request { RevWalk *revwalk; Commit *commit; - Persistent err; + int err; Persistent callback; }; }; diff --git a/src/tree.cc b/src/tree.cc index df9beac59..cbada98a0 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -44,7 +44,15 @@ int GitTree::New(git_repository* repo) { } size_t GitTree::EntryCount() { - return git_tree_entrycount(&*this->tree); + return git_tree_entrycount(this->tree); +} + +GitTree::Entry GitTree::EntryByIndex(int idx) { + GitTree::Entry entry; + + entry->SetValue(git_tree_entry_byindex(this->tree, idx)); + + return entry; } int GitTree::SortEntries() { diff --git a/src/tree.h b/src/tree.h index 4207f6853..f860718bb 100755 --- a/src/tree.h +++ b/src/tree.h @@ -76,15 +76,15 @@ class GitTree : public EventEmitter { /** * Get entry by index in the looked up tree. * + * @param idx index of the entry + * * @return git tree entry */ - //GitTree::Entry EntryByIndex(); + GitTree::Entry EntryByIndex(int idx); int SortEntries(); void ClearEntries(); - - protected: /** * Constructor @@ -112,6 +112,29 @@ class GitTree : public EventEmitter { // Experimental class Entry : EventEmitter { + public: + static Persistent constructor_template; + + void GitTree::Initialize (Handle target) { + HandleScope scope; + + Local t = FunctionTemplate::New(New); + + constructor_template = Persistent::New(t); + constructor_template->InstanceTemplate()->SetInternalFieldCount(1); + constructor_template->SetClassName(String::NewSymbol("Tree")); + + NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryCount", EntryCount); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryByIndex", EntryByIndex); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "sortEntries", EntryCount); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "clearEntries", ClearEntries); + + target->Set(String::NewSymbol("Tree"), constructor_template->GetFunction()); + } + + void SetValue(git_tree_entry* entry) { + this->entry = entry; + } private: git_tree_entry* entry; }; diff --git a/src/tree_entry.cc b/src/tree_entry.cc new file mode 100644 index 000000000..a44b01cda --- /dev/null +++ b/src/tree_entry.cc @@ -0,0 +1,37 @@ +/* +Copyright (c) 2011, Tim Branyen @tbranyen +*/ + +#include +#include +#include + +#include "../vendor/libgit2/src/git2.h" + +#include "repo.h" +#include "tree.h" +#include "git_tree.h" + +using namespace v8; +using namespace node; + +void GitTreeEntry::Initialize (Handle target) { + HandleScope scope; + + Local t = FunctionTemplate::New(New); + + constructor_template = Persistent::New(t); + constructor_template->InstanceTemplate()->SetInternalFieldCount(1); + constructor_template->SetClassName(String::NewSymbol("TreeEntry")); + + NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryCount", EntryCount); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryByIndex", EntryByIndex); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "sortEntries", EntryCount); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "clearEntries", ClearEntries); + + target->Set(String::NewSymbol("TreeEntry"), constructor_template->GetFunction()); +} + +void SetValue(git_tree_entry* entry) { + this->entry = entry; +} diff --git a/src/tree_entry.h b/src/tree_entry.h new file mode 100644 index 000000000..b8be140f3 --- /dev/null +++ b/src/tree_entry.h @@ -0,0 +1,25 @@ +/* +Copyright (c) 2011, Tim Branyen @tbranyen +*/ + +#include +#include +#include + +#include "../vendor/libgit2/src/git2.h" + +#include "repo.h" +#include "tree.h" + +using namespace v8; +using namespace node; + +class GitTreeEntry : EventEmitter { + public: + static void GitTree::Initialize (Handle target); + void SetValue(git_tree_entry* entry); + + private: + git_tree_entry* entry; +}; + From 6521f622cb53abb0a86eb80db54398d85ef1f6b2 Mon Sep 17 00:00:00 2001 From: tim Date: Fri, 11 Mar 2011 02:33:36 -0500 Subject: [PATCH 10/35] updated git tree to exist sas its own entity broken on the mac atm massive segmentation fault --- src/base.cc | 2 ++ src/tree.cc | 25 ++++++++++++++++++------- src/tree.h | 36 ++++-------------------------------- src/tree_entry.cc | 26 ++++++++++++++------------ src/tree_entry.h | 37 +++++++++++++++++++++++++++++++++++-- wscript | 2 +- 6 files changed, 74 insertions(+), 54 deletions(-) diff --git a/src/base.cc b/src/base.cc index cf2e332fe..5874011ff 100755 --- a/src/base.cc +++ b/src/base.cc @@ -18,6 +18,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "commit.h" #include "revwalk.h" #include "tree.h" +#include "tree_entry.h" extern "C" void init(Handle target) { HandleScope scope; @@ -32,4 +33,5 @@ extern "C" void init(Handle target) { Commit::Initialize(target); RevWalk::Initialize(target); GitTree::Initialize(target); + GitTreeEntry::Initialize(); } diff --git a/src/tree.cc b/src/tree.cc index cbada98a0..f7bb75c1f 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -10,6 +10,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "repo.h" #include "tree.h" +#include "tree_entry.h" using namespace v8; using namespace node; @@ -28,6 +29,8 @@ void GitTree::Initialize (Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor_template, "sortEntries", EntryCount); NODE_SET_PROTOTYPE_METHOD(constructor_template, "clearEntries", ClearEntries); + constructor_template->Set(String::NewSymbol("TreeEntry"), GitTreeEntry::constructor_template->GetFunction()); + target->Set(String::NewSymbol("Tree"), constructor_template->GetFunction()); } @@ -47,12 +50,8 @@ size_t GitTree::EntryCount() { return git_tree_entrycount(this->tree); } -GitTree::Entry GitTree::EntryByIndex(int idx) { - GitTree::Entry entry; - - entry->SetValue(git_tree_entry_byindex(this->tree, idx)); - - return entry; +git_tree_entry* GitTree::EntryByIndex(int idx) { + return git_tree_entry_byindex(this->tree, idx); } int GitTree::SortEntries() { @@ -98,9 +97,21 @@ Handle GitTree::EntryByIndex(const Arguments& args) { GitTree *tree = ObjectWrap::Unwrap(args.This()); + if(args.Length() == 0 || !args[0]->IsObject()) { + return ThrowException(Exception::Error(String::New("TreeEntry is required and must be a Object."))); + } + + if(args.Length() == 1 || !args[1]->IsObject()) { + return ThrowException(Exception::Error(String::New("Index is required and must be a Number."))); + } + + GitTreeEntry* entry = ObjectWrap::Unwrap(args[0]->ToObject()); + + int index = args[1]->ToInteger()->Value(); + + entry->SetValue(tree->EntryByIndex(index)); return Undefined(); - //return Local::New(Integer::New(count)); } Handle GitTree::SortEntries(const Arguments& args) { diff --git a/src/tree.h b/src/tree.h index f860718bb..ac0cb69ff 100755 --- a/src/tree.h +++ b/src/tree.h @@ -12,6 +12,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "../vendor/libgit2/src/git2.h" #include "repo.h" +#include "tree_entry.h" using namespace v8; using namespace node; @@ -49,9 +50,9 @@ class GitTree : public EventEmitter { git_tree* GetValue(); /** - * Mutator for Object + * Mutator for GitTree * - * @param obj a git_object object + * @param obj a git_tree object */ void SetValue(git_tree* tree); @@ -80,7 +81,7 @@ class GitTree : public EventEmitter { * * @return git tree entry */ - GitTree::Entry EntryByIndex(int idx); + git_tree_entry* EntryByIndex(int idx); int SortEntries(); void ClearEntries(); @@ -110,35 +111,6 @@ class GitTree : public EventEmitter { static Handle SortEntries(const Arguments& args); static Handle ClearEntries(const Arguments& args); - // Experimental - class Entry : EventEmitter { - public: - static Persistent constructor_template; - - void GitTree::Initialize (Handle target) { - HandleScope scope; - - Local t = FunctionTemplate::New(New); - - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("Tree")); - - NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryCount", EntryCount); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryByIndex", EntryByIndex); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "sortEntries", EntryCount); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "clearEntries", ClearEntries); - - target->Set(String::NewSymbol("Tree"), constructor_template->GetFunction()); - } - - void SetValue(git_tree_entry* entry) { - this->entry = entry; - } - private: - git_tree_entry* entry; - }; - private: /** * Internal reference to git_tree object diff --git a/src/tree_entry.cc b/src/tree_entry.cc index a44b01cda..cf8ac224b 100644 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -10,28 +10,30 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "repo.h" #include "tree.h" -#include "git_tree.h" +#include "tree_entry.h" using namespace v8; using namespace node; -void GitTreeEntry::Initialize (Handle target) { - HandleScope scope; - +void GitTreeEntry::Initialize() { Local t = FunctionTemplate::New(New); constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("TreeEntry")); - - NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryCount", EntryCount); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "entryByIndex", EntryByIndex); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "sortEntries", EntryCount); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "clearEntries", ClearEntries); - - target->Set(String::NewSymbol("TreeEntry"), constructor_template->GetFunction()); } -void SetValue(git_tree_entry* entry) { +void GitTreeEntry::SetValue(git_tree_entry* entry) { this->entry = entry; } + +Handle GitTreeEntry::New(const Arguments& args) { + HandleScope scope; + + GitTreeEntry *entry = new GitTreeEntry(); + + entry->Wrap(args.This()); + + return args.This(); +} +Persistent GitTreeEntry::constructor_template; diff --git a/src/tree_entry.h b/src/tree_entry.h index b8be140f3..70308df52 100644 --- a/src/tree_entry.h +++ b/src/tree_entry.h @@ -2,6 +2,9 @@ Copyright (c) 2011, Tim Branyen @tbranyen */ +#ifndef GITTREEENTRY_H +#define GITTREEENTRY_H + #include #include #include @@ -14,12 +17,42 @@ Copyright (c) 2011, Tim Branyen @tbranyen using namespace v8; using namespace node; +/** + * Class wrapper for libgit2 git_tree_entry + */ class GitTreeEntry : EventEmitter { public: - static void GitTree::Initialize (Handle target); - void SetValue(git_tree_entry* entry); + /** + * v8::FunctionTemplate used to create Node.js constructor + */ + static Persistent constructor_template; + + /** + * Used to intialize the EventEmitter from Node.js + * + * @param target v8::Object the Node.js module object + */ + static void Initialize(); + + /** + * Accessor for GitTreeEntry + * + * @return the internal git_tree_entry reference + */ + git_tree_entry* GetValue(); + + /** + * Mutator for GitTreeEntry + * + * @param obj a git_tree_entry object + */ + void SetValue(git_tree_entry* tree); + + protected: + static Handle New(const Arguments& args); private: git_tree_entry* entry; }; +#endif diff --git a/wscript b/wscript index c5dbfa148..172fa6ed3 100755 --- a/wscript +++ b/wscript @@ -36,6 +36,6 @@ def build(bld): main = bld.new_task_gen('cxx', 'shlib', 'node_addon') main.target = 'nodegit' - main.source = 'src/base.cc src/sig.cc src/blob.cc src/error.cc src/object.cc src/reference.cc src/repo.cc src/commit.cc src/oid.cc src/revwalk.cc src/tree.cc' + main.source = 'src/base.cc src/sig.cc src/blob.cc src/error.cc src/object.cc src/reference.cc src/repo.cc src/commit.cc src/oid.cc src/revwalk.cc src/tree.cc src/tree_entry.cc' main.rpath = abspath('vendor/libgit2/build/shared') main.uselib = 'GIT2' From 53b0d76d4fa480d02342c32f084fb592fe7beef2 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Fri, 11 Mar 2011 03:28:00 -0500 Subject: [PATCH 11/35] Added tree entry updated convenience api --- lib/commit.js | 23 ++++++++++++----------- lib/index.js | 6 ++++-- lib/tree.js | 44 +++++++++++++++++++++++--------------------- lib/tree_entry.js | 24 ++++++++++++++++++++++++ src/base.cc | 2 +- src/tree.cc | 2 -- src/tree_entry.cc | 19 ++++++++++++++++++- src/tree_entry.h | 4 +++- 8 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 lib/tree_entry.js diff --git a/lib/commit.js b/lib/commit.js index b95819e87..1c970b010 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -76,6 +76,7 @@ var _Commit = function( obj ) { enumerable: true }); + self.lookup = function( oid, callback ) { self.commit.lookup( self.repo, oid, function() { var args = Array.prototype.slice.call( arguments ); @@ -86,17 +87,17 @@ var _Commit = function( obj ) { }); }; - //self.tree = function() { - // var tree = new git.raw.Tree( self.repo ); - // if( tree.error ) { - // throw git.error( tree.error ); - // } - // else { - // self.commit.tree( tree ); - // } - - // return git.tree( tree ); - //}; + self.tree = function() { + var tree = new git.raw.Tree( self.repo ); + if( tree.error ) { + throw git.error( tree.error ); + } + else { + self.commit.tree( tree ); + } + + return git.tree( tree ); + }; return self; }; diff --git a/lib/index.js b/lib/index.js index 9be04db19..1acfd719f 100755 --- a/lib/index.js +++ b/lib/index.js @@ -7,7 +7,8 @@ var util = require( './util.js' ).util, ref = require( './ref.js' ).ref, revwalk = require( './revwalk.js' ).revwalk, commit = require( './commit.js' ).commit, - tree = require( './tree.js' ).tree; + tree = require( './tree.js' ).tree, + entry = require( './tree_entry.js' ).entry; exports.raw = require( '../build/default/nodegit' ); exports.blob = blob; @@ -18,5 +19,6 @@ exports.oid = oid; exports.sig = sig; exports.error = error; exports.revwalk = revwalk; -exports.tree = tree; exports.commit = commit; +exports.tree = tree; +exports.entry = entry; diff --git a/lib/tree.js b/lib/tree.js index e6becaf82..ce026c304 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -3,29 +3,13 @@ var git = require( '../' ); var _Tree = function( obj, tree ) { var self = {}; - //Object.defineProperty( self, 'length', { - // get: function() { - // return self.tree.entryCount(); - // }, - // enumerable: true - //}); - - self.each = function( callback ) { - if( !callback ) { return; } - - var commit, i; - for(i=0, len=self.length; i target) { Commit::Initialize(target); RevWalk::Initialize(target); GitTree::Initialize(target); - GitTreeEntry::Initialize(); + GitTreeEntry::Initialize(target); } diff --git a/src/tree.cc b/src/tree.cc index f7bb75c1f..24d5c833f 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -29,8 +29,6 @@ void GitTree::Initialize (Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor_template, "sortEntries", EntryCount); NODE_SET_PROTOTYPE_METHOD(constructor_template, "clearEntries", ClearEntries); - constructor_template->Set(String::NewSymbol("TreeEntry"), GitTreeEntry::constructor_template->GetFunction()); - target->Set(String::NewSymbol("Tree"), constructor_template->GetFunction()); } diff --git a/src/tree_entry.cc b/src/tree_entry.cc index cf8ac224b..10dd3a657 100644 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -15,18 +15,27 @@ Copyright (c) 2011, Tim Branyen @tbranyen using namespace v8; using namespace node; -void GitTreeEntry::Initialize() { +void GitTreeEntry::Initialize(Handle target) { Local t = FunctionTemplate::New(New); constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("TreeEntry")); + + NODE_SET_PROTOTYPE_METHOD(constructor_template, "name", Name); + + target->Set(String::NewSymbol("TreeEntry"), constructor_template->GetFunction()); } void GitTreeEntry::SetValue(git_tree_entry* entry) { this->entry = entry; } +const char* GitTreeEntry::Name() { + return git_tree_entry_name(this->entry); +} + + Handle GitTreeEntry::New(const Arguments& args) { HandleScope scope; @@ -36,4 +45,12 @@ Handle GitTreeEntry::New(const Arguments& args) { return args.This(); } + +Handle GitTreeEntry::Name(const Arguments& args) { + HandleScope scope; + + GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + + return String::New(entry->Name()); +} Persistent GitTreeEntry::constructor_template; diff --git a/src/tree_entry.h b/src/tree_entry.h index 70308df52..f98a8eb08 100644 --- a/src/tree_entry.h +++ b/src/tree_entry.h @@ -32,7 +32,7 @@ class GitTreeEntry : EventEmitter { * * @param target v8::Object the Node.js module object */ - static void Initialize(); + static void Initialize(Handle target); /** * Accessor for GitTreeEntry @@ -47,9 +47,11 @@ class GitTreeEntry : EventEmitter { * @param obj a git_tree_entry object */ void SetValue(git_tree_entry* tree); + const char* Name(); protected: static Handle New(const Arguments& args); + static Handle Name(const Arguments& args); private: git_tree_entry* entry; From f68a88f80d8b939e83db8db96dfe92975f270d59 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Fri, 11 Mar 2011 13:52:17 -0500 Subject: [PATCH 12/35] updated github pages to 0.0.2 --- css/common.css | 10 ++++++++++ index.html | 30 +++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/css/common.css b/css/common.css index 40023c345..e61f305c6 100644 --- a/css/common.css +++ b/css/common.css @@ -41,6 +41,16 @@ pre { font-size: 200%; } + #container .branding .small a { + text-decoration: none; + } + +#container .command, #container code { + -moz-box-shadow: 0px 0px 14px #CCC; + -webkit-box-shadow: 0px 0px 14px #CCC; + box-shadow: 0px 0px 14px #CCC; +} + #container .command { padding: 10px; background-color: #333; diff --git a/index.html b/index.html index 68d3913f4..bb9e98ef7 100644 --- a/index.html +++ b/index.html @@ -33,15 +33,16 @@
- Version 0.0.1 Node.js libgit2 asynchronous native bindings + Version 0.0.2 Node.js libgit2 asynchronous native bindings

A collection of non-blocking Node.js libgit2 bindings, raw api, convenience api, unit tests, documentation and accomodations to make contributing easier.

-

dependencies

+

require

@@ -52,8 +53,7 @@

install

use

-

- emulate `git log` +

emulate `git log`


   // Load in the module
   var git = require( 'nodegit' );
@@ -78,7 +78,27 @@ 

use

});
-

+ +

view commit tree and blob information

+

+  // Load in the module
+  var git = require( 'nodegit' );
+  // Open a repository for reading
+  git.repo( '.git', function( err, repo ) {
+      // Success is always 0, failure is always an error string
+      if( err ) { throw err; }
+      // Use the master branch
+      repo.branch( 'master', function( err, branch ) {
+          if( err ) { throw err; }
+          // Iterate over the revision history
+          branch.tree().each( function( i, entry ) {
+            console.log( entry.name );
+            console.log( entry.content );
+          });
+      });
+  });
+          
+        

download

From 3bc5d33a1f0cb60b0d63d8c327e5403ac9df5e7c Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Sat, 12 Mar 2011 00:24:43 -0500 Subject: [PATCH 13/35] convenience api tree example and added ability to read entry filename --- example/convenience-tree.js | 15 +++++++++++++++ lib/tree_entry.js | 7 +++++++ src/tree.cc | 2 +- src/tree_entry.cc | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 example/convenience-tree.js diff --git a/example/convenience-tree.js b/example/convenience-tree.js new file mode 100644 index 000000000..27dce1216 --- /dev/null +++ b/example/convenience-tree.js @@ -0,0 +1,15 @@ +var git = require( 'nodegit' ); + +git.repo( '../.git', function( err, repo ) { + if( err ) { throw err; } + + repo.branch( 'master', function( err, branch ) { + if( err ) { throw err; } + + branch.tree().each( function( i, entry ) { + + console.log( entry.name ); + + }); + }); +}); diff --git a/lib/tree_entry.js b/lib/tree_entry.js index a127d0b6b..9781e8e4e 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -10,6 +10,13 @@ var _TreeEntry = function( obj ) { enumerable: true }); + Object.defineProperty( self, 'content', { + get: function() { + return self.entry.content(); + }, + enumerable: true + }); + // Internal references to Git references if ( obj instanceof git.raw.TreeEntry ) { self.entry = obj; diff --git a/src/tree.cc b/src/tree.cc index 24d5c833f..ccdca43f2 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -99,7 +99,7 @@ Handle GitTree::EntryByIndex(const Arguments& args) { return ThrowException(Exception::Error(String::New("TreeEntry is required and must be a Object."))); } - if(args.Length() == 1 || !args[1]->IsObject()) { + if(args.Length() == 1 || !args[1]->IsNumber()) { return ThrowException(Exception::Error(String::New("Index is required and must be a Number."))); } diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 10dd3a657..a2a99c220 100644 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -35,6 +35,9 @@ const char* GitTreeEntry::Name() { return git_tree_entry_name(this->entry); } +int GitTreeEntry::ToObject(git_object** object, git_tree_entry* entry) { + return git_tree_entry_2object(object, entry); +} Handle GitTreeEntry::New(const Arguments& args) { HandleScope scope; From 908d7c55939307c732dd2535e354e13564c0a354 Mon Sep 17 00:00:00 2001 From: tim Date: Sat, 12 Mar 2011 01:45:50 -0500 Subject: [PATCH 14/35] added in objects to library and implemented their methods, started working on tree updates --- example/convenience-tree.js | 1 + lib/blob.js | 17 +++++++-- lib/index.js | 2 ++ lib/obj.js | 71 +++++++++++++++++++++++++++++++++++++ lib/tree_entry.js | 10 +++++- src/tree_entry.cc | 24 +++++++++++-- src/tree_entry.h | 3 ++ 7 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 lib/obj.js diff --git a/example/convenience-tree.js b/example/convenience-tree.js index 27dce1216..3a007f1ac 100644 --- a/example/convenience-tree.js +++ b/example/convenience-tree.js @@ -9,6 +9,7 @@ git.repo( '../.git', function( err, repo ) { branch.tree().each( function( i, entry ) { console.log( entry.name ); + console.log( entry.content ); }); }); diff --git a/lib/blob.js b/lib/blob.js index 0b835e2bb..ec31efebe 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -11,8 +11,21 @@ var _Blob = function( obj ) { self.blob = obj; } - self.content = function() { - return self.blob.rawContent(); + Object.defineProperty( self, 'raw', { + get: function() { + return self.blob.rawContent(); + }, + enumerable: true + }); + + + self.lookup = function( oid ) { + self.blob.lookup( self.repo, oid, function() { + var args = Array.prototype.slice.call( arguments ); + args[0] = git.util().error( args[0] ); + + callback.apply( self, args.concat( self ) ); + }); }; return self; diff --git a/lib/index.js b/lib/index.js index 1acfd719f..5b2aee9fc 100755 --- a/lib/index.js +++ b/lib/index.js @@ -4,6 +4,7 @@ var util = require( './util.js' ).util, error = require( './error.js' ).error, sig = require( './sig.js' ).sig, oid = require( './oid.js' ).oid, + oid = require( './obj.js' ).obj, ref = require( './ref.js' ).ref, revwalk = require( './revwalk.js' ).revwalk, commit = require( './commit.js' ).commit, @@ -16,6 +17,7 @@ exports.util = util; exports.repo = repo; exports.ref = ref; exports.oid = oid; +exports.obj = obj; exports.sig = sig; exports.error = error; exports.revwalk = revwalk; diff --git a/lib/obj.js b/lib/obj.js new file mode 100644 index 000000000..163b02600 --- /dev/null +++ b/lib/obj.js @@ -0,0 +1,71 @@ +var git = require( '../' ); + +var _Object = function( obj ) { + var self = {}; + + if( obj instanceof git.raw.Object ) { + self.obj = obj; + } + else { + self.obj = new git.raw.Object(); + } + + Object.defineProperty( self, 'id', { + get: function() { + }, + enumerable: true + }); + + Object.defineProperty( self, 'type', { + get: function() { + return self.obj.type(); + }, + enumerable: true + }); + + Object.defineProperty( self, 'length', { + get: function() { + return self.obj.size(); + }, + enumerable: true + }); + + Object.defineProperty( self, 'isLoose', { + get: function() { + return self.obj.typeIsLoose(); + }, + enumerable: true + }); + + self.id = function() { + var oid = git.oid(); + + self.obj.id( oid.oid ); + + return oid; + }; + + self.owner = function() { + var repo = git.repo(); + + self.obj.owner( repo.repo ); + + return repo; + }; + + self.toString = function() { + return self.obj.type2String(); + }; + + self.toType = function( type ) { + return self.obj.toType( type ); + }; + + self.free = function() { + return self.obj.free(); + }; + + return self; +}; + +exports.obj = _Object; diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 9781e8e4e..eceab8789 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -12,7 +12,15 @@ var _TreeEntry = function( obj ) { Object.defineProperty( self, 'content', { get: function() { - return self.entry.content(); + var obj = git.obj(), + blob; + + self.entry.toObject( obj.obj ); + + blob = git.blob( obj.owner() ); + blob.lookup( oid.oid ); + + return blob.content(); }, enumerable: true }); diff --git a/src/tree_entry.cc b/src/tree_entry.cc index a2a99c220..99b8f57ae 100644 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -10,6 +10,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "repo.h" #include "tree.h" +#include "object.h" #include "tree_entry.h" using namespace v8; @@ -23,6 +24,7 @@ void GitTreeEntry::Initialize(Handle target) { constructor_template->SetClassName(String::NewSymbol("TreeEntry")); NODE_SET_PROTOTYPE_METHOD(constructor_template, "name", Name); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "toObject", ToObject); target->Set(String::NewSymbol("TreeEntry"), constructor_template->GetFunction()); } @@ -35,8 +37,8 @@ const char* GitTreeEntry::Name() { return git_tree_entry_name(this->entry); } -int GitTreeEntry::ToObject(git_object** object, git_tree_entry* entry) { - return git_tree_entry_2object(object, entry); +int GitTreeEntry::ToObject(git_object** obj) { + return git_tree_entry_2object(obj, entry); } Handle GitTreeEntry::New(const Arguments& args) { @@ -56,4 +58,22 @@ Handle GitTreeEntry::Name(const Arguments& args) { return String::New(entry->Name()); } + +Handle GitTreeEntry::ToObject(const Arguments& args) { + HandleScope scope; + + GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + + if(args.Length() == 0 || !args[0]->IsObject()) { + return ThrowException(Exception::Error(String::New("Object is required and must be an Object."))); + } + + GitObject*obj = ObjectWrap::Unwrap(args[0]->ToObject()); + + git_object* out; + entry->ToObject(&out); + obj->SetValue(out); + + return Undefined(); +} Persistent GitTreeEntry::constructor_template; diff --git a/src/tree_entry.h b/src/tree_entry.h index f98a8eb08..7d37ea6ee 100644 --- a/src/tree_entry.h +++ b/src/tree_entry.h @@ -13,6 +13,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "repo.h" #include "tree.h" +#include "object.h" using namespace v8; using namespace node; @@ -48,10 +49,12 @@ class GitTreeEntry : EventEmitter { */ void SetValue(git_tree_entry* tree); const char* Name(); + int ToObject(git_object** obj); protected: static Handle New(const Arguments& args); static Handle Name(const Arguments& args); + static Handle ToObject(const Arguments& args); private: git_tree_entry* entry; From a793ed10e6d059dfea784774f50eb117435ed20b Mon Sep 17 00:00:00 2001 From: tim Date: Sat, 12 Mar 2011 01:51:50 -0500 Subject: [PATCH 15/35] Added Built in Boston logo --- css/common.css | 6 ++++++ index.html | 2 ++ 2 files changed, 8 insertions(+) diff --git a/css/common.css b/css/common.css index e61f305c6..28a621ff1 100644 --- a/css/common.css +++ b/css/common.css @@ -1,6 +1,12 @@ body { font-family: Georgia, sans-serif; } + body .boston { + padding: 20px; + position: relative; + left: 50%; + margin-left: -120px; + } .forkme { position: absolute; diff --git a/index.html b/index.html index bb9e98ef7..aca407895 100644 --- a/index.html +++ b/index.html @@ -126,6 +126,8 @@

download

+ Built in Boston USA + - - - - - diff --git a/js/highlight.pack.js b/js/highlight.pack.js deleted file mode 100644 index 6da5ed664..000000000 --- a/js/highlight.pack.js +++ /dev/null @@ -1 +0,0 @@ -var hljs=new function(){var p={};var a={};function n(c){return c.replace(/&/gm,"&").replace(//gm,">")}function k(s,r){if(!s){return false}for(var c=0;c"}function B(C){return""}while(z.length||A.length){var w=v().splice(0,1)[0];x+=n(y.substr(s,w.offset-s));s=w.offset;if(w.event=="start"){x+=t(w.node);u.push(w.node)}else{if(w.event=="stop"){var r=u.length;do{r--;var c=u[r];x+=B(c)}while(c!=w.node);u.splice(r,1);while(r'+n(M[0])+""}else{O+=n(M[0])}R=Q.lR.lastIndex;M=Q.lR.exec(N)}O+=n(N.substr(R,N.length-R));return O}function L(r,N){if(N.subLanguage&&a[N.subLanguage]){var M=g(N.subLanguage,r);u+=M.keyword_count;C+=M.r;return M.value}else{return G(r,N)}}function J(N,r){var M=N.nM?"":'';if(N.rB){s+=M;N.buffer=""}else{if(N.eB){s+=n(r)+M;N.buffer=""}else{s+=M;N.buffer=r}}D[D.length]=N}function F(M,O,R){var P=D[D.length-1];if(R){s+=L(P.buffer+M,P);return false}var S=A(O,P);if(S){s+=L(P.buffer+M,P);J(S,O);C+=S.r;return S.rB}var r=x(D.length-1,O);if(r){var T=P.nM?"":"";if(P.rE){s+=L(P.buffer+M,P)+T}else{if(P.eE){s+=L(P.buffer+M,P)+T+n(O)}else{s+=L(P.buffer+M+O,P)+T}}while(r>1){T=D[D.length-2].nM?"":"";s+=T;r--;D.length--}var Q=D[D.length-1];D.length--;D[D.length-1].buffer="";if(Q.starts){for(var N=0;N1){throw"Illegal"}return{language:K,r:C,keyword_count:u,value:s}}catch(H){if(H=="Illegal"){return{language:null,r:0,keyword_count:0,value:n(E)}}else{throw H}}}function i(){function r(y,x){if(y.compiled){return}if(y.b){y.bR=e(x,"^"+y.b)}if(y.e){y.eR=e(x,"^"+y.e)}if(y.i){y.iR=e(x,"^(?:"+y.i+")")}if(y.r==undefined){y.r=1}if(!y.displayClassName){y.displayClassName=y.cN}if(!y.cN){y.nM=true}for(var w in y.k){if(!y.k.hasOwnProperty(w)){continue}if(y.k[w] instanceof Object){y.keywordGroups=y.k}else{y.keywordGroups={keyword:y.k}}break}y.sm=[];if(y.c){for(var v=0;vz.keyword_count+z.r){z=w}if(w.keyword_count+w.r>y.keyword_count+y.r){z=y;y=w}}}var u=v.className;if(!u.match(y.language)){u=u?(u+" "+y.language):y.language}var c=d(v);if(c.length){var s=document.createElement("pre");s.innerHTML=y.value;y.value=m(c,d(s),C)}if(A){y.value=y.value.replace(/^((<[^>]+>|\t)+)/gm,function(D,G,F,E){return G.replace(/\t/g,A)})}if(r){y.value=y.value.replace(/\n/g,"
")}if(/MSIE [678]/.test(navigator.userAgent)&&v.tagName=="CODE"&&v.parentNode.tagName=="PRE"){var s=v.parentNode;var x=document.createElement("div");x.innerHTML="
"+y.value+"
";v=x.firstChild.firstChild;x.firstChild.cN=s.cN;s.parentNode.replaceChild(x.firstChild,s)}else{v.innerHTML=y.value}v.className=u;v.dataset={};v.dataset.result={language:y.language,kw:y.keyword_count,re:y.r};if(z&&z.language){v.dataset.second_best={language:z.language,kw:z.keyword_count,re:z.r}}}function l(){if(l.called){return}l.called=true;f();if(arguments.length){for(var c=0;c|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:["escape"],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:["escape"],r:0};this.BE={cN:"escape",b:"\\\\.",e:this.IMR,nM:true,r:0};this.CLCM={cN:"comment",b:"//",e:"$",r:0};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NUMBER_MODE={cN:"number",b:this.NR,e:this.IMR,r:0};this.CNM={cN:"number",b:this.CNR,e:this.IMR,r:0};this.inherit=function(c,t){var s={};for(var r in c){s[r]=c[r]}if(t){for(var r in t){s[r]=t[r]}}return s}}();var initHighlightingOnLoad=hljs.initHighlightingOnLoad;hljs.LANGUAGES.javascript={dM:{l:[hljs.UIR],c:["string","comment","number","regexp_container","function"],k:{keyword:{"in":1,"if":1,"for":1,"while":1,"finally":1,"var":1,"new":1,"function":1,"do":1,"return":1,"void":1,"else":1,"break":1,"catch":1,"instanceof":1,"with":1,"throw":1,"case":1,"default":1,"try":1,"this":1,"switch":1,"continue":1,"typeof":1,"delete":1},literal:{"true":1,"false":1,"null":1}}},m:[hljs.CLCM,hljs.CBLCLM,hljs.CNM,hljs.ASM,hljs.QSM,hljs.BE,{cN:"regexp_container",b:"("+hljs.RSR+"|case|return|throw)\\s*",e:hljs.IMR,nM:true,l:[hljs.IR],k:{"return":1,"throw":1,"case":1},c:["comment",{cN:"regexp",b:"/.*?[^\\\\/]/[gim]*",e:hljs.IMR}],r:0},{cN:"function",b:"\\bfunction\\b",e:"{",l:[hljs.UIR],k:{"function":1},c:[{cN:"title",b:"[A-Za-z$_][0-9A-Za-z$_]*",e:hljs.IMR},{cN:"params",b:"\\(",e:"\\)",c:["string","comment"]}]}]}; \ No newline at end of file From 802072bb355dafd95b8d2b5d73c5e414e3e60981 Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 13 Mar 2011 14:47:46 -0400 Subject: [PATCH 25/35] Made corrections to reference and repo api to align with new libgit2 changes --- lib/ref.js | 11 +++++++++++ lib/repo.js | 16 +--------------- vendor/libgit2/.lock-wafbuild | 2 +- vendor/libgit2/.lock-wscript | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/ref.js b/lib/ref.js index b945c804a..84d786a0e 100644 --- a/lib/ref.js +++ b/lib/ref.js @@ -11,6 +11,17 @@ var _Ref = function( obj ) { self.ref = obj; } + self.lookup = function( name, callback ) { + if( !callback ) { return; } + + self.ref.lookup( self.repo, name, function() { + var args = Array.prototype.slice.call( arguments ); + args[0] = git.util().error( args[0] ); + + callback.apply( self, args.concat( self ) ); + }); + }; + self.oid = function() { var oid = git.oid(); diff --git a/lib/repo.js b/lib/repo.js index 610c45531..84d1b5ec5 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -26,7 +26,7 @@ var _Repo = function( dir, callback ) { self.branch = function( name, callback ) { if( !callback ) { return; } - self.ref( 'refs/heads/' + name, function( err, ref ) { + git.ref( self.repo ).lookup( 'refs/heads/' + name, function( err, ref ) { if( err ) { throw err; } git.commit( self.repo ).lookup( ref.oid().oid, function() { @@ -38,20 +38,6 @@ var _Repo = function( dir, callback ) { }); }; - // Work with a specific head reference - self.ref = function( name, callback ) { - if( !callback ) { return; } - - var ref = git.ref( self.repo ); - - self.repo.lookupRef( ref.ref, name, function() { - var args = Array.prototype.slice.call( arguments ); - args[0] = git.util().error( args[0] ); - - callback.apply( ref, args.concat( ref ) ); - }); - }; - // Find a single commit self.commit = function( sha, callback ) { if( !callback ) { return; } diff --git a/vendor/libgit2/.lock-wafbuild b/vendor/libgit2/.lock-wafbuild index f41f896f1..7c3c622fb 100644 --- a/vendor/libgit2/.lock-wafbuild +++ b/vendor/libgit2/.lock-wafbuild @@ -1,5 +1,5 @@ argv = ['waf', 'configure'] -environ = {'SSH_AUTH_SOCK': '/tmp/launch-7qUexP/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273', 'SHELL': '/bin/bash', 'LOGNAME': 'timbranyen', 'USER': 'timbranyen', 'HOME': '/Users/timbranyen', 'PATH': '/usr/local/mysql-5.1.48-osx10.6-x86_64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin', 'DISPLAY': '/tmp/launch-7UXtiF/org.x:0', 'TMPDIR': '/var/folders/0j/0jwileIVGx44xbVHEc8nvk+++TI/-Tmp-/', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-m9ROAk/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '3', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'PWD': '/Users/timbranyen/Projects/nodegit/vendor/libgit2', '_': '/usr/bin/python', 'COMMAND_MODE': 'unix2003'} +environ = {'_': '/usr/bin/python', 'SSH_AUTH_SOCK': '/tmp/launch-7qUexP/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273', 'SHELL': '/bin/bash', 'LOGNAME': 'timbranyen', 'USER': 'timbranyen', 'HOME': '/Users/timbranyen', 'PATH': '/usr/local/mysql-5.1.48-osx10.6-x86_64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin', 'DISPLAY': '/tmp/launch-7UXtiF/org.x:0', 'MAKEFLAGS': '', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-m9ROAk/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '3', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'MAKELEVEL': '1', 'PWD': '/Users/timbranyen/Projects/nodegit/vendor/libgit2', 'TMPDIR': '/var/folders/0j/0jwileIVGx44xbVHEc8nvk+++TI/-Tmp-/', 'MFLAGS': '', 'COMMAND_MODE': 'unix2003'} files = ['/Users/timbranyen/Projects/nodegit/vendor/libgit2/wscript'] hash = -8574636053425009178 options = {'files': '', 'use_sqlite': True, 'sha1': 'builtin', 'jobs': 4, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'top': '', 'destdir': '', 'keep': False, 'zones': '', 'debug': False, 'prefix': '/usr/local/', 'download': False, 'msvc': None, 'force': False, 'arch': 'x86', 'targets': '', 'check_c_compiler': 'gcc', 'out': ''} diff --git a/vendor/libgit2/.lock-wscript b/vendor/libgit2/.lock-wscript index 2addecccd..8fd332a3d 100644 --- a/vendor/libgit2/.lock-wscript +++ b/vendor/libgit2/.lock-wscript @@ -2,7 +2,7 @@ argv = ['/usr/local/bin/node-waf', 'configure'] blddir = '/Users/timbranyen/Projects/nodegit/build' commands = {'dist': 0, 'configure': True, 'distcheck': 0, 'install': 0, 'build': 0, 'clean': 0, 'distclean': 0, 'check': 0, 'uninstall': 0} cwd = '/Users/timbranyen/Projects/nodegit' -environ = {'SSH_AUTH_SOCK': '/tmp/launch-7qUexP/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273', 'SHELL': '/bin/bash', 'LOGNAME': 'timbranyen', 'USER': 'timbranyen', 'HOME': '/Users/timbranyen', 'PATH': '/usr/local/mysql-5.1.48-osx10.6-x86_64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin', 'DISPLAY': '/tmp/launch-7UXtiF/org.x:0', 'TMPDIR': '/var/folders/0j/0jwileIVGx44xbVHEc8nvk+++TI/-Tmp-/', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-m9ROAk/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '2', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'PWD': '/Users/timbranyen/Projects/nodegit', '_': '/usr/local/bin/node-waf', 'COMMAND_MODE': 'unix2003'} +environ = {'_': '/usr/local/bin/node-waf', 'SSH_AUTH_SOCK': '/tmp/launch-7qUexP/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273', 'SHELL': '/bin/bash', 'LOGNAME': 'timbranyen', 'USER': 'timbranyen', 'HOME': '/Users/timbranyen', 'PATH': '/usr/local/mysql-5.1.48-osx10.6-x86_64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin', 'DISPLAY': '/tmp/launch-7UXtiF/org.x:0', 'MAKEFLAGS': '', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-m9ROAk/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '2', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'MAKELEVEL': '1', 'PWD': '/Users/timbranyen/Projects/nodegit', 'TMPDIR': '/var/folders/0j/0jwileIVGx44xbVHEc8nvk+++TI/-Tmp-/', 'MFLAGS': '', 'COMMAND_MODE': 'unix2003'} files = [] hash = 0 options = {'compile_targets': None, 'force': False, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'destdir': '', 'keep': False, 'zones': '', 'blddir': '', 'prefix': '/usr/local/', 'jobs': 4, 'srcdir': '', 'check_cxx_compiler': 'g++'} From 5d273117931b094b358fcadd70c26c925c3cc424 Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 13 Mar 2011 14:51:33 -0400 Subject: [PATCH 26/35] Updated lint check to full api --- util/hint-check.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/util/hint-check.js b/util/hint-check.js index 7bc5b7e26..cbcd4e6fb 100644 --- a/util/hint-check.js +++ b/util/hint-check.js @@ -1,6 +1,20 @@ var nodejshint = require( './nodejshint.js' ).test, -files = [ 'lib/index.js', 'lib/ref.js', 'lib/repo.js', 'lib/error.js', 'lib/revwalk.js', 'lib/commit.js', 'lib/util.js', 'lib/oid.js', 'lib/sig.js' ]; +files = [ + 'lib/blob.js', + 'lib/commit.js', + 'lib/error.js', + 'lib/index.js', + 'lib/obj.js', + 'lib/oid.js', + 'lib/ref.js', + 'lib/repo.js', + 'lib/revwalk.js', + 'lib/sig.js', + 'lib/tree.js', + 'lib/tree_entry.js', + 'lib/util.js' +]; nodejshint( files, function( failures ) { if( !files.length ) { From 0b468b9571e7295261b6c8dfb7e28afa0e74441f Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 13 Mar 2011 14:52:04 -0400 Subject: [PATCH 27/35] removed img from gh-pages --- img/boston.gif | Bin 5623 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 img/boston.gif diff --git a/img/boston.gif b/img/boston.gif deleted file mode 100644 index 20aa0c1cab8f7551d6bef246e65b595d2d6cf24a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5623 zcmd5+>0eR_puP8U*(EP(7f3WPHFFEAF|906GgD{MsSM2w7n&Su!paugzLb_gB30;e0y3^E>CmIcwJXxVc9d0AJuU0DS-c z{oA*1C8cLi6r9Y(`3Ps+QKame%X<-n|>pXcLpuK7IO>o|)5qtEc$% znUd3IlTy-iPZWOn@@0H{;-7#1IZ;rQk#$^_SI~9y*4Wsi4Km_KYwo()twS#*7)7%pU|5=aTe{ij-_XY}UwEp&f1vSdQ)N|k_VL`hhQ{KOGjHF%Ei5W|^!Rbx z_4YS!-adJvo1T7uJom)yJH2=BYF@s4IdX6G{Dq6t)6-|=<%+ucM~@zNcHKOEMy{-D zP^mlRWfjk!jlX+msJ*Pv>GZvQ{TD9QT&%e?@%(vx!_^xqb?v1q`GrMo*Ka74^_Q+F zJ34PpO})C_exsrBT3_GY&aUp7+RFtei_eyox8G114Ab}SjlO^XzVgCFbw_7e`T3!t z;ipfZb#!)BRo7l`SCv;(-cWT6kKB9z{=@6nuLlQ*9z1yX^w~3YM_0|IEBEg|c>DHU z*}3!ba~1a=JRBMxxvWs?pFTY!KPSt}FFji}I5a#udcUx!c7bk8F0?0~#dB%s+nC@I$&p8KyEtHa+b(W%gP0k^SwxQ1WI-giqyj6ZQYNT!fyMQBHZwqu6NwPqhg~UG44aawv7qkn1$;KfKCB)0DTq>*`PWyXVm9pcr?I;1tDPquPx;5 zXz!8FZ@jni(#=?F@uIK4`?A|rH=%jh19icqw!I*Lgv%OLi@7?`8;q`bh5~am2x!d7rqQ$x52X`G-Si?c&NclA>1N6z_Ln@JQBz?&)p)k zNbP?kzLSb$8^E2AJ9yF&64s$?nC*pPjv>}tLQa`AbcOmeyQ2B?@;P@xjZOpPkYLLV zJ)s45B)+2-5MSW4jW&@^e-82dgGVLsN1UNIGZ4)Licu5-u#&T#0$V78EB!BTl$1wh z3wX2g+jmD45Z5Y$saOxvN$40$_a~pS{i=F%Rs0&BOUT?jg4H$+lIGUHhduT{+X`Md>|3M1Vj(7`ASZ6E~~u00+pd^H<2 zTXOgbmAY<6h!Zw$#mFsf5_6;n^EGt0I{IQ30)PW%@cA|z>*^>nZ~S#Xf8F|zp=NYi z!zN<>QgbY3uh!4Rv3IwZOH0uVm_+tt-RdOj?RPRbMMmQd{6K#X$}kj?9rIv;@puNg zC`v4uV`=m;?nYaDoNLGmV{0eOhT2Of2PhV?rwI-lxF&V>$8Gjy-J>q)W0d+T-mhet4F%SRw{ndM~F8pY4#n>d=CcIwRgleZ6)(e`>u z5b*^Xr`8@Uw<6Dh6L3ud@?cQ}#8XIaNCVRy<#s)0Ba4!y-fADvtjEf3IHAX}+EE(F z4k>13ude#b>5;!LeI}fH%9vxtrpY?#uoU+06|5vE0j9lI%>*BS&(qbRW^4?@t|JlB zcZ9wNu!w|@ zT&3~h$v=Scin2W(bm5lmh(yK4OSA_p1(PRbu(gr%F2a8Yk+*n7hfNwjb}V#=>y`kh zND{HRU=D({Gl6I0wEkv=gUsRUgGmWWkus$~ZetAw zo^xyR`SMNC(o0@H6W3|9k(+7+T(4jo+CaaV{q7HUt55P6X0G~dt%r0LnRez zvZLw215rho{PKWpP!(WuZ*~uHNGG)ZLpo!E3+X7zu8ppsbYXnxyYuf!QpYQK3x8wu zz&#!KZ(jsXzKkARXmg?Qcmtd3(N8D}kTKjOi`?t8=S?kw{bUn(Eur&ZDaJCP&FYB6 zB_w;wGgHdixNy%R0-Un;X+z3Qc7_Z@`Qe+)`jnpHq{$^MnZ$idrP zI{0L}@g}S`Aqm2nz|Fh1NE|80JFrDqwHNN5r)2W4G{>g?xR4wka#WoR$+z_=()-3q zSuKn16n2}+$`gf;@U)?;u0oxRv9t3$M*dd4yga%`y2Edw>YI1Sk8f-j*#xbp00#xi zY21phtlWJ$C}9)0wcmCyWyY-u3O+LwGs(q^pYCkTU5xE+TeENvpdyB@EaV%H|SBw)M0HCWJCpZjr z4%ZdKde0=&sw0kcy02*i_s2kIf-wy*anyB?U~z(DDGL|oD~4bi#`&O_10-=7n|%Rr z8Jam`gM`Tz2I7#E>db22g@t>~y{95iCEAy89yc~TU2s&Ax%H)CE^r!hZnHtw0yG~4 zyfGhj=0>8d{WN6139{RsMcEI~@GQzAE*i;NJf4D1Dba^)3T8XK)O1CZW&t(`iaJMg zvPKAU?&sYImxWI6vng@4J7SB_fF*I$&}0RY=Y@)_DOCWimjx;T8qp46awWJgbCXz9 zABB-hOz@hI)LEm{o?{~F;bI!fAkZdk5nF&Zw<#%~jr+714PA`n1~M*kkaE@bzC>ip z0I;ve3pev^aneL~ zl)nXxV8fnxY7Rw{EDXxQM8xLD(#S4p`AT3VXL*J%n&q3dD+=Shona=&6WG5-P!Ho> zw%@l)iRNcSN4OMHb5cDSOhHbZG>4)j+;T%-+aaq188Mtl9Q%00G~h_{EZuuND);zZ zYs8!-E(kKmv1Nl?87@L5ugWG~Op2ay!8@&H=tto&JPpS|X0tLQc)3~xOFMY} z=##z)lAv&C8o$at6Gu&qa7o1KV}w#HtO-A-L0ImT^3UldFOGGjo#1Xj>LsKE1kPVT z=yOF`$gkT%WP0lfc3fzx;7-7r;$gm4sssYMbNa6!VlRR>?oR*$} zlyLKf`l{pAG~NQr0z55GhFp`K73Pv*5Oew)yEPQ8;Uc?%Y7x7vmpa$O4!L~WBV~B! zt$fJ&9F47t&rht%@H^9HkM81}mHDA+doaik{gIE@#EVO<5m14Pj=j>UBxa9XQdiJ! zl42g~f&0slKEjZ`@O^DZ= zfi(DNDv>DwoWIv`%&M!iV+ga>P^&uOefZ1EP_= zq?L!@1QwD$Q19ZfR*N%R_hUXoOFC(TVmry`dE=6{=OW~otSwS0#KdCUUojVO10X%f{Jit%eWV^oCrJPakru^5 zCWt9*AAoT`#x*IW5PPIVbFpMHu?4g3#~Jm=}iBa2X>R9UTrv z5)H_5Ky3c2S4o2hNJ{&_R6lg7`Srog*W;(L%Y0GxK$bv$2J1*60`fR%ozIT;H=(HI z?+8(bnWKW|3id7^0Ez|VFbBlL5Fe+>y`zDd0^Gri*b*IVf?$FL-G9ztpx?xDk;VuU zTM@|v^(B_<6_lmL-7iF#Rbi+=oQT(hE-J{)73XA##Yo{yGCio7NpC<;1R}-^lsw>W z(S&NMw`D2rECR4Cn-RHyvAXte8F_O)54S^dJ68jB8_~fp?6;=qTsuTY3J|SD@dB*# zA?!H`&Uu^pwg9l=!TPQp?NLHTJIm<80|XTlKL^t+IPn9$dj@~h%$RaliJ2GvK$aT3 z{3O`jc4!&DKhM9cPy-ZvG$R@?+<}`CY4=BJ-(cX~VJ7!p7~>hfH@b|Z4J;R_A=s&n zpvsfDK&c8+orFl0`w;}-QUkUaI8d(^wa$Dvg$dGV#h}q1X0~t7@z?WV3e zC3mBhSaaDUbEI4BLKF?@+KePnFN<r3u5}oo^S3eCj1>cO|>Ctc+{fz!o0U=xNo@nuG(aL8_!k@Y3fJY_Q4}aH-sZR@h z(evW9acW?l0|niTMzbj9M0%y_>2F8dSpd~tc@3+91C%D4UEx^7Gzlq4;hLGTp}$#_ Si@ Date: Sun, 13 Mar 2011 15:49:20 -0400 Subject: [PATCH 28/35] Added vendor back into gitignore, added lots of new unittests, removed img dir --- .gitignore | 1 + Makefile | 4 +-- src/oid.cc | 8 +++-- test/index.js | 24 +++++++++++-- test/raw-blob.js | 67 ++++++++++++++++++++++++++++++++++++ test/raw-commit.js | 1 - test/raw-obj.js | 38 +++++++++++++++++++++ test/raw-oid.js | 44 ++++++++++++++++++++++++ test/raw-ref.js | 82 +++++++++++++++++++++++++++++++++++++++++++++ test/raw-revwalk.js | 66 +++--------------------------------- util/hint-check.js | 3 +- 11 files changed, 267 insertions(+), 71 deletions(-) create mode 100644 test/raw-blob.js create mode 100644 test/raw-obj.js create mode 100644 test/raw-ref.js diff --git a/.gitignore b/.gitignore index 2bd9cb3ff..d7fb8a18b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .lock-wscript build/ +vendor/ diff --git a/Makefile b/Makefile index 580f85632..0ac04433d 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ clean: @@rm -rf $(BASE)/vendor/libgit2/build unittest: - $(NODE_JS) $(BASE)/test/index.js test + @@$(NODE_JS) $(BASE)/test/index.js test lint: - $(NODE_JS) $(BASE)/util/hint-check.js + @@$(NODE_JS) $(BASE)/util/hint-check.js diff --git a/src/oid.cc b/src/oid.cc index a996791b9..513e134d4 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -25,7 +25,11 @@ void Oid::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor_template, "mkstr", Mkstr); NODE_SET_PROTOTYPE_METHOD(constructor_template, "mkraw", Mkraw); NODE_SET_PROTOTYPE_METHOD(constructor_template, "fmt", Fmt); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "pathFmt", PathFmt); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "allocFmt", AllocFmt); NODE_SET_PROTOTYPE_METHOD(constructor_template, "toString", ToString); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "cpy", Cpy); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "cmp", Cmp); target->Set(String::NewSymbol("Oid"), constructor_template->GetFunction()); } @@ -47,7 +51,7 @@ void Oid::Mkraw(const unsigned char* raw) { } char* Oid::Fmt(char* buffer) { - git_oid_fmt(*&buffer, &this->oid); + git_oid_fmt(buffer, &this->oid); } void Oid::PathFmt(char* str) { @@ -113,7 +117,7 @@ Handle Oid::Fmt(const Arguments& args) { HandleScope scope; - char buffer[40]; + char buffer[32]; oid->Fmt(buffer); return String::New(buffer); } diff --git a/test/index.js b/test/index.js index 373de4825..843987578 100644 --- a/test/index.js +++ b/test/index.js @@ -5,7 +5,7 @@ require.paths.unshift( '../vendor' ); try { var reporter = require( '../vendor/nodeunit' ).reporters.default; } -catch(e) { +catch( e ) { var sys = require( 'sys' ); sys.puts( 'Cannot find nodeunit module.' ); sys.puts( 'You can download submodules for this project by doing:' ); @@ -34,16 +34,34 @@ process.chdir( './test' ); reporter.run( [ // Raw API - 'raw-repo.js', - 'raw-oid.js', + 'raw-blob.js', 'raw-commit.js', 'raw-error.js', + 'raw-obj.js', + 'raw-oid.js', 'raw-ref.js', + 'raw-repo.js', + 'raw-revwalk.js', + // Revwalk + // Sig + // Tree + // Tree Entry + // Util // TODO: //'raw-revwalk.js', // Convenience API 'convenience-repo.js' + // Blob + // Commit + // Error + // Obj + // Oid + // Ref + // RevWalk + // Sig + // Tree + // TreeEntry ] ); diff --git a/test/raw-blob.js b/test/raw-blob.js new file mode 100644 index 000000000..c775298df --- /dev/null +++ b/test/raw-blob.js @@ -0,0 +1,67 @@ +var git = require( '../' ).raw, + rimraf = require( '../vendor/rimraf' ); + +var testRepo = new git.Repo(); + +// Helper functions +var helper = { + // Test if obj is a true function + testFunction: function( test, obj, label ) { + // The object reports itself as a function + test( typeof obj, 'function', label +' reports as a function.' ); + // This ensures the repo is actually a derivative of the Function [[Class]] + test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); + }, + // Test code and handle exception thrown + testException: function( test, fun, label ) { + try { + fun(); + test( false, label ); + } + catch (ex) { + test( true, label ); + } + } +}; + +// Blob +exports.constructor = function( test ){ + test.expect( 3 ); + + // Test for function + helper.testFunction( test.equals, git.Blob, 'Blob' ); + + // Ensure we get an instance of Blob + test.ok( new git.Blob( testRepo ) instanceof git.Blob, 'Invocation returns an instance of Blob' ); + + test.done(); +}; + +// Blob::Lookup +exports.lookup = function( test ) { + var testOid = new git.Oid(), + testBlob = new git.Blob( testRepo ); + + test.expect( 3 ); + + // Test for function + helper.testFunction( test.equals, testBlob.lookup, 'Blob::Lookup' ); + + // Test repo argument existence + helper.testException( test.ok, function() { + testBlob.lookup(); + }, 'Throw an exception if no repo Object' ); + + // Test that both arguments result correctly + //helper.testException( test.ifError, function() { + // testOid.mkstr( "somestr" ); + //}, 'No exception is thrown with proper arguments' ); + + // Test invalid hex id string + //test.equals( -2, testOid.mkstr( '1392DLFJIOS' ), 'Invalid hex id String' ); + + // Test valid hex id string + //test.equals( 0, testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ), 'Valid hex id String' ); + + test.done(); +}; diff --git a/test/raw-commit.js b/test/raw-commit.js index cfe13d9bc..fbfe126ea 100644 --- a/test/raw-commit.js +++ b/test/raw-commit.js @@ -73,7 +73,6 @@ exports.lookup = function( test ) { }, 'No exception is thrown with proper arguments' ); testRepo.open( path.resolve( '../.git' ), function( err ) { - console.log( new git.Error().strError( err ) ); // Test invalid commit testOid.mkstr( '100644' ); testCommit.lookup( testRepo, testOid, function( err ) { diff --git a/test/raw-obj.js b/test/raw-obj.js new file mode 100644 index 000000000..5427334c6 --- /dev/null +++ b/test/raw-obj.js @@ -0,0 +1,38 @@ +var git = require( '../' ).raw, + rimraf = require( '../vendor/rimraf' ); + +// Helper functions +var helper = { + // Test if obj is a true function + testFunction: function( test, obj, label ) { + // The object reports itself as a function + test( typeof obj, 'function', label +' reports as a function.' ); + // This ensures the repo is actually a derivative of the Function [[Class]] + test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); + }, + // Test code and handle exception thrown + testException: function( test, fun, label ) { + try { + fun(); + test( false, label ); + } + catch (ex) { + test( true, label ); + } + } +}; + +var repo = new git.Repo(); + +// Obj +exports.constructor = function( test ){ + test.expect( 3 ); + + // Test for function + helper.testFunction( test.equals, git.Object, 'GitObject' ); + + // Ensure we get an instance of Obj + test.ok( new git.Object() instanceof git.Object, 'Invocation returns an instance of GitObject' ); + + test.done(); +}; diff --git a/test/raw-oid.js b/test/raw-oid.js index 0c52ffa27..af415754f 100644 --- a/test/raw-oid.js +++ b/test/raw-oid.js @@ -62,3 +62,47 @@ exports.mkstr = function( test ) { test.done(); }; + +// Oid::Fmt +exports.fmt = function( test ) { + var testOid = new git.Oid(); + + test.expect( 4 ); + + // Test for function + helper.testFunction( test.equals, testOid.fmt, 'Oid::Fmt' ); + + // Test invalid hex id string + testOid.mkstr( 'NNNNN' ); + test.equals( 38333, testOid.fmt().substring(0, 5).toUpperCase(), 'Invalid hex id String' ); + + // Test valid hex id string + testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ); + + // Slight hackery to get this to work... should investigate oid fmt + test.equals( '1810DFF58D8A660512D4832E740F692884338CCD', testOid.fmt().substring(0, 40).toUpperCase(), 'Valid hex id String' ); + + test.done(); +}; + +// Oid::Fmt +exports.toString = function( test ) { + var testOid = new git.Oid(); + + test.expect( 4 ); + + // Test for function + helper.testFunction( test.equals, testOid.toString, 'Oid::ToString' ); + + // Test invalid hex id string + testOid.mkstr( 'NNNNN' ); + test.equals( 38333, testOid.toString( 5 ), 'Invalid hex id String' ); + + // Test valid hex id string + testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ); + + // Slight hackery to get this to work... should investigate oid fmt + test.equals( '1810DFF58D8A660512D4832E740F692884338CCD', testOid.toString( 40 ).toUpperCase(), 'Valid hex id String' ); + + test.done(); +}; diff --git a/test/raw-ref.js b/test/raw-ref.js new file mode 100644 index 000000000..14a7f203c --- /dev/null +++ b/test/raw-ref.js @@ -0,0 +1,82 @@ +var git = require( '../' ).raw, + rimraf = require( '../vendor/rimraf' ); + +// Helper functions +var helper = { + // Test if obj is a true function + testFunction: function( test, obj, label ) { + // The object reports itself as a function + test( typeof obj, 'function', label +' reports as a function.' ); + // This ensures the repo is actually a derivative of the Function [[Class]] + test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); + }, + // Test code and handle exception thrown + testException: function( test, fun, label ) { + try { + fun(); + test( false, label ); + } + catch (ex) { + test( true, label ); + } + } +}; + +// Ref +exports.constructor = function( test ){ + test.expect( 3 ); + + // Test for function + helper.testFunction( test.equals, git.Ref, 'Ref' ); + + // Ensure we get an instance of Ref + test.ok( new git.Ref() instanceof git.Ref, 'Invocation returns an instance of Ref' ); + + test.done(); +}; + +// Ref::Lookup +exports.lookup = function( test ) { + var testRepo = new git.Repo(), + master = new git.Ref(); + + test.expect( 5 ); + + // Test for function + helper.testFunction( test.equals, master.lookup, 'Ref::Lookup' ); + + // Test repo argument existence + helper.testException( test.ok, function() { + master.lookup(); + }, 'Throw an exception if no repo' ); + + // Test name argument existence + helper.testException( test.ok, function() { + master.lookup( testRepo ); + }, 'Throw an exception if no name' ); + + // Test callback argument existence + helper.testException( test.ok, function() { + master.lookup( testRepo, 'refs/heads/master' ); + }, 'Throw an exception if no callback' ); + + // Cleanup, remove test repo directory - if it exists + rimraf( './test.git', function() { + // // Create bare repo and test for creation + // testRepo.init( './test.git', true, function( err, path, is_bare ) { + // test.equals( 0, err, 'Successfully created bare repository' ); + // // Verify repo exists + // testRepo.open( './test.git', function(err, path) { + // test.equals( 0, err, 'Valid repository created' ); + // test.equals( true, is_bare, 'Returns valid is_bare value' ); + + // testRepo.free(); + + // // Cleanup, remove test repo directory + // rimraf( './test.git', function() { + test.done(); + // }); + // }); + // }); + }); +}; diff --git a/test/raw-revwalk.js b/test/raw-revwalk.js index 15cf96345..702d7e4ba 100644 --- a/test/raw-revwalk.js +++ b/test/raw-revwalk.js @@ -1,4 +1,4 @@ -var git = require( '../' ).git2, +var git = require( '../' ).raw, rimraf = require( '../vendor/rimraf' ) || require( 'rimraf' ); var testRepo = new git.Repo(); @@ -24,75 +24,17 @@ var helper = { } }; -// Oid +// RevWalk exports.constructor = function( test ){ test.expect( 3 ); // Test for function - helper.testFunction( test.equals, git.Commit, 'Commit' ); + helper.testFunction( test.equals, git.RevWalk, 'RevWalk' ); // Ensure we get an instance of Oid testRepo.open( './dummyrepo/.git', function( err, path ) { - test.ok( new git.Commit( testRepo ) instanceof git.Commit, 'Invocation returns an instance of Commit' ); + test.ok( new git.RevWalk( testRepo ) instanceof git.RevWalk, 'Invocation returns an instance of RevWalk' ); test.done(); }); }; - -// Oid::Mkstr -exports.lookup = function( test ) { - var testOid = new git.Oid(), - testCommit = new git.Commit(testRepo); - - testOid.mkstr( 'cb09e99e91d41705197e0fb60823fdc7df776691' ); - - test.expect( 8 ); - - // Test for function - helper.testFunction( test.equals, testCommit.lookup, 'Commit::Lookup' ); - - // Test repo argument existence - helper.testException( test.ok, function() { - testCommit.lookup(); - }, 'Throw an exception if no repo' ); - - // Test oid argument existence - helper.testException( test.ok, function() { - testCommit.lookup( testRepo ); - }, 'Throw an exception if no oid' ); - - // Test callback argument existence - helper.testException( test.ok, function() { - testCommit.lookup( testRepo, testOid ); - }, 'Throw an exception if no callback' ); - - // Test that both arguments result correctly - helper.testException( test.ifError, function() { - testCommit.lookup( testRepo, testOid, function() {} ); - }, 'No exception is thrown with proper arguments' ); - - testRepo.open( './dummyrepo/.git', function( err, path ) { - // Test invalid commit - testOid.mkstr( '100644' ); - testCommit.lookup( testRepo, testOid, function( err, details ) { - test.notEqual( 0, err, 'Not a valid commit' ); - - // Test valid commit - testOid.mkstr( 'cb09e99e91d41705197e0fb60823fdc7df776691' ); - testCommit.lookup( testRepo, testOid, function( err, details ) { - test.equals( 0, err, 'Valid commit'); - - //test.equals( 'object', typeof details, 'Details is an object' ); - - //test.equals( 'string', typeof details.message, 'Details message is a String' ); - //if(details.message) { - // test.equals( 'initial commit', details.message.trim(), 'Details has correct message' ); - //} - - testRepo.free(); - - test.done(); - }); - }); - }); -}; diff --git a/util/hint-check.js b/util/hint-check.js index cbcd4e6fb..1c531d212 100644 --- a/util/hint-check.js +++ b/util/hint-check.js @@ -19,7 +19,8 @@ files = [ nodejshint( files, function( failures ) { if( !files.length ) { process.exit( 0 ); - } else { + } + else { process.exit( 1 ); } }); From 91407b6454a0e501a1c9573deae51d1ef89f000a Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 13 Mar 2011 16:06:26 -0400 Subject: [PATCH 29/35] updates to readme to reflect releases --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d817de03..adef3556e 100644 --- a/README.md +++ b/README.md @@ -195,17 +195,16 @@ __ Can keep track of current method coverage at: [http://bit.ly/tb_methods](http * An API that can be easily extended with convenience methods in JS * An API that offers a familiar clean syntax that will make adoption and use much more likely * Open for public testing - * Be able to open and read a repo and fetch all its commits and lookup specific commits and their associated metadata + reading blob rawcontent. + * GitHub landing page + * Repo, Oid, Commit, Error, Ref, and RevWalk support + * Built on libgit2 version 0.3.0 ### v0.0.2: ### * More methods implemented * More unit tests - * GitHub landing page (already done) * More API development - -### v0.0.3: ### - * Custom odb backend - * API coverage in GitHub Wiki + * Tree and Blob support + * Updated libgit2 to version 0.8.0 Getting involved ---------------- From e5b1527be4937077dc5ef1745fa05cfa4a89433d Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 13 Mar 2011 16:22:52 -0400 Subject: [PATCH 30/35] added windows build failure message --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index adef3556e..b23e9f128 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ This will install and configure everything you need to use `nodegit`. ### Windows via Cygwin ### -#### `nodegit` has been compiled and tested to work with the setup required to build and run `Node.js` itself. #### +#### `nodegit` has a build issue under Windows that current makes it impossible to use. #### Instructions on compiling `Node.js` on a Windows platform can be found here: [https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-(Windows)](https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-(Windows\)) From 45c2ebe80a5faffb3d5f6f4292b78451c518e583 Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 13 Mar 2011 20:15:55 -0400 Subject: [PATCH 31/35] Updates to oid unit tests --- test/raw-oid.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/raw-oid.js b/test/raw-oid.js index af415754f..cbccf45fa 100644 --- a/test/raw-oid.js +++ b/test/raw-oid.js @@ -100,8 +100,6 @@ exports.toString = function( test ) { // Test valid hex id string testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ); - - // Slight hackery to get this to work... should investigate oid fmt test.equals( '1810DFF58D8A660512D4832E740F692884338CCD', testOid.toString( 40 ).toUpperCase(), 'Valid hex id String' ); test.done(); From a02e8e7e30b41edb07a6a738918a1b100303c2cf Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Mon, 14 Mar 2011 13:25:19 -0400 Subject: [PATCH 32/35] Removed tmp libgit2 files --- vendor/libgit2/.lock-wafbuild | 8 -------- vendor/libgit2/.lock-wscript | 9 --------- 2 files changed, 17 deletions(-) delete mode 100644 vendor/libgit2/.lock-wafbuild delete mode 100644 vendor/libgit2/.lock-wscript diff --git a/vendor/libgit2/.lock-wafbuild b/vendor/libgit2/.lock-wafbuild deleted file mode 100644 index 7c3c622fb..000000000 --- a/vendor/libgit2/.lock-wafbuild +++ /dev/null @@ -1,8 +0,0 @@ -argv = ['waf', 'configure'] -environ = {'_': '/usr/bin/python', 'SSH_AUTH_SOCK': '/tmp/launch-7qUexP/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273', 'SHELL': '/bin/bash', 'LOGNAME': 'timbranyen', 'USER': 'timbranyen', 'HOME': '/Users/timbranyen', 'PATH': '/usr/local/mysql-5.1.48-osx10.6-x86_64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin', 'DISPLAY': '/tmp/launch-7UXtiF/org.x:0', 'MAKEFLAGS': '', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-m9ROAk/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '3', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'MAKELEVEL': '1', 'PWD': '/Users/timbranyen/Projects/nodegit/vendor/libgit2', 'TMPDIR': '/var/folders/0j/0jwileIVGx44xbVHEc8nvk+++TI/-Tmp-/', 'MFLAGS': '', 'COMMAND_MODE': 'unix2003'} -files = ['/Users/timbranyen/Projects/nodegit/vendor/libgit2/wscript'] -hash = -8574636053425009178 -options = {'files': '', 'use_sqlite': True, 'sha1': 'builtin', 'jobs': 4, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'top': '', 'destdir': '', 'keep': False, 'zones': '', 'debug': False, 'prefix': '/usr/local/', 'download': False, 'msvc': None, 'force': False, 'arch': 'x86', 'targets': '', 'check_c_compiler': 'gcc', 'out': ''} -out_dir = '/Users/timbranyen/Projects/nodegit/vendor/libgit2/build' -run_dir = '/Users/timbranyen/Projects/nodegit/vendor/libgit2' -top_dir = '/Users/timbranyen/Projects/nodegit/vendor/libgit2' diff --git a/vendor/libgit2/.lock-wscript b/vendor/libgit2/.lock-wscript deleted file mode 100644 index 8fd332a3d..000000000 --- a/vendor/libgit2/.lock-wscript +++ /dev/null @@ -1,9 +0,0 @@ -argv = ['/usr/local/bin/node-waf', 'configure'] -blddir = '/Users/timbranyen/Projects/nodegit/build' -commands = {'dist': 0, 'configure': True, 'distcheck': 0, 'install': 0, 'build': 0, 'clean': 0, 'distclean': 0, 'check': 0, 'uninstall': 0} -cwd = '/Users/timbranyen/Projects/nodegit' -environ = {'_': '/usr/local/bin/node-waf', 'SSH_AUTH_SOCK': '/tmp/launch-7qUexP/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273', 'SHELL': '/bin/bash', 'LOGNAME': 'timbranyen', 'USER': 'timbranyen', 'HOME': '/Users/timbranyen', 'PATH': '/usr/local/mysql-5.1.48-osx10.6-x86_64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin', 'DISPLAY': '/tmp/launch-7UXtiF/org.x:0', 'MAKEFLAGS': '', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-m9ROAk/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '2', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'MAKELEVEL': '1', 'PWD': '/Users/timbranyen/Projects/nodegit', 'TMPDIR': '/var/folders/0j/0jwileIVGx44xbVHEc8nvk+++TI/-Tmp-/', 'MFLAGS': '', 'COMMAND_MODE': 'unix2003'} -files = [] -hash = 0 -options = {'compile_targets': None, 'force': False, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'destdir': '', 'keep': False, 'zones': '', 'blddir': '', 'prefix': '/usr/local/', 'jobs': 4, 'srcdir': '', 'check_cxx_compiler': 'g++'} -srcdir = '/Users/timbranyen/Projects/nodegit' From 4a98179add744611ba73af7070fade384c21dc4d Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Mon, 14 Mar 2011 19:20:30 -0400 Subject: [PATCH 33/35] Updated tests --- test/convenience-repo.js | 2 +- test/raw-oid.js | 4 ++-- test/raw-repo.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/convenience-repo.js b/test/convenience-repo.js index 574708b93..2a96583a3 100644 --- a/test/convenience-repo.js +++ b/test/convenience-repo.js @@ -37,7 +37,7 @@ exports.constructor = function( test ){ // Test invalid repository git.repo( '/etc/hosts', function( err, path ) { - test.equals( 'Object does not exist in the scope searched.', err, 'Invalid repository error code' ); + test.equals( 'The specified repository is invalid', err, 'Invalid repository error code' ); // Test valid repository git.repo( '../.git', function( err, path ) { diff --git a/test/raw-oid.js b/test/raw-oid.js index cbccf45fa..f5b6adfa2 100644 --- a/test/raw-oid.js +++ b/test/raw-oid.js @@ -74,7 +74,7 @@ exports.fmt = function( test ) { // Test invalid hex id string testOid.mkstr( 'NNNNN' ); - test.equals( 38333, testOid.fmt().substring(0, 5).toUpperCase(), 'Invalid hex id String' ); + test.equals( '00000', testOid.fmt().substring(0, 5).toUpperCase(), 'Invalid hex id String' ); // Test valid hex id string testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ); @@ -96,7 +96,7 @@ exports.toString = function( test ) { // Test invalid hex id string testOid.mkstr( 'NNNNN' ); - test.equals( 38333, testOid.toString( 5 ), 'Invalid hex id String' ); + test.equals( '00000', testOid.toString( 5 ), 'Invalid hex id String' ); // Test valid hex id string testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ); diff --git a/test/raw-repo.js b/test/raw-repo.js index 18bc44267..5d50d16a1 100644 --- a/test/raw-repo.js +++ b/test/raw-repo.js @@ -58,7 +58,7 @@ exports.open = function( test ) { // Test invalid repository testRepo.open( '/etc/hosts', function( err ) { - test.equals( -3, err, 'Invalid repository error code' ); + test.equals( -8, err, 'Invalid repository error code' ); // Test valid repository testRepo.open( path.resolve( '../.git' ), function( err ) { From b1f941c62f508db5f392a6bb0ea1d591753a045b Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Mon, 14 Mar 2011 19:24:21 -0400 Subject: [PATCH 34/35] bumped version numbers up to 0.2.0 --- README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b23e9f128..d6489438d 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,6 @@ API Example Usage console.log( '\n' ); }); }); - - // Memory cleanup - repo.free(); }); #### Raw API #### @@ -186,6 +183,13 @@ Release information __ Can keep track of current method coverage at: [http://bit.ly/tb_methods](http://bit.ly/tb_methods) __ +### v0.0.2: ### + * More methods implemented + * More unit tests + * More API development + * Tree and Blob support + * Updated libgit2 to version 0.8.0 + ### v0.0.1: ### * Some useful methods implemented * Some unit tests @@ -199,13 +203,6 @@ __ Can keep track of current method coverage at: [http://bit.ly/tb_methods](http * Repo, Oid, Commit, Error, Ref, and RevWalk support * Built on libgit2 version 0.3.0 -### v0.0.2: ### - * More methods implemented - * More unit tests - * More API development - * Tree and Blob support - * Updated libgit2 to version 0.8.0 - Getting involved ---------------- From cb76e3c030ab29db332aff3b297dc39451a84762 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Mon, 14 Mar 2011 19:25:16 -0400 Subject: [PATCH 35/35] bumped package.json up --- package.json | 2 +- wscript | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d3a61f5d5..32e7bcf2c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodegit", "description": "NodeJS libgit2 asynchronous native bindings", - "version": "0.0.1", + "version": "0.0.2", "homepage": "https://github.com/tbranyen/nodegit", "author": "Tim Branyen (http://twitter.com/tbranyen)", "main": "./lib/index.js", diff --git a/wscript b/wscript index 172fa6ed3..a6079f57a 100755 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ import os from os import system from os.path import exists, abspath -VERSION = '0.0.1' +VERSION = '0.0.2' APPNAME = 'nodegit' srcdir = '.' blddir = 'build'