Skip to content

Add opt-in UPX clean/smudge filters - #136

Merged
dscho merged 1 commit into
mainfrom
upx-filter
Nov 4, 2026
Merged

dscho merged 1 commit into
mainfrom
upx-filter

Conversation

@mjcheetham

@mjcheetham mjcheetham commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Add opt-in clean/smudge filtering for large DLLs. Git stores UPX-packed binaries, while users can choose unpacked working-tree files to avoid decompression at startup.

Packed binaries remain runnable, so ordinary clones work without filter configuration or special checkout steps.

Usage

After checkout:

bash ./.large-dll-filter.sh setup

For configuration only, without unpacking existing files:

bash ./.large-dll-filter.sh setup --no-refresh

Help is available with --help, -h, or -?.

Revised design

Following review, filtering and setup share one hidden script, .large-dll-filter.sh, with clean, smudge, and setup modes.

The script prepends the checkout's UCRT64 and clangarm64 bin directories to PATH. Setup configures repository-local filters and directly unpacks existing attributed files. It does not replace files from the index or require transactional conversion: partially unpacked checkouts work too.

Clean/smudge retain private temporary files to bridge Git's streams to UPX's file interface. Packing uses --exact to preserve original bytes. The local driver is required so failed clean operations cannot silently stage unpacked binaries.

No filter attributes are introduced here. Selecting Rust's LLVM DLLs and configuring package-update automation are separate follow-ups.

Validation

Tested with packaged x64 UPX in both SDK directory layouts: lossless round trips, stable staging, repeated setup, configuration-only setup, Unicode and spaced paths, missing files, preservation of local working-file edits, and filter failure handling.

The script is identical across both SDK repositories. Native ARM64 execution has not been tested locally.

@mjcheetham

Copy link
Copy Markdown
Member Author

ARM64 counterpart PR: git-for-windows#69

@dscho dscho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this very good first iteration.

A lot of that iteration, however, suffers from Sol's overconfidence and inclination to write more code than is necessary, more code than is elegant, way more code than is desirable.

I think basically the entire 130 line script to set up the filter can be reduced to maybe a dozen. And if we do that already, if we condense and distill it to the elegance we strive for, we can easily and neatly fold the setup logic into the filter script.

Speaking of the filter script: I doubt that having upx in the name is doing us any favors. It is technically true, but it doesn't tell the reader anything about the script's purpose. Its purpose is to handle large DLLs. So maybe the filename should reflect that (and a comment at the top would not hurt one bit, either).

Also about the filter script: its location in the top level directory might be based on the prior art of the update-pacman.ps1 script. But I don't think it's actually a good idea to clutter the top level directory that way. In the least, I would like to make it a dot file, e.g. .git-large-dll-smudge-filter.sh. At least this way a regular ls would not show it.

Thoughts? Concerns?

Comment thread upx-filter.sh Outdated
if ! "$upx" --no-env -t "$directory/input.dll" >/dev/null 2>&1
then
# Validate unpacked input before passing it through.
"$upx" --no-env --exact -o "$directory/output.dll" \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, with --exact, code signatures are recreated precisely.

Comment thread upx-filter.sh Outdated

case "$1" in
clean)
# Git can clean content that is already in its repository form.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems a bit misleading. If the DLL is already compressed, we do not want to try to compress it again because that would fail with an error.

Comment thread setup-upx-filter.sh Resolved
Comment thread setup-upx-filter.sh Resolved
Comment thread setup-upx-filter.sh Resolved
Comment thread setup-upx-filter.sh Resolved
Comment thread setup-upx-filter.sh Resolved
Comment thread setup-upx-filter.sh Resolved
@mjcheetham

Copy link
Copy Markdown
Member Author

Also about the filter script: its location in the top level directory might be based on the prior art of the update-pacman.ps1 script. But I don't think it's actually a good idea to clutter the top level directory that way.

Sol initially tried to put the script in the .github/ directory, which I pointed out was a smell, since this is nothing to do with GitHub specifically (well, it kinda is since GitHub is the one with the file size limits).

With sparse-checkout however, we'd want to make sure the UPX pieces were always present (or could detect if they were missing; hence the validation).

@dscho

dscho commented Nov 3, 2026

Copy link
Copy Markdown
Member

Sol initially tried to put the script in the .github/ directory, which I pointed out was a smell, since this is nothing to do with GitHub specifically (well, it kinda is since GitHub is the one with the file size limits).

Heh. I repeated the exact sequence when I thought about better locations.

With sparse-checkout however, we'd want to make sure the UPX pieces were always present (or could detect if they were missing; hence the validation).

I disagree. Whether or not all the necessary bits and pieces are present in a sparse checkout is the user's responsibility, or at least the person's who makes the edits to the .sparse/* files.

This filter is a nice-to-have for most people, not a requirement. I need it to be focused, small, precise in its job. The fact that we will need to decompress the DLLs for the purposes of building Git installers or even for the ci-artifacts (because uncompressed DLLs compress better than UPX-compressed ones) only means that we have to follow up carefully over there, once, not that the script should carry complexity that is not justified by its long-term benefit.

Large DLLs can exceed remote file-size limits. UPX-packed binaries
remain runnable without filter configuration, at the cost of startup
decompression. Provide opt-in local filtering so users can trade disk
space for avoiding that repeated cost while Git keeps compressed blobs.

Provide clean, smudge, and setup modes in .large-dll-filter.sh. Prefer
the checkout's ucrt64/bin and clangarm64/bin on PATH so the same script
works in both SDKs and from a regular Git Bash.

After checkout, enable filtering and unpack existing attributed files:

    bash ./.large-dll-filter.sh setup

Use setup --no-refresh in package-update automation to configure the
driver without rewriting working-tree files. Setup installs these
repository-local values:

    filter.upx.clean = bash ./.large-dll-filter.sh clean
    filter.upx.smudge = bash ./.large-dll-filter.sh smudge
    filter.upx.required = true

Require successful filtering to avoid silently staging unpacked blobs
when clean fails. Attribute selection remains separate from setup.

Unpack existing packed files directly in the working tree, leaving the
index unchanged. Partial optimization is harmless, since both forms
work. Skip absent files, symlinks, and files not recognized as packed.
Disable Git's filename quoting when enumerating Windows paths so
spaces and Unicode names are preserved.

Use private temporary files for stream conversion, where UPX's file
interface requires them, and --exact to preserve original bytes.
Help is available with --help, -h, or -?.

Assisted-by: GPT-6.1 Sol
Signed-off-by: Matthew John Cheetham <[email protected]>

@dscho dscho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I see potential for further improvements, such as letting usage accept an optional exit code (defaulting to exit ${1-1}) because every call to usage exits afterwards, the only difference being the exit code, and moving the primary use case (clean and smudge) way up to the top (probably also refactoring the mktemp logic into its own function).

But these are merely optimizations for something that isn't performance-critical nor subject for heavy development, so the current form is fine.

@dscho
dscho merged commit 0ae7e73 into main Nov 4, 2026
44 of 45 checks passed
@dscho
dscho deleted the upx-filter branch November 4, 2026 14:00
@francescobarracca05-del

This comment was marked as spam.

@francescobarracca05-del

This comment was marked as spam.

@francescobarracca05-del

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants