Permalink
Browse files

commit has many parents (not just one)

  • Loading branch information...
1 parent 8401f74 commit 2c9eaefee5009b6da7acea18bf33553998c302c6 @comboy comboy committed Mar 21, 2012
View
@@ -20,6 +20,9 @@ class Commit < ActiveRecord::Base
has_many :test_suite_runs
has_many :project_instance_commits
+ has_and_belongs_to_many :parents,
+ :class_name => 'Commit', :association_foreign_key => 'parent_id', :join_table => 'commits_parents'
+
def short_description
desc = description.split("\n").first
if desc.size > 100
@@ -32,13 +35,6 @@ def short_number
number[0..8]
end
- def parent
- #FIXME TODO XXX
- parent = project.commits.order('committed_at DESC').where('committed_at < ?',self.committed_at).first
- parent = parent.parent if parent.skipped?
- parent
- end
-
def next
#FIXME TODO XXX
project.commits.order('committed_at ASC').where('committed_at > ?',self.committed_at).first
@@ -85,7 +85,9 @@ def prepare_env(commit)
pi_commit = commit.in_instance(self) #FIXME architect it better
# Older commits should always be prepared first
- prepare_env(pi_commit.parent.commit) if pi_commit.parent && !pi_commit.parent.prepared?
+ pi_commit.parents.each do |pic_parent|
+ prepare_env(pic_parrent.commit) unless pic_parent.prepared?
+ end
if pi_commit.prepared?
project_handler.prepare_env pi_commit
@@ -21,8 +21,8 @@ def prepared?
self.state == 'prepared'
end
- def parent
- commit.parent.try(:in_instance, project_instance)
+ def parents
+ commit.parents.map {|c| c.in_instance project_instance }
end
def data=(value)
@@ -36,9 +36,10 @@ def build_state
return 'fail'
end
+ # FIXME it's using only one parent (may fails for merges)
def previous_run
- @previous_run ||= (commit.parent &&
- commit.parent.test_suite_runs.where(:test_suite_id => test_suite.id).
+ @previous_run ||= (commit.parents.first &&
+ commit.parents.first.test_suite_runs.where(:test_suite_id => test_suite.id).
order('created_at DESC').first)
end
@@ -1,7 +1,7 @@
- introduced = fixed = []
- if tsr = commit.test_suite_runs.order('created_at DESC').first
- state = commit.build_state
-- if parent = commit.parent
+-# if parent = commit.parent
-# if tsr && parent.test_suite_runs.first
-# parent_errors = parent.test_suite_runs.first.test_unit_runs.with_error
-# my_errors = tsr.test_unit_runs.with_error
@@ -42,7 +42,8 @@
- commit.test_suite_runs.finished.includes(:test_suite).order('test_suites.created_at').group_by(&:test_suite).each do |ts, tsrs|
- prev_tsr = nil
- - prev_tsr = parent.test_suite_runs.where(:test_suite_id => ts.id).first if parent
+ - # FIXME this is using only one parrent
+ - prev_tsr = commit.parents.first.test_suite_runs.where(:test_suite_id => ts.id).first if commit.parents.first
%b= "#{ts.name}:"
- tsr = tsrs.first
@@ -4,7 +4,6 @@ def self.up
t.string :number
t.text :description
t.integer :author_id
- t.integer :parent_id
t.timestamp :committed_at
# TODO: think about it, that's probably not the best place to keep it
@@ -0,0 +1,12 @@
+class CreateCommitsParents < ActiveRecord::Migration
+ def self.up
+ create_table :commits_parents, :id => false do |t|
+ t.integer :commit_id
+ t.integer :parent_id
+ end
+ end
+
+ def self.down
+ drop_table :commits_parents
+ end
+end
View
@@ -1,4 +1,3 @@
-# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
@@ -11,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110612171733) do
+ActiveRecord::Schema.define(:version => 20120321184927) do
create_table "authors", :force => true do |t|
t.string "name"
@@ -24,7 +23,6 @@
t.string "number"
t.text "description"
t.integer "author_id"
- t.integer "parent_id"
t.datetime "committed_at"
t.text "preparation_log"
t.text "dev_structure"
@@ -34,6 +32,11 @@
t.boolean "skipped", :default => false
end
+ create_table "commits_parents", :id => false, :force => true do |t|
+ t.integer "commit_id"
+ t.integer "parent_id"
+ end
+
create_table "notifications", :force => true do |t|
t.string "name"
t.string "notification_type"
View
@@ -20,6 +20,18 @@ def checkout(commit)
got_commit_number commit.number
end
+ # Should return hash with data about commit with given number
+ # Recognized keys:
+ # :number - commit number
+ # :author_name
+ # :author_email
+ # :committed_at [Time]
+ # :description
+ # :parents - array with numbers of parent commits
+ def details(numbe)
+ raise "implement me"
+ end
+
def link_to_commit(number)
end
@@ -53,6 +65,15 @@ def got_commit_number(number)
)
commit.save!
+
+ if info[:parents]
+ info[:parents].each do |number|
+ if parent = @project.commits.find_by_number(number)
+ commit.parents << parent
+ end
+ end
+ end
+
end
unless pi_commit = @project_instance.commits.find_by_commit_id(commit.id)
View
@@ -20,7 +20,7 @@ def update
@g.fetch rescue nil # FIXME better handling
#@g.merge("origin/#{@project.vcs_branch_name}")
# IMPROVE simplified branch handling
- @g.log.between('HEAD',"origin/#{branch_name}").map(&:sha).each do |sha|
+ @g.log.between('HEAD',"origin/#{branch_name}").map(&:sha).reverse_each do |sha|
got_commit_number sha
end
end
@@ -38,7 +38,8 @@ def details(number)
:author_name => c.author.name,
:author_email => c.author.email,
:committed_at => c.date,
- :description => c.message
+ :description => c.message,
+ :parents => c.parents.map(&:sha)
}
end

0 comments on commit 2c9eaef

Please sign in to comment.