diff options
author | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2012-07-20 08:39:34 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2012-07-20 08:39:34 +0300 |
commit | 3063af5adcf1c0331681fbbc13e679de1eb96487 (patch) | |
tree | 3c3b7459bcdf8c2f52ba05ea0cc68d88c9e62a90 /app/models/commit.rb | |
parent | 3c6daec4b1194f5a2c43fcc5b7e370cd5c8add1e (diff) | |
download | gitlab-ce-3063af5adcf1c0331681fbbc13e679de1eb96487.tar.gz |
BaseContext
Controllers refactoring with contexts
Move commit compare logic to model
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 800ad19b9f1..859bee29fa5 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -80,6 +80,29 @@ class Commit def commits_between(repo, from, to) repo.commits_between(from, to).map { |c| Commit.new(c) } end + + def compare(project, from, to) + first = project.commit(to.try(:strip)) + last = project.commit(from.try(:strip)) + + result = { + :commits => [], + :diffs => [], + :commit => nil + } + + if first && last + commits = [first, last].sort_by(&:created_at) + younger = commits.first + older = commits.last + + result[:commits] = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} + result[:diffs] = project.repo.diff(younger.id, older.id) rescue [] + result[:commit] = Commit.new(older) + end + + result + end end def persisted? |