Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Option to perform diff without tempfiles #123

Open
davidbodow-st opened this issue Jul 13, 2023 · 1 comment
Open

[Feature request] Option to perform diff without tempfiles #123

davidbodow-st opened this issue Jul 13, 2023 · 1 comment

Comments

@davidbodow-st
Copy link

davidbodow-st commented Jul 13, 2023

Overview

When calling a diff of two large strings, a system that is low on disk space can fail with ENOSPC when attempting to write the strings to tempfiles.

Use Case

I would like to diff strings in memory, especially if the system has trimmed down the free disk substantially. For example, we use a large Sidekiq deployment, and having overprovisioned disk for 1000s of workers (only a few of which need to run disks) ends up costing a non-trivial amount. We could create a "high disk queue", but that seems more complex than adding a generally useful diffing option here.

Implementation Ideas

Bash process substitution can be used to avoid writing the tempfiles when calling diffbin:

❯ diff <(echo foo) <(echo bar)
1c1
< foo
---
> bar

We could handle passing the process substitution args instead of the usual args by implementing a new source in #diff: https://github.com/samg/diffy/blob/main/lib/diffy/diff.rb#L43

Other

I'd be happy to open a PR for this if there is interest in the feature, but no bandwidth otherwise.

Repository owner deleted a comment from ErCargo Jul 20, 2023
@samg
Copy link
Owner

samg commented Jul 20, 2023

Hi @davidbodow-st - I'd be happy to look at a PR for the feature you're describing. You'll have to be careful that it's implemented in a way which is secure and not susceptible to shell code injection (i.e. some way data in the diffed files can be interpreted as shell commands). Let me know when you have something ready to review and we could look at getting it included in the gem.

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

No branches or pull requests

2 participants