Class: Amp::Core::Repositories::Git::Encoding::BinaryDelta::CopyHunk
- Inherits:
-
Object
- Object
- Amp::Core::Repositories::Git::Encoding::BinaryDelta::CopyHunk
- Defined in:
- lib/amp-git/encoding/binary_delta.rb
Overview
A Hunk that performs a copy operation. One of two types of delta hunks in the git binary delta format.
Instance Method Summary collapse
-
#apply(output, input) ⇒ Object
Applies the Hunk with a given output buffer with an input string.
-
#initialize(opcode, fp) ⇒ CopyHunk
constructor
Creates a new copy hunk.
Constructor Details
#initialize(opcode, fp) ⇒ CopyHunk
Creates a new copy hunk.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/amp-git/encoding/binary_delta.rb', line 140 def initialize(opcode, fp) @offset = @length = 0 shift = 0 0.upto(3) do @offset |= Support::HexString.from_bin(fp.read(1)).ord << shift if opcode & 0x01 > 0 opcode >>= 1 shift += 8 end shift = 0 0.upto(2) do @length |= Support::HexString.from_bin(fp.read(1)).ord << shift if opcode & 0x01 > 0 opcode >>= 1 shift += 8 end @length = 1 << 16 if @length == 0 end |
Instance Method Details
#apply(output, input) ⇒ Object
Applies the Hunk with a given output buffer with an input string.
162 163 164 |
# File 'lib/amp-git/encoding/binary_delta.rb', line 162 def apply(output, input) output.write input[@offset...@offset + @length] end |