Skip to content

Commit 7f49959

Browse files
committed
Retire the ProjectOptions class
Now that pretty much all the project-specific options that `PatchSeries` needs are part of `IConfig`, let's just move the remaining bits that that are needed to submit a patch series from `ProjectOptions` into the `PatchSeries` class itself. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 73e136f commit 7f49959

File tree

4 files changed

+48
-148
lines changed

4 files changed

+48
-148
lines changed

lib/patch-series.ts

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { md2text } from "./markdown-renderer.js";
99
import { IPatchSeriesMetadata } from "./patch-series-metadata.js";
1010
import { PatchSeriesOptions } from "./patch-series-options.js";
1111
import { IConfig } from "./project-config.js";
12-
import { ProjectOptions } from "./project-options.js";
1312
import { getPullRequestKeyFromURL } from "./pullRequestKey.js";
1413

1514
export interface ILogger {
@@ -138,19 +137,33 @@ export class PatchSeries {
138137
throw new Error(`Cannot find base branch ${basedOn}`);
139138
}
140139

141-
const project = await ProjectOptions.get(config, workDir, headCommit, cc, baseCommit, basedOn);
142140
if (rangeDiff) {
143141
options.rangeDiff = rangeDiff;
144142
}
145143

144+
cc.push(...config.project.cc);
145+
// Hard-code a check for gitgitgadget/git whether this is a Git GUI PR
146+
// and hence needs the Git GUI maintainer to be Cc:ed
147+
if (
148+
`${config.repo.owner}/${config.repo.name}` === "gitgitgadget/git" &&
149+
(await revParse(`${baseCommit}:git-gui.sh`, workDir)) !== undefined
150+
) {
151+
// Git GUI
152+
cc.push("Johannes Sixt <[email protected]>");
153+
}
154+
146155
return new PatchSeries(
147156
config,
148157
notes,
149158
options,
150-
project,
151159
metadata,
152160
rangeDiffRanges,
153161
patchCount,
162+
cc,
163+
workDir,
164+
headCommit,
165+
baseCommit,
166+
basedOn,
154167
coverLetter,
155168
senderName,
156169
);
@@ -525,9 +538,13 @@ export class PatchSeries {
525538
public readonly config: IConfig;
526539
public readonly notes: GitNotes;
527540
public readonly options: PatchSeriesOptions;
528-
public readonly project: ProjectOptions;
529541
public readonly metadata: IPatchSeriesMetadata;
530542
public readonly rangeDiff: IRangeDiff | undefined;
543+
public readonly cc: string[];
544+
public readonly workDir: string;
545+
public readonly headCommit: string;
546+
public readonly baseCommit: string;
547+
public readonly basedOn?: string;
531548
public readonly coverLetter?: string;
532549
public readonly senderName?: string;
533550
public readonly patchCount: number;
@@ -536,19 +553,27 @@ export class PatchSeries {
536553
config: IConfig,
537554
notes: GitNotes,
538555
options: PatchSeriesOptions,
539-
project: ProjectOptions,
540556
metadata: IPatchSeriesMetadata,
541557
rangeDiff: IRangeDiff | undefined,
542558
patchCount: number,
559+
cc: string[],
560+
workDir: string,
561+
headCommit: string,
562+
baseCommit: string,
563+
basedOn?: string,
543564
coverLetter?: string,
544565
senderName?: string,
545566
) {
546567
this.config = config;
547568
this.notes = notes;
548569
this.options = options;
549-
this.project = project;
550570
this.metadata = metadata;
551571
this.rangeDiff = rangeDiff;
572+
this.cc = cc;
573+
this.workDir = workDir;
574+
this.headCommit = headCommit;
575+
this.baseCommit = baseCommit;
576+
this.basedOn = basedOn;
552577
this.coverLetter = coverLetter;
553578
this.senderName = senderName;
554579
this.patchCount = patchCount;
@@ -570,9 +595,9 @@ export class PatchSeries {
570595
): Promise<IPatchSeriesMetadata | undefined> {
571596
let globalOptions: IGitGitGadgetOptions | undefined;
572597
if (this.options.dryRun) {
573-
logger.log(`Dry-run ${this.project.headCommit} v${this.metadata.iteration}`);
598+
logger.log(`Dry-run ${this.headCommit} v${this.metadata.iteration}`);
574599
} else {
575-
logger.log(`Submitting ${this.project.headCommit} v${this.metadata.iteration}`);
600+
logger.log(`Submitting ${this.headCommit} v${this.metadata.iteration}`);
576601
globalOptions = await this.notes.get<IGitGitGadgetOptions>("");
577602
}
578603

@@ -582,7 +607,7 @@ export class PatchSeries {
582607
PatchSeries.cleanUpHeaders(mails);
583608

584609
const ident = await git(["var", "GIT_AUTHOR_IDENT"], {
585-
workDir: this.project.workDir,
610+
workDir: this.workDir,
586611
});
587612
const match = ident.match(/.*>/);
588613
const thisAuthor = match && match[0];
@@ -638,7 +663,7 @@ export class PatchSeries {
638663
const tagMessage = PatchSeries.generateTagMessage(
639664
mails[0],
640665
mails.length > 1,
641-
this.project.midUrlPrefix,
666+
this.config.project.urlPrefix,
642667
this.metadata.referencesMessageIds,
643668
);
644669
const prKey = getPullRequestKeyFromURL(this.metadata.pullRequestURL);
@@ -701,7 +726,7 @@ export class PatchSeries {
701726
this.rangeDiff.previousRange,
702727
this.rangeDiff.currentRange,
703728
],
704-
{ workDir: this.project.workDir },
729+
{ workDir: this.workDir },
705730
);
706731
// split the range-diff and prefix with a space
707732
footers.push(
@@ -794,7 +819,7 @@ export class PatchSeries {
794819
globalOptions.activeMessageIDs[mid] = originalCommit;
795820
}
796821

797-
if (originalCommit && (await commitExists(originalCommit, this.project.workDir))) {
822+
if (originalCommit && (await commitExists(originalCommit, this.workDir))) {
798823
await this.notes.appendCommitNote(originalCommit, mid);
799824
}
800825
}
@@ -840,8 +865,8 @@ export class PatchSeries {
840865
}
841866

842867
protected async generateMBox(): Promise<string> {
843-
const mergeBase = await git(["merge-base", this.project.baseCommit, this.project.headCommit], {
844-
workDir: this.project.workDir,
868+
const mergeBase = await git(["merge-base", this.baseCommit, this.headCommit], {
869+
workDir: this.workDir,
845870
});
846871
const args = [
847872
"format-patch",
@@ -851,9 +876,9 @@ export class PatchSeries {
851876
"--add-header=Fcc: Sent",
852877
"--base",
853878
mergeBase,
854-
this.project.to,
879+
`--to=${this.config.project.to}`,
855880
].concat(PatchSeries.generateSingletonHeaders());
856-
this.project.cc.map((email) => {
881+
this.cc.map((email) => {
857882
args.push("--cc=" + PatchSeries.encodeSender(email));
858883
});
859884
if (this.metadata.referencesMessageIds) {
@@ -867,17 +892,17 @@ export class PatchSeries {
867892
}
868893
if (this.patchCount > 1) {
869894
if (!this.coverLetter) {
870-
throw new Error(`Branch ${this.project.headCommit} needs a description`);
895+
throw new Error(`Branch ${this.headCommit} needs a description`);
871896
}
872897
args.push("--cover-letter");
873898
}
874899
if (this.options.patience) {
875900
args.push("--patience");
876901
}
877902

878-
args.push(`${this.project.baseCommit}..${this.project.headCommit}`);
903+
args.push(`${this.baseCommit}..${this.headCommit}`);
879904

880-
return await git(args, { workDir: this.project.workDir });
905+
return await git(args, { workDir: this.workDir });
881906
}
882907

883908
protected async generateTagObject(tagName: string, tagMessage: string): Promise<void> {
@@ -887,10 +912,10 @@ export class PatchSeries {
887912
}
888913
args.push(tagName);
889914
args.push(this.metadata.headCommit);
890-
await git(args, { stdin: tagMessage, workDir: this.project.workDir });
915+
await git(args, { stdin: tagMessage, workDir: this.workDir });
891916
}
892917

893918
protected async sendMBox(mbox: string): Promise<void> {
894-
await git(["send-mbox"], { stdin: mbox, workDir: this.project.workDir });
919+
await git(["send-mbox"], { stdin: mbox, workDir: this.workDir });
895920
}
896921
}

lib/project-options.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

tests/patch-series.test.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { fileURLToPath } from "url";
33
import { git } from "../lib/git.js";
44
import { GitNotes } from "../lib/git-notes.js";
55
import { PatchSeries } from "../lib/patch-series.js";
6-
import { ProjectOptions } from "../lib/project-options.js";
76
import { testCreateRepo, testConfig } from "./test-lib.js";
87

98
jest.setTimeout(60000);
@@ -94,21 +93,8 @@ class PatchSeriesTest extends PatchSeries {
9493
headLabel: "",
9594
iteration: 1,
9695
};
97-
class ProjectOptionsTest extends ProjectOptions {
98-
public constructor() {
99-
super("", "", "", [], "", "", "");
100-
}
101-
}
102-
103-
const x = new PatchSeriesTest(
104-
testConfig,
105-
new GitNotes(),
106-
{},
107-
new ProjectOptionsTest(),
108-
prMeta,
109-
undefined,
110-
1,
111-
);
96+
97+
const x = new PatchSeriesTest(testConfig, new GitNotes(), {}, prMeta, undefined, 1, [], "", "", "");
11298

11399
x.insertCcAndFromLines(mails, thisAuthor, senderName);
114100

tests/project-options.test.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)