Module: Canopus::Workspace::GitBlame
- Defined in:
- lib/canopus/workspace/git_blame.rb
Defined Under Namespace
Classes: GitBlameLine, GitBlameSnapshot
Constant Summary
collapse
- BLAME_MAX_BYTES =
1 << 20
- BLAME_MAX_LINES =
20_000
- BLAME_CACHE_LIMIT =
16
- BLAME_BUDGET =
Porrima::Budget.new(max_bytes: 2 << 20, max_lines: BLAME_MAX_LINES)
Instance Method Summary
collapse
Instance Method Details
#close_git ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/canopus/workspace/git_blame.rb', line 62
def close_git
@git_blame_generation = (@git_blame_generation || 0) + 1
jobs = [*@git_blame_jobs&.values].compact.uniq.reject { |thread| thread.equal?(Thread.current) }
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 0.1
jobs.each do |thread|
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
break unless remaining.positive?
thread.join(remaining)
end
jobs.each { |thread| thread.kill if thread.alive? }
jobs.each(&:join)
@git_blame_jobs&.clear
super
end
|
#git_blame_decorations(buffer, rows, current = nil) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/canopus/workspace/git_blame.rb', line 13
def git_blame_decorations(buffer, rows, current = nil)
mode = @settings["git"]["inline_blame"]
return [] if mode == "off" || !buffer.path || buffer.rope.bytesize > BLAME_MAX_BYTES ||
buffer.line_count > BLAME_MAX_LINES
text = buffer.text
return [] unless git_blame_text_supported?(text)
path = safe_git_diff_path(git_relative_path(buffer))
key = [buffer.object_id, buffer.version, @git_generation.to_i, path].freeze
snapshot = (@git_blame_cache ||= {})[key]
unless snapshot
requested = request_git_blame(buffer, path, key, text.dup.freeze)
snapshot = requested if requested.is_a?(GitBlameSnapshot)
return [] unless snapshot
end
return [] if snapshot.reason
visible = rows.begin...[rows.end, buffer.line_count].min
selected = if mode == "cursor"
return [] unless current.is_a?(Editor) && current.buffer.equal?(buffer)
row = buffer.rope.point_at(current.primary.head).row
visible.cover?(row) ? [row] : []
else
visible.to_a
end
selected.filter_map do |row|
next if row == buffer.line_count - 1 && buffer.line(row).empty?
git_blame_decoration(buffer, row, snapshot.lines[row])
end
rescue Error
[]
end
|
#invalidate_git ⇒ Object
57
58
59
60
|
# File 'lib/canopus/workspace/git_blame.rb', line 57
def invalidate_git
invalidate_git_blame
super
end
|
#invalidate_git_blame(buffer = nil) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/canopus/workspace/git_blame.rb', line 46
def invalidate_git_blame(buffer = nil)
@git_blame_generation = (@git_blame_generation || 0) + 1
if buffer
@git_blame_cache&.delete_if { |key, _| key[0] == buffer.object_id }
else
@git_blame_cache&.clear
end
@decorations.invalidate(:blame, buffer: buffer)
nil
end
|