@@ -9,6 +9,7 @@ import { ListrEnquirerPromptAdapter } from '@listr2/prompt-adapter-enquirer';
9
9
import { shortSha } from '../utils.js' ;
10
10
11
11
import { getCurrentV8Version } from './common.js' ;
12
+ import { forceRunAsync } from '../run.js' ;
12
13
13
14
export async function checkOptions ( options ) {
14
15
if ( options . sha . length > 1 && options . squash ) {
@@ -41,6 +42,8 @@ export function doBackport(options) {
41
42
}
42
43
}
43
44
todo . push ( commitSquashedBackport ( ) ) ;
45
+ } else if ( options . preserveOriginalAuthor ) {
46
+ todo . push ( cherryPickV8Commits ( options ) ) ;
44
47
} else {
45
48
todo . push ( applyAndCommitPatches ( ) ) ;
46
49
}
@@ -76,18 +79,47 @@ function commitSquashedBackport() {
76
79
} ;
77
80
} ;
78
81
79
- function commitPatch ( patch ) {
82
+ const commitTask = ( patch , extraArgs , trailers ) => async ( ctx ) => {
83
+ const messageTitle = formatMessageTitle ( [ patch ] ) ;
84
+ const messageBody = formatMessageBody ( patch , false , trailers ) ;
85
+ await ctx . execGitNode ( 'add' , [ 'deps/v8' ] ) ;
86
+ await ctx . execGitNode ( 'commit' , [
87
+ ...ctx . gpgSign , ...extraArgs ,
88
+ '-m' , messageTitle , '-m' , messageBody
89
+ ] ) ;
90
+ } ;
91
+
92
+ function amendHEAD ( patch ) {
80
93
return {
81
- title : 'Commit patch ' ,
94
+ title : 'Amend/commit ' ,
82
95
task : async ( ctx ) => {
83
- const messageTitle = formatMessageTitle ( [ patch ] ) ;
84
- const messageBody = formatMessageBody ( patch , false ) ;
85
- await ctx . execGitNode ( 'add' , [ 'deps/v8' ] ) ;
86
- await ctx . execGitNode ( 'commit' , [ '-m' , messageTitle , '-m' , messageBody ] ) ;
96
+ let coAuthor ;
97
+ if ( patch . hadConflicts ) {
98
+ const getGitConfigEntry = async ( configKey ) => {
99
+ const output = await forceRunAsync ( 'git' , [ 'config' , configKey ] , {
100
+ ignoreFailure : false ,
101
+ captureStdout : true ,
102
+ spawnArgs : { cwd : ctx . nodeDir }
103
+ } ) ;
104
+ return output . trim ( ) ;
105
+ } ;
106
+ await ctx . execGitNode ( 'am' , [ ...ctx . gpgSign , '--continue' ] ) ;
107
+ coAuthor = `\nCo-authored-by: ${
108
+ await getGitConfigEntry ( 'user.name' ) } <${
109
+ await getGitConfigEntry ( 'user.email' ) } >`;
110
+ }
111
+ await commitTask ( patch , [ '--amend' ] , coAuthor ) ( ctx ) ;
87
112
}
88
113
} ;
89
114
}
90
115
116
+ function commitPatch ( patch ) {
117
+ return {
118
+ title : 'Commit patch' ,
119
+ task : commitTask ( patch )
120
+ } ;
121
+ }
122
+
91
123
function formatMessageTitle ( patches ) {
92
124
const action =
93
125
patches . some ( patch => patch . hadConflicts ) ? 'backport' : 'cherry-pick' ;
@@ -106,12 +138,12 @@ function formatMessageTitle(patches) {
106
138
}
107
139
}
108
140
109
- function formatMessageBody ( patch , prefixTitle ) {
141
+ function formatMessageBody ( patch , prefixTitle , trailers = '' ) {
110
142
const indentedMessage = patch . message . replace ( / \n / g, '\n ' ) ;
111
143
const body =
112
144
'Original commit message:\n\n' +
113
145
` ${ indentedMessage } \n\n` +
114
- `Refs: https://github.com/v8/v8/commit/${ patch . sha } ` ;
146
+ `Refs: https://github.com/v8/v8/commit/${ patch . sha } ${ trailers } ` ;
115
147
116
148
if ( prefixTitle ) {
117
149
const action = patch . hadConflicts ? 'Backport' : 'Cherry-pick' ;
@@ -167,6 +199,15 @@ function applyAndCommitPatches() {
167
199
} ;
168
200
}
169
201
202
+ function cherryPickV8Commits ( ) {
203
+ return {
204
+ title : 'Cherry-pick commit from V8 clone to deps/v8' ,
205
+ task : ( ctx , task ) => {
206
+ return task . newListr ( ctx . patches . map ( cherryPickV8CommitTask ) ) ;
207
+ }
208
+ } ;
209
+ }
210
+
170
211
function applyPatchTask ( patch ) {
171
212
return {
172
213
title : `Commit ${ shortSha ( patch . sha ) } ` ,
@@ -190,10 +231,33 @@ function applyPatchTask(patch) {
190
231
} ;
191
232
}
192
233
193
- async function applyPatch ( ctx , task , patch ) {
234
+ function cherryPickV8CommitTask ( patch ) {
235
+ return {
236
+ title : `Commit ${ shortSha ( patch . sha ) } ` ,
237
+ task : ( ctx , task ) => {
238
+ const todo = [
239
+ {
240
+ title : 'Cherry-pick' ,
241
+ task : ( ctx , task ) => applyPatch ( ctx , task , patch , 'am' )
242
+ }
243
+ ] ;
244
+ if ( ctx . bump !== false ) {
245
+ if ( ctx . nodeMajorVersion < 9 ) {
246
+ todo . push ( incrementV8Version ( ) ) ;
247
+ } else {
248
+ todo . push ( incrementEmbedderVersion ( ) ) ;
249
+ }
250
+ }
251
+ todo . push ( amendHEAD ( patch ) ) ;
252
+ return task . newListr ( todo ) ;
253
+ }
254
+ } ;
255
+ }
256
+
257
+ async function applyPatch ( ctx , task , patch , method = 'apply' ) {
194
258
try {
195
259
await ctx . execGitNode (
196
- 'apply' ,
260
+ method ,
197
261
[ '-p1' , '--3way' , '--directory=deps/v8' ] ,
198
262
patch . data /* input */
199
263
) ;
0 commit comments