11var Promise = require ( "promise" ) ;
2- var git = require ( ' ../' ) ;
2+ var git = require ( " ../" ) ;
33var Commit = git . Commit ;
4- var Oid = git . Oid ;
5- var Revwalk = git . Revwalk ;
6- var events = require ( 'events' ) ;
7- var Tree = require ( "./tree" ) ;
8-
9- // Backwards compatibility.
10- Object . defineProperties ( Commit . prototype , {
11- "oid" : {
12- value : Commit . prototype . id ,
13- enumerable : false
14- } ,
15-
16- "offset" : {
17- value : Commit . prototype . timeOffset ,
18- enumerable : false
19- } ,
20-
21- "parentCount" : {
22- value : Commit . prototype . parentcount ,
23- enumerable : false
24- }
25- } ) ;
4+ var events = require ( "events" ) ;
265
276/**
287 * Retrieve the SHA.
298 * @return {String }
309 */
3110Commit . prototype . sha = function ( ) {
32- return this . oid ( ) . toString ( ) ;
11+ return this . id ( ) . toString ( ) ;
3312} ;
3413
3514/**
@@ -53,7 +32,7 @@ Commit.prototype.date = function() {
5332 * @return {Tree }
5433 */
5534Commit . prototype . getTree = function ( callback ) {
56- this . repo . getTree ( this . treeId ( ) , callback ) ;
35+ return this . repo . getTree ( this . treeId ( ) , callback ) ;
5736} ;
5837
5938/**
@@ -65,18 +44,22 @@ Commit.prototype.getTree = function(callback) {
6544 * @return {TreeEntry }
6645 */
6746Commit . prototype . getEntry = function ( path , callback ) {
68- this . getTree ( function ( error , tree ) {
69- if ( error ) return callback ( error ) ;
47+ return this . getTree ( ) . then ( function ( tree ) {
48+ return tree . getEntry ( path ) . then ( function ( entry ) {
49+ if ( callback ) {
50+ callback ( entry ) ;
51+ }
7052
71- tree . getEntry ( path , callback ) ;
72- } ) ;
53+ return entry ;
54+ } ) ;
55+ } , callback ) ;
7356} ;
7457
7558/**
7659 * Walk the history from this commit backwards.
77- * An EventEmitter is returned that will emit a ' commit' event for each
78- * commit in the history, and one ' end' event when the walk is completed.
79- * Don' t forget to call `start()` on the returned event.
60+ * An EventEmitter is returned that will emit a " commit" event for each
61+ * commit in the history, and one " end" event when the walk is completed.
62+ * Don" t forget to call `start()` on the returned event.
8063 *
8164 * @fires Commit#commit
8265 * @fires Commit#end
@@ -85,7 +68,7 @@ Commit.prototype.getEntry = function(path, callback) {
8568 */
8669Commit . prototype . history = function ( ) {
8770 var event = new events . EventEmitter ( ) ;
88- var oid = this . oid ( ) ;
71+ var oid = this . id ( ) ;
8972 var revwalk = this . repo . createRevWalk ( ) ;
9073
9174 revwalk . sorting . apply ( revwalk , arguments ) ;
@@ -94,14 +77,16 @@ Commit.prototype.history = function() {
9477
9578 event . start = function ( ) {
9679 revwalk . walk ( oid , function commitRevWalk ( error , commit ) {
97- if ( error ) return event . emit ( 'error' , error ) ;
80+ if ( error ) {
81+ return event . emit ( "error" , error ) ;
82+ }
9883
9984 if ( ! commit ) {
100- event . emit ( ' end' , commits ) ;
85+ event . emit ( " end" , commits ) ;
10186 return ;
10287 }
10388
104- event . emit ( ' commit' , commit ) ;
89+ event . emit ( " commit" , commit ) ;
10590 commits . push ( commit ) ;
10691 } ) ;
10792 } ;
@@ -110,14 +95,13 @@ Commit.prototype.history = function() {
11095} ;
11196
11297/**
113- * Retrieve the commit' s parents -- as commit objects.
98+ * Retrieve the commit" s parents -- as commit objects.
11499 *
115100 * @param {number } limit - Optional amount of parents to return.
116101 * @param {Function } callback
117102 * @return {[Commit] } array of commits
118103 */
119104Commit . prototype . getParents = function ( limit , callback ) {
120- var commit = this ;
121105 var parents = [ ] ;
122106 var i = 0 ;
123107
@@ -127,7 +111,7 @@ Commit.prototype.getParents = function(limit, callback) {
127111 }
128112
129113 // If no limit was set, default to the maximum parents.
130- limit = typeof limit === "number" ? limit : this . parentCount ( ) ;
114+ limit = typeof limit === "number" ? limit : this . parentcount ( ) ;
131115
132116 function processParents ( commit , callback ) {
133117 var oid = commit . parentId ( i ) ;
@@ -163,14 +147,14 @@ Commit.prototype.getParents = function(limit, callback) {
163147} ;
164148
165149/**
166- * Retrieve the commit' s parent shas.
150+ * Retrieve the commit" s parent shas.
167151 *
168152 * @param {Function } callback
169153 * @return {[Oid] } array of oids
170154 */
171155Commit . prototype . parents = function ( ) {
172156 var result = [ ] ;
173- for ( var i = 0 ; i < this . parentCount ( ) ; i ++ ) {
157+ for ( var i = 0 ; i < this . parentcount ( ) ; i ++ ) {
174158 result . push ( this . parentId ( i ) ) ;
175159 }
176160 return result ;
@@ -184,30 +168,23 @@ Commit.prototype.parents = function() {
184168 * @return {[Diff] } an array of diffs
185169 */
186170Commit . prototype . getDiff = function ( callback ) {
187- var self = this ;
188- self . getParents ( function commitParents ( error , parents ) {
189- if ( error ) return callback ( error ) ;
190-
191- var parentDiffs = [ ] ;
192- parents . forEach ( function commitEachParent ( parent ) {
193- parent . getTree ( function ( error , parentTree ) {
194- if ( error ) return callback ( error ) ;
195-
196- self . getTree ( function ( error , thisTree ) {
197- if ( error ) return callback ( error ) ;
198-
199- parentTree . diff ( thisTree , function walkDiff ( error , diff ) {
200- if ( error ) return callback ( error ) ;
201-
202- parentDiffs . push ( diff ) ;
203- if ( parentDiffs . length === parents . length ) {
204- callback ( null , parentDiffs ) ;
205- }
206- } ) ;
171+ var commit = this ;
172+
173+ return commit . getParents ( ) . then ( function ( parents ) {
174+ return parents . map ( function ( parent ) {
175+ return parent . getTree ( function ( parentTree ) {
176+ return commit . getTree ( function ( thisTree ) {
177+ return parentTree . diff ( thisTree ) ;
207178 } ) ;
208179 } ) ;
209180 } ) ;
210- } ) ;
181+ } ) . then ( function ( parentDiffs ) {
182+ if ( callback ) {
183+ callback ( null , parentDiffs ) ;
184+ }
185+
186+ return parentDiffs ;
187+ } , callback ) ;
211188} ;
212189
213190/**
0 commit comments