gitlab_git 7.2.11 → 7.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/gitlab_git/blame.rb +57 -11
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50788ad664893b2875689cfa12eb02c5bd730ec1
4
- data.tar.gz: fcf06c07bd60c4e88d049ee75eb7fc7724819036
3
+ metadata.gz: 3dfe1adc18e236f4674a8a9444280bad676a7813
4
+ data.tar.gz: 8071dc50122e79328543e6a14965141d58450914
5
5
  SHA512:
6
- metadata.gz: 039657190c51f2a0e2b18680c6ab70d878ad89795ea1866b161b59e4be645e337652391097b645f75e465a155d30b57ce113c012066279763494ce84fa8f2fff
7
- data.tar.gz: 40d9f6f79c4820ea7a0a99730c463f85f4e71ae9702217df120bce263c9fc010b632302cf3747d0eff3dea19c98563597f7d21f61a43782dd8646712f546407c
6
+ metadata.gz: ed619af4decb82283bd18af7842d0abd3fb6433b3999ae395cd85d99eba84f8fcbb77305676aac13d387ceadfd81dfe800c7821e3b36c31fc779c8a198fa8f65
7
+ data.tar.gz: dc1bc45f26596917a2adc26bab5e94a0ee64655ca84f407259049f8f5ec65fbf29155d8d04b92cb95cdab5f3b2378665ad5c47d65457d93f6af2093ac04ec6ac
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.11
1
+ 7.2.12
@@ -1,24 +1,70 @@
1
1
  module Gitlab
2
2
  module Git
3
3
  class Blame
4
- attr_accessor :blob
4
+ attr_reader :lines, :blames
5
5
 
6
6
  def initialize(repository, sha, path)
7
- @repo = repository.rugged
8
- @blame = Rugged::Blame.new(@repo, path, { newest_commit: sha })
9
- @blob = Blob.find(repository, sha, path)
10
- @lines = @blob.data.split("\n")
7
+ @repo = repository
8
+ @sha = sha
9
+ @path = path
10
+ @lines = []
11
+ @blames = load_blame
11
12
  end
12
13
 
13
14
  def each
14
- @blame.each do |blame|
15
- from = blame[:final_start_line_number] - 1
16
- commit = @repo.lookup(blame[:final_commit_id])
15
+ @blames.each do |blame|
16
+ yield(
17
+ Gitlab::Git::Commit.new(blame.commit),
18
+ blame.line
19
+ )
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def load_blame
26
+ cmd = %W(git --git-dir=#{@repo.path} blame -p #{@sha} -- #{@path})
27
+ raw_output = IO.popen(cmd) {|io| io.read }
28
+ process_raw_blame raw_output
29
+ end
30
+
31
+ def process_raw_blame(output)
32
+ lines, final = [], []
33
+ info, commits = {}, {}
34
+
35
+ # process the output
36
+ output.split("\n").each do |line|
37
+ if line[0, 1] == "\t"
38
+ lines << line[1, line.size]
39
+ elsif m = /^(\w{40}) (\d+) (\d+)/.match(line)
40
+ commit_id, old_lineno, lineno = m[1], m[2].to_i, m[3].to_i
41
+ commits[commit_id] = nil if !commits.key?(commit_id)
42
+ info[lineno] = [commit_id, old_lineno]
43
+ end
44
+ end
45
+
46
+ # load all commits in single call
47
+ commits.keys.each do |key|
48
+ commits[key] = @repo.lookup(key)
49
+ end
17
50
 
18
- yield(Gitlab::Git::Commit.new(commit),
19
- @lines[from, blame[:lines_in_hunk]] || [],
20
- blame[:final_start_line_number])
51
+ # get it together
52
+ info.sort.each do |lineno, (commit_id, old_lineno)|
53
+ commit = commits[commit_id]
54
+ final << BlameLine.new(lineno, old_lineno, commit, lines[lineno - 1])
21
55
  end
56
+
57
+ @lines = final
58
+ end
59
+ end
60
+
61
+ class BlameLine
62
+ attr_accessor :lineno, :oldlineno, :commit, :line
63
+ def initialize(lineno, oldlineno, commit, line)
64
+ @lineno = lineno
65
+ @oldlineno = oldlineno
66
+ @commit = commit
67
+ @line = line
22
68
  end
23
69
  end
24
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.11
4
+ version: 7.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-10 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab-linguist
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.4.3
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Gitlab::Git library