lib/gitlab_git/compare.rb in gitlab_git-4.0.0 vs lib/gitlab_git/compare.rb in gitlab_git-4.1.0
- old
+ new
@@ -5,29 +5,31 @@
def initialize(repository, from, to, limit = 100)
@commits, @diffs = [], []
@commit = nil
@same = false
+ @limit = limit
+ @repository = repository
return unless from && to
- base = Gitlab::Git::Commit.find(repository, from.try(:strip))
- head = Gitlab::Git::Commit.find(repository, to.try(:strip))
+ @base = Gitlab::Git::Commit.find(repository, from.try(:strip))
+ @head = Gitlab::Git::Commit.find(repository, to.try(:strip))
- return unless base && head
+ return unless @base && @head
- if base.id == head.id
+ if @base.id == @head.id
@same = true
return
end
- @commit = head
- @commits = Gitlab::Git::Commit.between(repository, base.id, head.id)
- @diffs = if @commits.size > limit
- []
- else
- Gitlab::Git::Diff.between(repository, head.id, base.id) rescue []
- end
+ @commit = @head
+ @commits = Gitlab::Git::Commit.between(repository, @base.id, @head.id)
+ end
+
+ def diffs(paths = nil)
+ return [] if @commits.size > @limit
+ Gitlab::Git::Diff.between(@repository, @head.id, @base.id, *paths) rescue []
end
end
end
end