Skip to content

Commit 888bfbb

Browse files
committed
feat(git-v8): preserve original author when backporting
1 parent dfa9c92 commit 888bfbb

File tree

3 files changed

+75
-11
lines changed

3 files changed

+75
-11
lines changed

components/git/v8.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,22 @@ export function builder(yargs) {
4444
describe: 'Bump V8 embedder version number or patch version',
4545
default: true
4646
})
47+
.option('gpg-sign', {
48+
alias: 'S',
49+
type: 'boolean',
50+
describe: 'GPG-sign commits',
51+
default: false
52+
})
53+
.option('preserve-original-author', {
54+
type: 'boolean',
55+
describe: 'Preserve original commit author and date',
56+
default: true
57+
})
4758
.option('squash', {
4859
type: 'boolean',
4960
describe:
50-
'If multiple commits are backported, squash them into one',
61+
'If multiple commits are backported, squash them into one. When ' +
62+
'`--squash` is passed, `--preserve-original-author` will be ignored',
5163
default: false
5264
});
5365
}
@@ -88,7 +100,7 @@ export function handler(argv) {
88100
input,
89101
spawnArgs: {
90102
cwd: options.nodeDir,
91-
stdio: input ? ['pipe', 'ignore', 'ignore'] : 'ignore'
103+
stdio: input ? ['pipe', 'inherit', 'inherit'] : 'inherit'
92104
}
93105
});
94106
};
@@ -97,7 +109,7 @@ export function handler(argv) {
97109
return forceRunAsync('git', args, {
98110
ignoreFailure: false,
99111
captureStdout: true,
100-
spawnArgs: { cwd: options.v8Dir, stdio: ['ignore', 'pipe', 'ignore'] }
112+
spawnArgs: { cwd: options.v8Dir, stdio: ['ignore', 'pipe', 'inherit'] }
101113
});
102114
};
103115

lib/update-v8/backport.js

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export function doBackport(options) {
4141
}
4242
}
4343
todo.push(commitSquashedBackport());
44+
} else if (options.preserveOriginalAuthor) {
45+
todo.push(cherryPickV8Commits(options));
4446
} else {
4547
todo.push(applyAndCommitPatches());
4648
}
@@ -76,18 +78,35 @@ function commitSquashedBackport() {
7678
};
7779
};
7880

79-
function commitPatch(patch) {
81+
const commitTask = (patch, ...extraArgs) => async(ctx) => {
82+
const messageTitle = formatMessageTitle([patch]);
83+
const messageBody = formatMessageBody(patch, false);
84+
await ctx.execGitNode('add', ['deps/v8']);
85+
await ctx.execGitNode('commit', [
86+
...ctx.gpgSign, ...extraArgs,
87+
'-m', messageTitle, '-m', messageBody
88+
]);
89+
};
90+
91+
function amendHEAD(patch) {
8092
return {
81-
title: 'Commit patch',
93+
title: 'Amend/commit',
8294
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]);
95+
if (patch.hadConflicts) {
96+
await ctx.execGitNode('am', [...ctx.gpgSign, '--continue']);
97+
}
98+
await commitTask(patch, '--amend')(ctx);
8799
}
88100
};
89101
}
90102

103+
function commitPatch(patch) {
104+
return {
105+
title: 'Commit patch',
106+
task: commitTask(patch)
107+
};
108+
}
109+
91110
function formatMessageTitle(patches) {
92111
const action =
93112
patches.some(patch => patch.hadConflicts) ? 'backport' : 'cherry-pick';
@@ -167,6 +186,15 @@ function applyAndCommitPatches() {
167186
};
168187
}
169188

189+
function cherryPickV8Commits() {
190+
return {
191+
title: 'Cherry-pick commit from V8 clone to deps/v8',
192+
task: (ctx, task) => {
193+
return task.newListr(ctx.patches.map(cherryPickV8CommitTask));
194+
}
195+
};
196+
}
197+
170198
function applyPatchTask(patch) {
171199
return {
172200
title: `Commit ${shortSha(patch.sha)}`,
@@ -190,10 +218,33 @@ function applyPatchTask(patch) {
190218
};
191219
}
192220

193-
async function applyPatch(ctx, task, patch) {
221+
function cherryPickV8CommitTask(patch) {
222+
return {
223+
title: `Commit ${shortSha(patch.sha)}`,
224+
task: (ctx, task) => {
225+
const todo = [
226+
{
227+
title: 'Cherry-pick',
228+
task: (ctx, task) => applyPatch(ctx, task, patch, 'am')
229+
}
230+
];
231+
if (ctx.bump !== false) {
232+
if (ctx.nodeMajorVersion < 9) {
233+
todo.push(incrementV8Version());
234+
} else {
235+
todo.push(incrementEmbedderVersion());
236+
}
237+
}
238+
todo.push(amendHEAD(patch));
239+
return task.newListr(todo);
240+
}
241+
};
242+
}
243+
244+
async function applyPatch(ctx, task, patch, method = 'apply') {
194245
try {
195246
await ctx.execGitNode(
196-
'apply',
247+
method,
197248
['-p1', '--3way', '--directory=deps/v8'],
198249
patch.data /* input */
199250
);

lib/update-v8/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function minor(options) {
2626
export async function backport(options) {
2727
const shouldStop = await checkOptions(options);
2828
if (shouldStop) return;
29+
options.gpgSign = options.gpgSign ? ['-S'] : [];
2930
const tasks = new Listr(
3031
[updateV8Clone(), doBackport(options)],
3132
getOptions(options)

0 commit comments

Comments
 (0)