Refactor Git::Diff to separate classes for DiffStats and DiffPathStatus #815
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Git::Diff
: The originalGit::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.Git::DiffStats
Class: A newGit::DiffStats
class has been introduced to exclusively handle the logic forgit diff --numstat
, providing access to insertion/deletion counts and file-level statistics.Git::DiffPathStatus
Class: A newGit::DiffPathStatus
class now manages the output ofgit 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::DiffStats
object.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
anddiff_path_status
methods for future work.