1- var git = require ( '../' ) ,
2- events = require ( 'events' ) ;
3-
4- /**
5- * Convenience commit constructor.
6- *
7- * @constructor
8- * @param {git.raw.Repo } rawRepo Raw repository object.
9- * @param {git.raw.Commit } [rawCommit = new git.raw.Commit(rawRepo)] Raw commit object.
10- */
11- var Commit = function ( repo , rawCommit ) {
12- if ( ! ( repo instanceof git . repo ) ) {
13- throw new Error ( 'First parameter for Commit must be a raw repo' ) ;
14- }
15- this . repo = repo ;
16-
17- if ( ! ( rawCommit instanceof git . raw . Commit ) ) {
18- throw new Error ( 'Second parameter for Commit must be a raw commit' ) ;
19- }
20- this . rawCommit = rawCommit ;
21- } ;
22-
23- /**
24- * Retrieve the commit's OID.
25- */
26- Commit . prototype . oid = function ( ) {
27- return new git . oid ( this . rawCommit . oid ( ) ) ;
28- } ;
1+ var git = require ( '../' ) ,
2+ Commit = git . Commit ,
3+ events = require ( 'events' ) ;
294
305/**
316 * Retrieve the SHA.
@@ -34,66 +9,25 @@ Commit.prototype.sha = function() {
349 return this . oid ( ) . sha ( ) ;
3510} ;
3611
37- /**
38- * Retrieve the message
39- */
40- Commit . prototype . message = function ( ) {
41- return this . rawCommit . message ( ) ;
42- } ;
43-
4412/**
4513 * Retrieve the commit time as a unix timestamp.
4614 */
47- Commit . prototype . time = function ( ) {
48- return this . rawCommit . time ( ) * 1000 ;
15+ Commit . prototype . timeMs = function ( ) {
16+ return this . time ( ) * 1000 ;
4917} ;
5018
5119/**
5220 * Retrieve the commit time as a Date object.
5321 */
5422Commit . prototype . date = function ( ) {
55- return new Date ( this . time ( ) ) ;
56- } ;
57-
58- /**
59- * Retrieve the commit's positive or negative timezone offset, in minutes from UTC.
60- */
61- Commit . prototype . offset = function ( callback ) {
62- return this . rawCommit . offset ( ) ;
63- } ;
64-
65- /**
66- * Retrieve the commit's author signature.
67- */
68- Commit . prototype . author = function ( ) {
69- return this . rawCommit . author ( ) ;
23+ return new Date ( this . timeMs ( ) ) ;
7024} ;
7125
7226/**
73- * Retrieve the commit's committer.
74- */
75- Commit . prototype . committer = function ( ) {
76- return this . rawCommit . committer ( ) ;
77- } ;
78-
79- /**
80- * Retrieve the tree for this commit.
81- *
82- * @param {Commit~getTreeCallback } callback
27+ * Get the tree associated with this commit.
8328 */
8429Commit . prototype . getTree = function ( callback ) {
85- /**
86- * @callback Commit~getTreeCallback Callback executed on tree retrieval
87- * @param {GitError|null } error An Error or null if successful.
88- * @param {Tree|null } Tree
89- */
90-
91- var self = this ;
92- this . rawCommit . tree ( function ( error , rawTree ) {
93- if ( error ) return callback ( error ) ;
94-
95- callback ( null , new git . tree ( self . repo , rawTree ) ) ;
96- } ) ;
30+ this . repo . getTree ( this . treeId ( ) , callback ) ;
9731} ;
9832
9933/**
@@ -103,18 +37,16 @@ Commit.prototype.getTree = function(callback) {
10337 * @param {String } path
10438 * @param {Commit~fileCallback } callback
10539 */
106- Commit . prototype . file = function ( path , callback ) {
40+ Commit . prototype . getFile = function ( path , callback ) {
10741 /**
10842 * @callback Commit~fileCallback Callback executed on file retrieval.
10943 * @param {GitError|null } error An Error or null if successful.
11044 * @param {Entry|null } file Retrieved file entry.
11145 */
11246 this . getTree ( function ( error , tree ) {
11347 if ( error ) return callback ( error ) ;
114- tree . entry ( path , function ( error , entry ) {
115- if ( error ) return callback ( error ) ;
116- callback ( null , entry ) ;
117- } ) ;
48+
49+ tree . getEntryByPath ( path , callback ) ;
11850 } ) ;
11951} ;
12052
@@ -132,7 +64,7 @@ Commit.prototype.history = function() {
13264 var event = new events . EventEmitter ( ) ;
13365
13466 var oid = this . oid ( ) ;
135- var revwalk = new git . revwalk ( this . repo , this . repo . rawRepo . createRevWalk ( ) ) ;
67+ var revwalk = this . repo . createRevWalk ( ) ;
13668 var commits = [ ] ;
13769 event . start = function ( ) {
13870 revwalk . walk ( oid , function commitRevWalk ( error , commit ) {
@@ -170,24 +102,23 @@ Commit.prototype.history = function() {
170102 *
171103 * @param {Commit~parentsCallback } callback
172104 */
173- Commit . prototype . parents = function ( callback ) {
105+ Commit . prototype . getParents = function ( callback ) {
174106 /**
175107 * @callback Commit~parentsCallback Callback executed on parents retrieval.
176108 * @param {GitError|null } error An Error or null if successful.
177109 * @param {Commit[]|null } parents Commit's parent(s).
178110 */
179111 var self = this ;
180-
181- function processParents ( rawCommit , n , acc , callback ) {
112+ function processParents ( commit , n , acc , callback ) {
182113 if ( n < 0 ) return callback ( null , acc ) ;
183114
184- rawCommit . parent ( n , function nextParent ( error , rawParentCommit ) {
115+ self . repo . getCommit ( self . parentId ( n ) , function nextParent ( error , parent ) {
185116 if ( error ) return callback ( error ) ;
186- processParents ( rawParentCommit , n - 1 , acc . concat ( [ new Commit ( self . repo , rawParentCommit ) ] ) , callback ) ;
117+ processParents ( parent , n - 1 , acc . concat ( [ parent ] ) , callback ) ;
187118 } ) ;
188119 }
189120
190- processParents ( this . rawCommit , this . rawCommit . parentCount ( ) - 1 , [ ] , callback ) ;
121+ processParents ( this , this . parentCount ( ) - 1 , [ ] , callback ) ;
191122} ;
192123
193124/**
@@ -196,14 +127,14 @@ Commit.prototype.parents = function(callback) {
196127 *
197128 * @param {Commit~parentsDiffTreesCallback } callback
198129 */
199- Commit . prototype . parentsDiffTrees = function ( callback ) {
130+ Commit . prototype . diff = function ( callback ) {
200131 /**
201132 * @callback Commit~parentsDiffTreesCallback Callback executed on diff trees retrieval.
202133 * @param {GitError|null } error An Error or null if successful.
203134 * @param {DiffList[]|null } diffLists Array of DiffTrees showing changes between this commit and its parent(s)
204135 */
205136 var self = this ;
206- self . parents ( function commitParents ( error , parents ) {
137+ self . getParents ( function commitParents ( error , parents ) {
207138 if ( error ) return callback ( error ) ;
208139
209140 var parentDiffLists = [ ] ;
@@ -227,5 +158,3 @@ Commit.prototype.parentsDiffTrees = function(callback) {
227158 } ) ;
228159 } ) ;
229160} ;
230-
231- exports . commit = Commit ;
0 commit comments