@@ -63,13 +63,14 @@ export const process_commit_formatting_options = (options) => {
63
63
64
64
/**
65
65
* Format the given oid hash, followed by any refs that point to it
66
+ * @param git_context {{ fs, dir, gitdir, cache }} as taken by most isomorphic-git methods.
66
67
* @param oid
67
68
* @param short_hashes Whwther to shorten the hash
68
69
* @returns {String }
69
70
*/
70
- export const format_oid = ( oid , { short_hashes = false } = { } ) => {
71
+ export const format_oid = async ( git_context , oid , { short_hashes = false } = { } ) => {
71
72
// TODO: List refs at this commit, after the hash
72
- return short_hashes ? shorten_hash ( oid ) : oid ;
73
+ return short_hashes ? shorten_hash ( git_context , oid ) : oid ;
73
74
}
74
75
75
76
/**
@@ -110,30 +111,31 @@ export const format_timestamp_and_offset = (owner) => {
110
111
111
112
/**
112
113
* Produce a string representation of a commit.
114
+ * @param git_context {{ fs, dir, gitdir, cache }} as taken by most isomorphic-git methods.
113
115
* @param commit A CommitObject
114
116
* @param oid Commit hash
115
117
* @param options Options returned by parsing the command arguments in `commit_formatting_options`
116
118
* @returns {string }
117
119
*/
118
- export const format_commit = ( commit , oid , options = { } ) => {
120
+ export const format_commit = async ( git_context , commit , oid , options = { } ) => {
119
121
const title_line = ( ) => commit . message . split ( '\n' ) [ 0 ] ;
120
122
const indent = ( text ) => text . split ( '\n' ) . map ( it => ` ${ it } ` ) . join ( '\n' ) ;
121
123
122
124
switch ( options . format || 'medium' ) {
123
125
// TODO: Other formats
124
126
case 'oneline' :
125
- return `${ chalk . yellow ( format_oid ( oid , options ) ) } ${ title_line ( ) } ` ;
127
+ return `${ chalk . yellow ( await format_oid ( git_context , oid , options ) ) } ${ title_line ( ) } ` ;
126
128
case 'short' : {
127
129
let s = '' ;
128
- s += chalk . yellow ( `commit ${ format_oid ( oid , options ) } \n` ) ;
130
+ s += chalk . yellow ( `commit ${ await format_oid ( git_context , oid , options ) } \n` ) ;
129
131
s += `Author: ${ format_person ( commit . author ) } \n` ;
130
132
s += '\n' ;
131
133
s += indent ( title_line ( ) ) ;
132
134
return s ;
133
135
}
134
136
case 'medium' : {
135
137
let s = '' ;
136
- s += chalk . yellow ( `commit ${ format_oid ( oid , options ) } \n` ) ;
138
+ s += chalk . yellow ( `commit ${ await format_oid ( git_context , oid , options ) } \n` ) ;
137
139
s += `Author: ${ format_person ( commit . author ) } \n` ;
138
140
s += `Date: ${ format_date ( commit . author ) } \n` ;
139
141
s += '\n' ;
@@ -142,7 +144,7 @@ export const format_commit = (commit, oid, options = {}) => {
142
144
}
143
145
case 'full' : {
144
146
let s = '' ;
145
- s += chalk . yellow ( `commit ${ format_oid ( oid , options ) } \n` ) ;
147
+ s += chalk . yellow ( `commit ${ await format_oid ( git_context , oid , options ) } \n` ) ;
146
148
s += `Author: ${ format_person ( commit . author ) } \n` ;
147
149
s += `Commit: ${ format_person ( commit . committer ) } \n` ;
148
150
s += '\n' ;
@@ -151,7 +153,7 @@ export const format_commit = (commit, oid, options = {}) => {
151
153
}
152
154
case 'fuller' : {
153
155
let s = '' ;
154
- s += chalk . yellow ( `commit ${ format_oid ( oid , options ) } \n` ) ;
156
+ s += chalk . yellow ( `commit ${ await format_oid ( git_context , oid , options ) } \n` ) ;
155
157
s += `Author: ${ format_person ( commit . author ) } \n` ;
156
158
s += `AuthorDate: ${ format_date ( commit . author ) } \n` ;
157
159
s += `Commit: ${ format_person ( commit . committer ) } \n` ;
@@ -330,6 +332,7 @@ export const process_diff_formatting_options = (options, { show_patch_by_default
330
332
331
333
/**
332
334
* Produce a string representation of the given diffs.
335
+ * @param git_context {{ fs, dir, gitdir, cache }} as taken by most isomorphic-git methods.
333
336
* @param diffs A single object, or array of them, in the format:
334
337
* {
335
338
* a: { mode, oid },
@@ -339,15 +342,18 @@ export const process_diff_formatting_options = (options, { show_patch_by_default
339
342
* @param options Object returned by process_diff_formatting_options()
340
343
* @returns {string }
341
344
*/
342
- export const format_diffs = ( diffs , options ) => {
345
+ export const format_diffs = async ( git_context , diffs , options ) => {
343
346
if ( ! ( diffs instanceof Array ) )
344
347
diffs = [ diffs ] ;
345
348
346
349
let s = '' ;
347
350
if ( options . raw ) {
348
351
// https://git-scm.com/docs/diff-format#_raw_output_format
349
352
for ( const { a, b, diff } of diffs ) {
350
- s += `:${ a . mode } ${ b . mode } ${ shorten_hash ( a . oid ) } ${ shorten_hash ( b . oid ) } ` ;
353
+ const short_a_oid = await shorten_hash ( git_context , a . oid ) ;
354
+ const short_b_oid = await shorten_hash ( git_context , b . oid ) ;
355
+
356
+ s += `:${ a . mode } ${ b . mode } ${ short_a_oid } ${ short_b_oid } ` ;
351
357
// Status. For now, we just support A/D/M
352
358
if ( a . mode === '000000' ) {
353
359
s += 'A' ; // Added
@@ -409,19 +415,22 @@ export const format_diffs = (diffs, options) => {
409
415
const a_path = diff . oldFileName . startsWith ( '/' ) ? diff . oldFileName : `${ options . source_prefix } ${ diff . oldFileName } ` ;
410
416
const b_path = diff . newFileName . startsWith ( '/' ) ? diff . newFileName : `${ options . dest_prefix } ${ diff . newFileName } ` ;
411
417
418
+ const short_a_oid = await shorten_hash ( git_context , a . oid ) ;
419
+ const short_b_oid = await shorten_hash ( git_context , b . oid ) ;
420
+
412
421
// NOTE: This first line shows `a/$newFileName` for files that are new, not `/dev/null`.
413
422
const first_line_a_path = a_path !== '/dev/null' ? a_path : `${ options . source_prefix } ${ diff . newFileName } ` ;
414
423
s += chalk . bold ( `diff --git ${ first_line_a_path } ${ b_path } \n` ) ;
415
424
if ( a . mode === b . mode ) {
416
- s += chalk . bold ( `index ${ shorten_hash ( a . oid ) } ..${ shorten_hash ( b . oid ) } ${ a . mode } \n` ) ;
425
+ s += chalk . bold ( `index ${ short_a_oid } ..${ short_b_oid } ${ a . mode } \n` ) ;
417
426
} else {
418
427
if ( a . mode === '000000' ) {
419
428
s += chalk . bold ( `new file mode ${ b . mode } \n` ) ;
420
429
} else {
421
430
s += chalk . bold ( `old mode ${ a . mode } \n` ) ;
422
431
s += chalk . bold ( `new mode ${ b . mode } \n` ) ;
423
432
}
424
- s += chalk . bold ( `index ${ shorten_hash ( a . oid ) } ..${ shorten_hash ( b . oid ) } \n` ) ;
433
+ s += chalk . bold ( `index ${ short_a_oid } ..${ short_b_oid } \n` ) ;
425
434
}
426
435
if ( ! diff . hunks . length )
427
436
continue ;
0 commit comments