diff --git a/README.md b/README.md index 505f630..b16e267 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Quoting Michael Feathers (source [here][michael-feathers-source]): view, using information from our version control systems, we can get a better sense of the effects of our refactoring efforts.* - Note: `code-complexity` currently measures complexity using either: - lines of code count (all languages) - cyclomatic complexity (JavaScript/TypeScript) @@ -43,6 +42,7 @@ $ npx code-complexity [options] -u, --until [until] limit analysis to commits older in age than date -s, --sort [sort] sort results (allowed valued: score, churn, complexity or file) -d, --directories display values for directories instead of files + -mb, --max-buffer [maxBuffer] set the max buffer size for git log (in bytes) -h, --help display help for command Examples: @@ -53,10 +53,11 @@ $ npx code-complexity [options] $ code-complexity ../foo --sort score $ code-complexity /foo/bar --filter 'src/**,!src/front/**' $ code-complexity . --limit 10 --sort score - $ code-complexity . --limit 10 --directories + $ code-complexity . --limit 10 --directories $ code-complexity . --limit 10 --sort score -cs halstead $ code-complexity . --since=2021-06-01 --limit 100 $ code-complexity . --since=2021-04-01 --until=2021-07-01 + $ code-complexity . --max-buffer 64000000 ``` ## Output diff --git a/src/io/cli.ts b/src/io/cli.ts index 80501b9..f212b4f 100644 --- a/src/io/cli.ts +++ b/src/io/cli.ts @@ -79,6 +79,11 @@ function getRawCli( "-d, --directories", "display values for directories instead of files" ) + .option( + "-mb, --max-buffer [maxBuffer]", + "set the max buffer size for git log (in bytes)", + parseInt + ) .on("--help", () => { console.log(); console.log("Examples:"); @@ -94,6 +99,7 @@ function getRawCli( "$ code-complexity . --limit 10 --sort score -cs halstead", "$ code-complexity . --since=2021-06-01 --limit 100", "$ code-complexity . --since=2021-04-01 --until=2021-07-01", + "$ code-complexity . --max-buffer 64000000", ].forEach((example) => console.log(example.padStart(2))); }); } @@ -113,6 +119,7 @@ function buildOptions(args: string[], options: any): Options { complexityStrategy: options.complexityStrategy ? (String(options.complexityStrategy) as ComplexityStrategy) : "sloc", + maxBuffer: options.maxBuffer ? Number(options.maxBuffer) : undefined, }; // FIXME: I'm not a fan of pulling the code here but it's good enough. diff --git a/src/lib/githistory/githistory.ts b/src/lib/githistory/githistory.ts index d3b62f8..1eabb85 100644 --- a/src/lib/githistory/githistory.ts +++ b/src/lib/githistory/githistory.ts @@ -68,7 +68,8 @@ export default class GitHistory { } private executeGitLogCommand(gitLogCommand: string): string { - return execSync(gitLogCommand, { encoding: "utf8", maxBuffer: 32_000_000 }); + const maxBuffer = this.options.maxBuffer ?? 32_000_000; + return execSync(gitLogCommand, { encoding: "utf8", maxBuffer }); } private listFiles(): string[] { diff --git a/src/lib/types.d.ts b/src/lib/types.d.ts index ee647e0..57f72e9 100644 --- a/src/lib/types.d.ts +++ b/src/lib/types.d.ts @@ -15,4 +15,5 @@ export type Options = { complexityStrategy?: ComplexityStrategy; filter?: string[]; format?: Format; + maxBuffer?: number; }; diff --git a/test/lib/statistics.test.ts b/test/lib/statistics.test.ts index d1227e4..e33af92 100644 --- a/test/lib/statistics.test.ts +++ b/test/lib/statistics.test.ts @@ -442,6 +442,27 @@ describe("Statistics", () => { }); }); + context("options.maxBuffer", () => { + it("returns the appropriate elements", async () => { + // Given + const options: Options = { ...defaultOptions, maxBuffer: 64_000_000 }; + new TestRepositoryFixture().addFile({ name: "a.js" }).writeOnDisk(); + + // When + const result = (await Statistics.compute(options)).list(); + + // Then + expect(result).to.deep.equal([ + { + churn: 1, + complexity: 1, + path: "a.js", + score: 1, + }, + ]); + }); + }); + context("when file no longer exists", () => { it("it is ignored", async () => { // Given