Skip to content

Commit 62b6c2a

Browse files
committed
mingw-w64-git-lfs: make the logic a bit more readable
While the previous version works, and is concise, it is quite obviously much harder to read, to understand and to modify. Let's avoid those complex regular expressions and parse/transform the Git LFS release notes as well as the `PKGBUILD` file line by line. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a494353 commit 62b6c2a

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

update-scripts/mingw-w64-git-lfs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,29 @@
1717
`/repos/git-lfs/git-lfs/releases/tags/v${version}`
1818
)
1919

20-
const getSHA256 = (architecture) =>
21-
releaseNotes.match(new RegExp(`git-lfs-windows-${architecture}-\\S+\\.zip.*\r?\n([0-9a-f]{64})\r?\n`))[1]
22-
23-
const fs = require('fs')
24-
let PKGBUILD = fs.readFileSync('PKGBUILD').toString('utf-8')
25-
for (const architecture of [
26-
{ lfs: '386', msys2: 'i686' },
27-
{ lfs: 'amd64', msys2: 'x86_64' },
28-
{ lfs: 'arm64', msys2: 'aarch64' }
29-
]) {
30-
const match = PKGBUILD.match(new RegExp(`^([^]*\\r?\\n${architecture.msys2}\\)[^]*? sha256sum=)[0-9a-f]{64}([^]*)$`))
31-
PKGBUILD = `${match[1]}${getSHA256(architecture.lfs)}${match[2]}`
20+
const sha256sums = {}
21+
let architecture
22+
let match
23+
for (const line of releaseNotes.split(/\r?\n/)) {
24+
if (line.match(/^[0-9a-f]{64}$/)) sha256sums[architecture] = line
25+
else if ((match = line.match(/git-lfs-windows-(\S+)-v\S+\.zip/))) architecture = match[1]
26+
else architecture = undefined
27+
}
28+
29+
const msys2lfsArchitecture = {
30+
'i686': '386',
31+
'x86_64': 'amd64',
32+
'aarch64': 'arm64',
3233
}
33-
fs.writeFileSync('PKGBUILD', PKGBUILD)
34+
35+
const fs = require('fs')
36+
const lines = fs.readFileSync('PKGBUILD').toString('utf-8').split(/\r?\n/)
37+
lines.forEach((line, i) => {
38+
if ((match = line.match(/^(\S+)\)$/))) {
39+
architecture = msys2lfsArchitecture[match[1]]
40+
} else if ((match = line.match(/^(\s*sha256sum=)[0-9a-f]{64}$/))) {
41+
lines[i] = `${match[1]}${sha256sums[architecture]}`
42+
}
43+
})
44+
fs.writeFileSync('PKGBUILD', lines.join('\n'))
3445
})().catch(console.log)

0 commit comments

Comments
 (0)