Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.

Commit a83071a

Browse files
committed
Optimization of file history
1 parent 1f3a14e commit a83071a

File tree

4 files changed

+23
-47
lines changed

4 files changed

+23
-47
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v 7.2.9
2+
- Optimization of file history method
3+
14
v 7.2.8
25
- Ignore symbolic refs that point to deleted branches (Stan Hu)
36

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
gitlab_git (7.2.8)
4+
gitlab_git (7.2.9)
55
activesupport (~> 4.0)
66
charlock_holmes (~> 0.6)
77
gitlab-linguist (~> 3.0)
@@ -49,7 +49,7 @@ GEM
4949
guard (>= 1.1)
5050
rspec (~> 2.11)
5151
i18n (0.7.0)
52-
json (1.8.2)
52+
json (1.8.3)
5353
listen (1.0.2)
5454
rb-fsevent (>= 0.9.3)
5555
rb-inotify (>= 0.9)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.2.8
1+
7.2.9

lib/gitlab_git/repository.rb

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,23 @@ def log(options)
278278
options[:offset] ||= 0
279279
actual_ref = options[:ref] || root_ref
280280
sha = sha_from_ref(actual_ref)
281-
build_log(sha, options)
282-
rescue Rugged::OdbError, Rugged::InvalidError, Rugged::ReferenceError
283-
# Return an empty array if the ref wasn't found
284-
[]
281+
repo = options[:repo]
282+
283+
cmd = %W(git -C #{path} log)
284+
cmd << %W(-n #{options[:limit].to_i})
285+
cmd << %W(--skip=#{options[:offset].to_i})
286+
cmd << %W(--follow) if options[:follow]
287+
cmd << %W(--no-merges) if options[:skip_merges]
288+
cmd << sha
289+
cmd << %W(-- #{options[:path]}) if options[:path]
290+
291+
raw_output = IO.popen(cmd.flatten) {|io| io.read }
292+
293+
log = raw_output.scan(/commit\ ([0-9a-f]{40})/).flatten.map do |c|
294+
Rugged::Commit.new(rugged, c)
295+
end
296+
297+
log.is_a?(Array) ? log : []
285298
end
286299

287300
def sha_from_ref(ref)
@@ -837,46 +850,6 @@ def parse_gitmodules(commit, content)
837850
results
838851
end
839852

840-
# Return an array of log commits, given an SHA hash and a hash of
841-
# options.
842-
def build_log(sha, options)
843-
# Instantiate a Walker and add the SHA hash
844-
walker = Rugged::Walker.new(rugged)
845-
walker.push(sha)
846-
847-
commits = []
848-
skipped = 0
849-
current_path = options[:path]
850-
current_path = nil if current_path == ''
851-
852-
limit = options[:limit].to_i
853-
offset = options[:offset].to_i
854-
skip_merges = options[:skip_merges]
855-
856-
walker.sorting(Rugged::SORT_DATE)
857-
walker.each do |c|
858-
break if limit > 0 && commits.length >= limit
859-
860-
if skip_merges
861-
# Skip merge commits
862-
next if c.parents.length > 1
863-
end
864-
865-
if !current_path ||
866-
commit_touches_path?(c, current_path, options[:follow], walker)
867-
868-
# This is a commit we care about, unless we haven't skipped enough
869-
# yet
870-
skipped += 1
871-
commits.push(c) if skipped > offset
872-
end
873-
end
874-
875-
walker.reset
876-
877-
commits
878-
end
879-
880853
# Returns true if +commit+ introduced changes to +path+, using commit
881854
# trees to make that determination. Uses the history simplification
882855
# rules that `git log` uses by default, where a commit is omitted if it

0 commit comments

Comments
 (0)