samg / diffy

Easy Diffing in Ruby

Home Page:http://rubygems.org/gems/diffy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request] Option to perform diff without tempfiles

davidbodow-st opened this issue · comments

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.

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.