Class: Git::DiffFilePatchInfo Private

Inherits:
Data
  • Object
show all
Defined in:
lib/git/diff_file_patch_info.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Immutable value object representing a single file's patch information

DiffFilePatchInfo encapsulates the parsed data from a unified diff for one file, including source and destination file references, the patch text, change type, and line statistics.

Work in progress; this class is internal for now and may be made public in a future release.

Examples:

A modified file patch

patch_info = Git::DiffFilePatchInfo.new(
  src: Git::FileRef.new(mode: '100644', sha: 'abc1234', path: 'lib/foo.rb'),
  dst: Git::FileRef.new(mode: '100644', sha: 'def5678', path: 'lib/foo.rb'),
  patch: "diff --git a/lib/foo.rb b/lib/foo.rb\n...",
  status: :modified,
  similarity: nil,
  binary: false,
  insertions: 10,
  deletions: 5
)

A new file patch (src is nil)

patch_info = Git::DiffFilePatchInfo.new(
  src: nil,
  dst: Git::FileRef.new(mode: '100644', sha: 'abc1234', path: 'lib/new.rb'),
  patch: "diff --git a/lib/new.rb b/lib/new.rb\nnew file mode 100644\n...",
  status: :added,
  similarity: nil,
  binary: false,
  insertions: 20,
  deletions: 0
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binaryBoolean (readonly)

Returns whether this is a binary file.

Returns:

  • (Boolean)

    whether this is a binary file



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#deletionsInteger (readonly)

Returns number of lines deleted.

Returns:

  • (Integer)

    number of lines deleted



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#dstFileRef? (readonly)

Returns the destination file reference, or nil for deleted files.

Returns:

  • (FileRef, nil)

    the destination file reference, or nil for deleted files



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#insertionsInteger (readonly)

Returns number of lines inserted.

Returns:

  • (Integer)

    number of lines inserted



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#patchString (readonly)

Returns the full unified diff patch text for this file.

Returns:

  • (String)

    the full unified diff patch text for this file



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#similarityInteger? (readonly)

Returns similarity percentage for renames/copies (0-100), nil otherwise.

Returns:

  • (Integer, nil)

    similarity percentage for renames/copies (0-100), nil otherwise



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#srcFileRef? (readonly)

Returns the source file reference, or nil for new/added files.

Returns:

  • (FileRef, nil)

    the source file reference, or nil for new/added files



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#statusSymbol (readonly)

Returns the change status (:added, :modified, :deleted, :renamed, :copied, :type_changed).

Returns:

  • (Symbol)

    the change status (:added, :modified, :deleted, :renamed, :copied, :type_changed)



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/git/diff_file_patch_info.rb', line 64

DiffFilePatchInfo = Data.define(
  :src,
  :dst,
  :patch,
  :status,
  :similarity,
  :binary,
  :insertions,
  :deletions
) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source file path
  #
  # Returns the source path if it exists. Useful for renames/copies to see
  # where the file came from.
  #
  # @return [String, nil] the source file path, or nil if no source (added files)
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

Instance Method Details

#added?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if this file was added

Returns:

  • (Boolean)


124
125
126
# File 'lib/git/diff_file_patch_info.rb', line 124

def added?
  status == :added
end

#binary?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if this is a binary file

Returns:

  • (Boolean)

    true if the file is binary



100
101
102
# File 'lib/git/diff_file_patch_info.rb', line 100

def binary?
  binary
end

#copied?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if this file was copied

Returns:

  • (Boolean)


116
117
118
# File 'lib/git/diff_file_patch_info.rb', line 116

def copied?
  status == :copied
end

#deleted?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if this file was deleted

Returns:

  • (Boolean)


132
133
134
# File 'lib/git/diff_file_patch_info.rb', line 132

def deleted?
  status == :deleted
end

#pathString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the primary file path

Returns the destination path if it exists, otherwise the source path. This is the "current" or "canonical" path for the file.

Returns:

  • (String)

    the file path



81
82
83
# File 'lib/git/diff_file_patch_info.rb', line 81

def path
  dst&.path || src&.path
end

#renamed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if this file was renamed

Returns:

  • (Boolean)


108
109
110
# File 'lib/git/diff_file_patch_info.rb', line 108

def renamed?
  status == :renamed
end

#src_pathString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the source file path

Returns the source path if it exists. Useful for renames/copies to see where the file came from.

Returns:

  • (String, nil)

    the source file path, or nil if no source (added files)



92
93
94
# File 'lib/git/diff_file_patch_info.rb', line 92

def src_path
  src&.path
end