|
3 | 3 | // It will download third-party source code, modify it, |
4 | 4 | // and install it into the correct locations. |
5 | 5 |
|
6 | | -import { execSync } from 'child_process' |
| 6 | +import { execFileSync } from 'child_process' |
7 | 7 | import { deepList, justFiles, makeNodeDisklet, navigateDisklet } from 'disklet' |
8 | 8 | import { existsSync, mkdirSync } from 'fs' |
9 | 9 | import { join } from 'path' |
@@ -160,33 +160,51 @@ async function copySwift(): Promise<void> { |
160 | 160 | function getRepo(name: string, uri: string, hash: string): void { |
161 | 161 | const path = join(tmp, name) |
162 | 162 |
|
163 | | - // Either clone or fetch: |
| 163 | + // Clone cheaply, then fetch just the pinned commit if needed: |
164 | 164 | if (!existsSync(path)) { |
165 | 165 | console.log(`Cloning ${name}...`) |
166 | | - loudExec(tmp, ['git', 'clone', uri, name]) |
167 | | - } else { |
168 | | - // We might already have the right commit, so fetch lazily: |
| 166 | + loudExec(tmp, [ |
| 167 | + 'git', |
| 168 | + 'clone', |
| 169 | + '--no-checkout', |
| 170 | + '--filter=blob:none', |
| 171 | + '--no-tags', |
| 172 | + uri, |
| 173 | + name |
| 174 | + ]) |
| 175 | + } |
| 176 | + |
| 177 | + if (!hasCommit(path, hash)) { |
| 178 | + console.log(`Fetching ${name}...`) |
169 | 179 | try { |
170 | | - loudExec(path, ['git', 'fetch']) |
| 180 | + loudExec(path, ['git', 'fetch', '--depth=1', '--no-tags', 'origin', hash]) |
171 | 181 | } catch (error) { |
172 | 182 | console.log(error) |
173 | 183 | } |
174 | 184 | } |
175 | 185 |
|
176 | 186 | // Checkout: |
177 | 187 | console.log(`Checking out ${name}...`) |
178 | | - execSync(`git checkout -f ${hash}`, { |
179 | | - cwd: path, |
180 | | - stdio: 'inherit', |
181 | | - encoding: 'utf8' |
182 | | - }) |
| 188 | + loudExec(path, ['git', 'checkout', '-f', hash]) |
| 189 | +} |
| 190 | + |
| 191 | +function hasCommit(path: string, hash: string): boolean { |
| 192 | + try { |
| 193 | + execFileSync('git', ['cat-file', '-e', `${hash}^{commit}`], { |
| 194 | + cwd: path, |
| 195 | + stdio: 'ignore' |
| 196 | + }) |
| 197 | + return true |
| 198 | + } catch (error) { |
| 199 | + return false |
| 200 | + } |
183 | 201 | } |
184 | 202 |
|
185 | 203 | /** |
186 | 204 | * Runs a command and displays its results. |
187 | 205 | */ |
188 | 206 | function loudExec(path: string, argv: string[]): void { |
189 | | - execSync(argv.join(' '), { |
| 207 | + execFileSync(argv[0], argv.slice(1), { |
190 | 208 | cwd: path, |
191 | 209 | stdio: 'inherit', |
192 | 210 | encoding: 'utf8' |
|
0 commit comments