@@ -3,12 +3,12 @@ var spawn = require('child_process').spawn;
3
3
var byline = require ( 'byline' ) ;
4
4
var async = require ( 'async' ) ;
5
5
var util = require ( 'util' ) ;
6
- var path = require ( 'path' ) ;
6
+ var pathutil = require ( 'path' ) ;
7
7
require ( 'buffertools' ) . extend ( )
8
8
9
9
var Git = function ( p )
10
10
{
11
- this . path = path . resolve ( p ) ;
11
+ this . path = pathutil . resolve ( p ) ;
12
12
} ;
13
13
14
14
Git . prototype . git = function ( /* command, args, options, callback */ )
@@ -339,6 +339,30 @@ Git.prototype.parseTree = function(sha, callback) {
339
339
} ) ;
340
340
} ;
341
341
342
+ Git . prototype . findBlob = function ( sha , path , callback ) {
343
+ var self = this ;
344
+ if ( typeof path === "string" )
345
+ path = pathutil . resolve ( '/' , path ) . split ( '/' ) ;
346
+
347
+ while ( path [ 0 ] == "" || path [ 0 ] == "." )
348
+ path . shift ( ) ;
349
+
350
+
351
+ var name = path . shift ( ) ;
352
+ this . parseTree ( sha , function ( err , files ) {
353
+ if ( err ) return callback ( err , null ) ;
354
+
355
+ if ( ! files [ name ] )
356
+ return callback ( "Path not found" , null ) ;
357
+
358
+ if ( files [ name ] . type == "blob" )
359
+ return callback ( null , files [ name ] ) ;
360
+ else if ( files [ name ] . type == "tree" )
361
+ return self . findBlob ( files [ name ] . object , path , callback ) ;
362
+ else
363
+ return callback ( "Unsupported object type" , null ) ;
364
+ } ) ;
365
+ } ;
342
366
343
367
module . exports = Git ;
344
368
0 commit comments