Class: GitSpelunk::Offset

Inherits:
Object
  • Object
show all
Defined in:
lib/git_spelunk/offset.rb

Defined Under Namespace

Classes: Chunk

Constant Summary collapse

STATS_PATTERN =
/@@ \-(\d+),(\d+) \+(\d+),(\d+) @@/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, file_name, sha, line_number) ⇒ Offset

Returns a new instance of Offset.



39
40
41
42
43
44
45
46
47
# File 'lib/git_spelunk/offset.rb', line 39

def initialize(repo, file_name, sha, line_number)
  @repo = repo
  @file_name = file_name
  @sha = sha
  @line_number = line_number
  @commit = @repo.lookup(@sha)
  @parent = @commit.parents[0]
  true
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



37
38
39
# File 'lib/git_spelunk/offset.rb', line 37

def file_name
  @file_name
end

#hunksObject (readonly)

Returns the value of attribute hunks.



37
38
39
# File 'lib/git_spelunk/offset.rb', line 37

def hunks
  @hunks
end

#repoObject (readonly)

Returns the value of attribute repo.



37
38
39
# File 'lib/git_spelunk/offset.rb', line 37

def repo
  @repo
end

#shaObject (readonly)

Returns the value of attribute sha.



37
38
39
# File 'lib/git_spelunk/offset.rb', line 37

def sha
  @sha
end

Instance Method Details

#at_beginning_of_time?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/git_spelunk/offset.rb', line 137

def at_beginning_of_time?
  @parent.nil?
end

#line_number_to_parentObject



145
146
147
148
149
150
151
152
153
# File 'lib/git_spelunk/offset.rb', line 145

def line_number_to_parent
  return :at_beginning_of_time unless @parent && hunks
  chunk = target_chunk(@line_number)
  return :unable_to_trace unless chunk

  return :first_commit_for_file if chunk.minus_offset == 0 && chunk.minus_length == 0

  chunk.find_parent_line_number(@line_number)
end

#unable_to_trace_lineage?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/git_spelunk/offset.rb', line 141

def unable_to_trace_lineage?
  @parent && (@hunks.nil? || target_chunk.nil?)
end