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

Use rugged for diffing #124

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Use rugged for diffing #124

wants to merge 1 commit into from

Conversation

Earlopain
Copy link

@Earlopain Earlopain commented Oct 13, 2023

This is a proof of concept.

Diffy currently uses a subprocesses to obtain a diff. This instead uses libgit through the gem rugged. I have opted to ignore backwards compatibility for this. There is probably a way you can have the current mode and this coexist but that would have introduced a bunch more complexity (I also don't see why you'd want to maintain both versions anyways).
Almost all tests are passing, except a few outliers I couldn't quite figure out myself.

This version is faster since it doesn't have to spawn subprocesses and is easier to install and deploy because rugged comes with everything it needs out of the box.

Connects to #123

Here is a monkeypatch to make use of this today. It's lacking quite a few features normally found in the gem but it works for my specific usecase and can easily extended.

require "rugged"

module DiffyNoSubprocess
  def diff
    @diff ||= Rugged::Patch.from_strings(@string1, @string2, context_lines: 10_000).to_s.force_encoding("UTF-8")
  end

  def each
    lines = diff.split("\n").drop(5).map { |line| "#{line}\n" }

    if block_given?
      lines.each { |line| yield line }
    else
      lines.to_enum
    end
  end
end

Diffy::Diff.prepend DiffyNoSubprocess

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.

None yet

1 participant