Class: Amp::Core::Repositories::Git::Encoding::BinaryDelta::CopyHunk

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(opcode, fp) ⇒ CopyHunk

Creates a new copy hunk.

Parameters:

  • opcode (Fixnum)

    the opcode that identifies this hunk’s properties.

  • fp (IO, #read)

    the input stream we’re reading this delta from



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.

Parameters:

  • output (IO, #write)

    the output buffer we’re building up

  • input (String)

    the original data. Used for copies.



162
163
164
# File 'lib/amp-git/encoding/binary_delta.rb', line 162

def apply(output, input)
  output.write input[@offset...@offset + @length]
end