Skip to content

Refactor Git::Diff to separate classes for DiffStats and DiffPathStatus #815

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

Merged
merged 1 commit into from
Jul 2, 2025

Conversation

jcouball
Copy link
Member

@jcouball jcouball commented Jul 2, 2025

This pull request refactors the Git::Diff class decomposing it into new, more focused classes, while backward compatibility is maintained via a deprecated facade.

Summary of Changes

  • Decomposed Git::Diff: The original Git::Diff class, which handled full patch parsing, statistics, and name-status, has been refactored. Its core responsibility is now limited to parsing a full diff patch and providing an enumeration of DiffFile objects.
  • New Git::DiffStats Class: A new Git::DiffStats class has been introduced to exclusively handle the logic for git diff --numstat, providing access to insertion/deletion counts and file-level statistics.
  • New Git::DiffPathStatus Class: A new Git::DiffPathStatus class now manages the output of git diff --name-status, providing a clear mapping of changed file paths to their status (e.g., 'A', 'M', 'D').

New Public API

To provide direct access to this new, cleaner implementation, the following methods have been added to Git::Base:

  • Git::Base#diff_stats(from, to): Returns a Git::DiffStats object.
  • Git::Base#diff_path_status(from, to): Returns a Git::DiffPathStatus object.

Backward Compatibility

To ensure a smooth transition for existing users, the public interface of Git::Diff remains unchanged. Methods such as .stats, .insertions, and .name_status will continue to function as before, but they now delegate to the new underlying classes and will issue deprecation warnings.

Deprecation warnings can be silenced by adding Git::Deprecation.behavior = :silence to your code.

This provides a clear migration path for users, who are encouraged to adopt the new diff_stats and diff_path_status methods for future work.

This pull request refactors the Git::Diff decomposing it into new, more focused
classes, while backward compatibility is maintained via a deprecated facade.
@jcouball jcouball merged commit e22eb10 into main Jul 2, 2025
7 checks passed
@jcouball jcouball deleted the refactor_diff branch July 2, 2025 23:27
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.

1 participant