diff options
author | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-07-24 05:46:36 -0700 |
---|---|---|
committer | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-07-24 05:46:36 -0700 |
commit | eca823c1c7cef45cc18c6ab36d2327650c85bfc3 (patch) | |
tree | 50b6d6cce1d1da7f5a6e08b497b1b35718db30a9 /app/models/commit.rb | |
parent | 024e0348904179a8dea81c01e27a5f014cf57499 (diff) | |
parent | 8b7e404b5b6944e9c92cc270b2e5d0005781d49d (diff) | |
download | gitlab-ce-eca823c1c7cef45cc18c6ab36d2327650c85bfc3.tar.gz |
Merge branch 'master' into api
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? |