diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-16 14:35:48 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-23 19:06:00 +0100 |
commit | 3eb0354061b6c2ad39c90c9a3e9a5afa62e7685f (patch) | |
tree | 01147e7de1e4c50834c62aef7369782d2f8ad2a2 /lib | |
parent | 43fa9c1f1a40903f6416b954c326d67259c7290a (diff) | |
download | gitlab-ce-3eb0354061b6c2ad39c90c9a3e9a5afa62e7685f.tar.gz |
Make Git history follow renames again by performing the --skip in Ruby
This hack is needed because of an issue when --follow and --skip
are passed to git log at the same time.
See https://gitlab.com/gitlab-org/gitlab-ce/issues/23062
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 4b6ad8037ce..9c68060064a 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -324,24 +324,30 @@ module Gitlab end def log_by_shell(sha, options) + limit = options[:limit].to_i + offset = options[:offset].to_i + use_follow_flag = options[:follow] && options[:path].present? + + # We will perform the offset in Ruby because --follow doesn't play well with --skip. + # See: https://gitlab.com/gitlab-org/gitlab-ce/issues/3574#note_3040520 + offset_in_ruby = use_follow_flag && options[:offset].present? + limit += offset if offset_in_ruby + cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path} log) - cmd += %W(-n #{options[:limit].to_i}) + cmd += %W(-n #{limit}) cmd += %w(--format=%H) - cmd += %W(--skip=#{options[:offset].to_i}) - cmd += %w(--follow) if options[:follow] + cmd += %W(--skip=#{offset}) unless offset_in_ruby + cmd += %w(--follow) if use_follow_flag cmd += %w(--no-merges) if options[:skip_merges] cmd += %W(--after=#{options[:after].iso8601}) if options[:after] cmd += %W(--before=#{options[:before].iso8601}) if options[:before] cmd += [sha] cmd += %W(-- #{options[:path]}) if options[:path].present? - raw_output = IO.popen(cmd) {|io| io.read } - - log = raw_output.lines.map do |c| - Rugged::Commit.new(rugged, c.strip) - end + raw_output = IO.popen(cmd) { |io| io.read } + lines = offset_in_ruby ? raw_output.lines.drop(offset) : raw_output.lines - log.is_a?(Array) ? log : [] + lines.map { |c| Rugged::Commit.new(rugged, c.strip) } end def sha_from_ref(ref) |