From fc488dd86cf9a97c99b8dd1971978af839abfd53 Mon Sep 17 00:00:00 2001 From: Rich Evans Date: Sat, 5 Jan 2019 13:04:18 -0800 Subject: [PATCH] Chunk clean, checkout and update submodule commands within repository.ts to ensure the length of the files passed to the repository are less than 30k characters to avoid ENAMETOOLONG failures on Windows when working with very large changesets --- extensions/git/src/repository.ts | 61 ++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 6a57806ac12..6e4a2c34c0b 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -844,21 +844,70 @@ export class Repository implements Disposable { } }); - const promises: Promise[] = []; + const maxCommandLineLength: number = 30000; if (toClean.length > 0) { - promises.push(this.repository.clean(toClean)); + let sliceStart: number = 0; + let sliceEnd: number = 1; + let accumulatedStringLength = 0; + + while (sliceEnd < toClean.length) { + if ((accumulatedStringLength + (toClean[sliceEnd - 1].length + 1)) > maxCommandLineLength) { + await this.repository.clean(toClean.slice(sliceStart, sliceEnd)); + sliceStart = sliceEnd; + sliceEnd++; + accumulatedStringLength = 0; + } + else { + accumulatedStringLength += toClean[sliceEnd - 1].length + 1; + sliceEnd++; + } + } + + await this.repository.clean(toClean.slice(sliceStart, sliceEnd)); } if (toCheckout.length > 0) { - promises.push(this.repository.checkout('', toCheckout)); + let sliceStart: number = 0; + let sliceEnd: number = 1; + let accumulatedStringLength = 0; + + while (sliceEnd < toCheckout.length) { + if ((accumulatedStringLength + (toCheckout[sliceEnd - 1].length + 1)) > maxCommandLineLength) { + await this.repository.checkout('', toCheckout.slice(sliceStart, sliceEnd)); + sliceStart = sliceEnd; + sliceEnd++; + accumulatedStringLength = 0; + } + else { + accumulatedStringLength += toCheckout[sliceEnd - 1].length + 1; + sliceEnd++; + } + } + + await this.repository.checkout('', toCheckout.slice(sliceStart, sliceEnd)); } if (submodulesToUpdate.length > 0) { - promises.push(this.repository.updateSubmodules(submodulesToUpdate)); - } + let sliceStart: number = 0; + let sliceEnd: number = 1; + let accumulatedStringLength = 0; - await Promise.all(promises); + while (sliceEnd < submodulesToUpdate.length) { + if ((accumulatedStringLength + (submodulesToUpdate[sliceEnd - 1].length + 1)) > maxCommandLineLength) { + await this.repository.updateSubmodules(submodulesToUpdate.slice(sliceStart, sliceEnd)); + sliceStart = sliceEnd; + sliceEnd++; + accumulatedStringLength = 0; + } + else { + accumulatedStringLength += submodulesToUpdate[sliceEnd - 1].length + 1; + sliceEnd++; + } + } + + await this.repository.updateSubmodules(submodulesToUpdate.slice(sliceStart, sliceEnd)); + } }); }