class Commit

Attributes

commit[RW]
head[RW]
refs[RW]

Public Class Methods

commits(repo, ref, path = nil, limit = nil, offset = nil) click to toggle source
# File app/models/commit.rb, line 58
def commits(repo, ref, path = nil, limit = nil, offset = nil)
  if path
    repo.log(ref, path, max_count: limit, skip: offset)
  elsif limit && offset
    repo.commits(ref, limit, offset)
  else
    repo.commits(ref)
  end.map{ |c| Commit.new(c) }
end
commits_between(repo, from, to) click to toggle source
# File app/models/commit.rb, line 68
def commits_between(repo, from, to)
  repo.commits_between(from, to).map { |c| Commit.new(c) }
end
commits_since(repo, date) click to toggle source
# File app/models/commit.rb, line 46
def commits_since(repo, date)
  commits = repo.heads.map do |h|
    repo.log(h.name, nil, since: date).each { |c| Commit.new(c, h) }
  end.flatten.uniq { |c| c.id }

  commits.sort! do |x, y|
    y.committed_date <=> x.committed_date
  end

  commits
end
commits_with_refs(repo, n = 20) click to toggle source
# File app/models/commit.rb, line 36
def commits_with_refs(repo, n = 20)
  commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) }

  commits.sort! do |x, y|
    y.committed_date <=> x.committed_date
  end

  commits[0..n]
end
compare(project, from, to) click to toggle source
# File app/models/commit.rb, line 72
def compare(project, from, to)
  result = {
    commits: [],
    diffs: [],
    commit: nil,
    same: false
  }

  return result unless from && to

  first = project.commit(to.try(:strip))
  last = project.commit(from.try(:strip))

  if first && last
    commits = [first, last].sort_by(&:created_at)
    younger = commits.first
    older = commits.last

    result[:same] = (younger.id == older.id)
    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
find_or_first(repo, commit_id = nil, root_ref) click to toggle source
# File app/models/commit.rb, line 14
def find_or_first(repo, commit_id = nil, root_ref)
  commit = if commit_id
             repo.commit(commit_id)
           else
             repo.commits(root_ref).first
           end

  Commit.new(commit) if commit
end
fresh_commits(repo, n = 10) click to toggle source
# File app/models/commit.rb, line 24
def fresh_commits(repo, n = 10)
  commits = repo.heads.map do |h|
    repo.commits(h.name, n).map { |c| Commit.new(c, h) }
  end.flatten.uniq { |c| c.id }

  commits.sort! do |x, y|
    y.committed_date <=> x.committed_date
  end

  commits[0...n]
end
new(raw_commit, head = nil) click to toggle source
# File app/models/commit.rb, line 100
def initialize(raw_commit, head = nil)
  @commit = raw_commit
  @head = head
end

Public Instance Methods

author_email() click to toggle source
# File app/models/commit.rb, line 117
def author_email
  author.email
end
author_name() click to toggle source
# File app/models/commit.rb, line 121
def author_name
  utf8 author.name
end
committer_email() click to toggle source
# File app/models/commit.rb, line 134
def committer_email
  committer.email
end
committer_name() click to toggle source
# File app/models/commit.rb, line 130
def committer_name
  utf8 committer.name
end
created_at() click to toggle source
# File app/models/commit.rb, line 113
def created_at
  committed_date
end
different_committer?() click to toggle source

Was this commit committed by a different person than the original author?

# File app/models/commit.rb, line 126
def different_committer?
  author_name != committer_name || author_email != committer_email
end
parents_count() click to toggle source
# File app/models/commit.rb, line 146
def parents_count
  parents && parents.count || 0
end
prev_commit() click to toggle source
# File app/models/commit.rb, line 138
def prev_commit
  parents.try :first
end
prev_commit_id() click to toggle source
# File app/models/commit.rb, line 142
def prev_commit_id
  prev_commit.try :id
end
safe_message() click to toggle source
# File app/models/commit.rb, line 109
def safe_message
  @safe_message ||= utf8 message
end
short_id(length = 10) click to toggle source
# File app/models/commit.rb, line 105
def short_id(length = 10)
  id.to_s[0..length]
end