File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 1010
1111#include < v8.h>
1212#include < node.h>
13+ #include < string>
1314
14- #include " ../vendor/libgit2/include/ git2.h"
15+ #include " git2.h"
1516
1617#include " repo.h"
1718#include " tree.h"
@@ -32,10 +33,14 @@ class GitTreeEntry : ObjectWrap {
3233 static void Initialize (Handle<v8::Object> target);
3334 git_tree_entry* GetValue ();
3435 void SetValue (git_tree_entry* tree);
36+ void SetRoot (std::string root);
37+ std::string GetRoot ();
3538
3639 protected:
3740 static Handle<Value> New (const Arguments& args);
3841
42+ static Handle<Value> Root (const Arguments& args);
43+
3944 static Handle<Value> Name (const Arguments& args);
4045 static void NameWork (uv_work_t * req);
4146 static void NameAfterWork (uv_work_t * req);
@@ -54,12 +59,13 @@ class GitTreeEntry : ObjectWrap {
5459
5560 private:
5661 git_tree_entry* entry;
62+ std::string root;
5763
5864 struct NameBaton {
5965 uv_work_t request;
6066
6167 git_tree_entry* rawEntry;
62- std::string name;
68+ const char * name;
6369
6470 Persistent<Function> callback;
6571 };
Original file line number Diff line number Diff line change @@ -87,13 +87,45 @@ TreeEntry.prototype.isDirectory = function(callback) {
8787 * @param {Function } callback
8888 */
8989TreeEntry . prototype . name = function ( callback ) {
90- this . rawEntry . name ( function ( error , name ) {
90+ this . rawEntry . name ( function treeEntryName ( error , name ) {
9191 if ( success ( error , callback ) ) {
9292 callback ( null , name ) ;
9393 }
9494 } ) ;
9595} ;
9696
97+ /**
98+ * Retrieve the entry's root path.
99+ *
100+ * @param {Function } callback
101+ */
102+ TreeEntry . prototype . root = function ( callback ) {
103+ this . rawEntry . root ( function treeEntryRoot ( error , root ) {
104+ if ( success ( error , callback ) ) {
105+ callback ( null , root ) ;
106+ }
107+ } ) ;
108+ } ;
109+
110+ /**
111+ * Retrieve the path relative to the repository root for this TreeEntry.
112+ *
113+ * @param {Function } callback
114+ */
115+ TreeEntry . prototype . path = function ( callback ) {
116+ var self = this ;
117+ self . root ( function treeEntryRoot ( error , root ) {
118+ if ( ! success ( error , callback ) ) {
119+ return ;
120+ }
121+ self . rawEntry . name ( function treeEntryName ( error , name ) {
122+ if ( success ( error , callback ) ) {
123+ callback ( null , root + name ) ;
124+ }
125+ } ) ;
126+ } ) ;
127+ } ;
128+
97129/**
98130 * Retrieve the TreeEntry's content.
99131 *
You can’t perform that action at this time.
0 commit comments