[Bps-public-commit] smokingit branch, master, updated. 747450cf761bea7be7d971a630b66937ccd815ab

Alex Vandiver alexmv at bestpractical.com
Fri Jul 22 21:10:53 EDT 2011


The branch, master has been updated
       via  747450cf761bea7be7d971a630b66937ccd815ab (commit)
       via  c54f5c3bfbb4184a2a82a1605d52232d2dfd5e69 (commit)
       via  51eff893f466e39f883e036a47950ea6f6f056f9 (commit)
       via  07a7bdf75cac43a105b036039c718f31d6402308 (commit)
       via  1f735b9493b855091bfc7af7df42c0553dfaddf6 (commit)
       via  ac34e465f2ab907f092f29fd3cdf7a6c66795ff8 (commit)
      from  be1b208dc46ba93e960b35658cc21bb3437773ae (commit)

Summary of changes:
 bin/local_updates                    |    8 ++----
 lib/Smokingit/Action/UpdateBranch.pm |   21 -----------------
 lib/Smokingit/Model/Branch.pm        |   42 ++++++++++++++++++++++++++++++++-
 lib/Smokingit/Model/Project.pm       |   20 +++++++++++++--
 4 files changed, 60 insertions(+), 31 deletions(-)

- Log -----------------------------------------------------------------
commit ac34e465f2ab907f092f29fd3cdf7a6c66795ff8
Author: Alex Vandiver <alex at chmrr.net>
Date:   Fri Jul 22 21:00:18 2011 -0400

    Refactor trunk-guessing into the model

diff --git a/lib/Smokingit/Action/UpdateBranch.pm b/lib/Smokingit/Action/UpdateBranch.pm
index 346a4fe..fc20d77 100644
--- a/lib/Smokingit/Action/UpdateBranch.pm
+++ b/lib/Smokingit/Action/UpdateBranch.pm
@@ -37,25 +37,7 @@ sub arguments {
     $args->{review_by}{autocompleter} = $self->autocompleter("review_by");
 
     if ($self->record->status eq "ignore" and not $self->record->to_merge_into->id) {
-        my @trunks;
-        while (my $b = $branches->next) {
-            push @trunks, [$b->id, $b->current_commit->sha, $b->name];
-        }
-        local $ENV{GIT_DIR} = $self->record->project->repository_path;
-        my $topic = $self->record->current_commit->sha;
-        my @revlist = map {chomp; $_} `git rev-list $topic @{[map {"^".$_->[1]} @trunks]}`;
-        my $branchpoint;
-        if (@revlist) {
-            $branchpoint = `git rev-parse $revlist[-1]~`;
-            chomp $branchpoint;
-        } else {
-            $branchpoint = $topic;
-        }
-        for my $t (@trunks) {
-            next if `git rev-list --max-count=1 $branchpoint ^$t->[1]` =~ /\S/;
-            $args->{to_merge_into}{default_value} = $t->[0];
-            last;
-        }
+        $args->{to_merge_into}{default_value} = $self->record->guess_merge_into;
     }
     return $self->{__cached_arguments} = $args;
 }
diff --git a/lib/Smokingit/Model/Branch.pm b/lib/Smokingit/Model/Branch.pm
index b87adf0..9433fb8 100644
--- a/lib/Smokingit/Model/Branch.pm
+++ b/lib/Smokingit/Model/Branch.pm
@@ -78,6 +78,37 @@ sub create {
     return ($ok, $msg);
 }
 
+sub guess_merge_into {
+    my $self = shift;
+
+    my @trunks;
+    my $branches = $self->project->trunk_or_relengs;
+    while (my $b = $branches->next) {
+        push @trunks, [$b->id, $b->current_commit->sha, $b->name];
+    }
+
+    # Find the commit before the first non-trunk commit, which is the
+    # commit this branch was branched off of
+    local $ENV{GIT_DIR} = $self->project->repository_path;
+    my $topic = $self->current_commit->sha;
+    my @revlist = map {chomp; $_} `git rev-list $topic @{[map {"^".$_->[1]} @trunks]}`;
+    my $branchpoint;
+    if (@revlist) {
+        $branchpoint = `git rev-parse $revlist[-1]~`;
+        chomp $branchpoint;
+    } else {
+        $branchpoint = $topic;
+    }
+
+    for my $t (@trunks) {
+        # Find the first trunk which contains all the branch point
+        # (i.e. branchpoint - trunk is the empty set)
+        next if `git rev-list --max-count=1 $branchpoint ^$t->[1]` =~ /\S/;
+        return $t->[0];
+    }
+    return undef;
+}
+
 sub branches {
     my $self = shift;
     my $branches = Smokingit::Model::BranchCollection->new;

commit 1f735b9493b855091bfc7af7df42c0553dfaddf6
Author: Alex Vandiver <alex at chmrr.net>
Date:   Fri Jul 22 21:03:51 2011 -0400

    Move master to being the first branch created

diff --git a/lib/Smokingit/Model/Project.pm b/lib/Smokingit/Model/Project.pm
index c84ecbc..9f6d8c6 100644
--- a/lib/Smokingit/Model/Project.pm
+++ b/lib/Smokingit/Model/Project.pm
@@ -153,7 +153,9 @@ sub sync_branches {
         $branch->set_current_commit_id($self->sha($new_ref)->id);
     }
 
-    for my $name (keys %branches) {
+    my $has_master = delete $branches{master};
+
+    for my $name (($has_master ? ("master") : ()), sort keys %branches) {
         warn "New branch $name\n";
         my $trunk = ($name eq "master");
         my $sha = $self->repository->ref_sha1("refs/heads/$name");

commit 07a7bdf75cac43a105b036039c718f31d6402308
Author: Alex Vandiver <alex at chmrr.net>
Date:   Fri Jul 22 21:02:18 2011 -0400

    Move trunk-guessing to branch creation time

diff --git a/lib/Smokingit/Action/UpdateBranch.pm b/lib/Smokingit/Action/UpdateBranch.pm
index fc20d77..6dd6622 100644
--- a/lib/Smokingit/Action/UpdateBranch.pm
+++ b/lib/Smokingit/Action/UpdateBranch.pm
@@ -36,9 +36,6 @@ sub arguments {
     $args->{review_by}{ajax_autocompletes} = 1;
     $args->{review_by}{autocompleter} = $self->autocompleter("review_by");
 
-    if ($self->record->status eq "ignore" and not $self->record->to_merge_into->id) {
-        $args->{to_merge_into}{default_value} = $self->record->guess_merge_into;
-    }
     return $self->{__cached_arguments} = $args;
 }
 
diff --git a/lib/Smokingit/Model/Branch.pm b/lib/Smokingit/Model/Branch.pm
index 9433fb8..a078d82 100644
--- a/lib/Smokingit/Model/Branch.pm
+++ b/lib/Smokingit/Model/Branch.pm
@@ -71,6 +71,10 @@ sub create {
     my ($ok, $msg) = $self->SUPER::create(%args);
     return ($ok, $msg) unless $ok;
 
+    $self->set_to_merge_into( $self->guess_merge_into )
+        unless $self->project->branches->count == 1
+            or $self->to_merge_into->id;
+
     Smokingit->gearman->dispatch_background(
         plan_tests => $self->project->name,
     );

commit 51eff893f466e39f883e036a47950ea6f6f056f9
Author: Alex Vandiver <alex at chmrr.net>
Date:   Fri Jul 22 21:06:42 2011 -0400

    Skip additional schedule_tests per branch during project creation

diff --git a/lib/Smokingit/Model/Branch.pm b/lib/Smokingit/Model/Branch.pm
index a078d82..bce4adc 100644
--- a/lib/Smokingit/Model/Branch.pm
+++ b/lib/Smokingit/Model/Branch.pm
@@ -55,10 +55,13 @@ use Smokingit::Record schema {
 sub create {
     my $self = shift;
     my %args = (
-        sha => undef,
+        plan_tests => 1,
+        sha        => undef,
         @_,
     );
 
+    my $plan_tests = delete $args{plan_tests};
+
     # Ensure that we have a tip commit
     my $project = Smokingit::Model::Project->new;
     $project->load( $args{project_id} );
@@ -77,7 +80,7 @@ sub create {
 
     Smokingit->gearman->dispatch_background(
         plan_tests => $self->project->name,
-    );
+    ) if $plan_tests;
 
     return ($ok, $msg);
 }
diff --git a/lib/Smokingit/Model/Project.pm b/lib/Smokingit/Model/Project.pm
index 9f6d8c6..80402cb 100644
--- a/lib/Smokingit/Model/Project.pm
+++ b/lib/Smokingit/Model/Project.pm
@@ -167,6 +167,7 @@ sub sync_branches {
             status        => $trunk ? "master" : "ignore",
             long_status   => "",
             to_merge_into => undef,
+            plan_tests    => 0,
         );
         warn "Create failed: $msg" unless $ok;
     }

commit c54f5c3bfbb4184a2a82a1605d52232d2dfd5e69
Author: Alex Vandiver <alex at chmrr.net>
Date:   Fri Jul 22 21:07:58 2011 -0400

    After initial project creation, test every new branch by default

diff --git a/lib/Smokingit/Model/Project.pm b/lib/Smokingit/Model/Project.pm
index 80402cb..bb20f08 100644
--- a/lib/Smokingit/Model/Project.pm
+++ b/lib/Smokingit/Model/Project.pm
@@ -153,6 +153,7 @@ sub sync_branches {
         $branch->set_current_commit_id($self->sha($new_ref)->id);
     }
 
+    my $test_new = $branches->count ? 1 : 0;
     my $has_master = delete $branches{master};
 
     for my $name (($has_master ? ("master") : ()), sort keys %branches) {
@@ -160,11 +161,14 @@ sub sync_branches {
         my $trunk = ($name eq "master");
         my $sha = $self->repository->ref_sha1("refs/heads/$name");
         my $branch = Smokingit::Model::Branch->new;
+        my $status = $trunk    ? "master"  :
+                     $test_new ? "hacking" :
+                                 "ignore";
         my ($ok, $msg) = $branch->create(
             project_id    => $self->id,
             name          => $name,
             sha           => $sha,
-            status        => $trunk ? "master" : "ignore",
+            status        => $status,
             long_status   => "",
             to_merge_into => undef,
             plan_tests    => 0,

commit 747450cf761bea7be7d971a630b66937ccd815ab
Author: Alex Vandiver <alex at chmrr.net>
Date:   Fri Jul 22 21:09:04 2011 -0400

    Make sync_branches return a list of actions taken, and sync_project return a descriptive string

diff --git a/bin/local_updates b/bin/local_updates
index 5b3e234..011fe7d 100755
--- a/bin/local_updates
+++ b/bin/local_updates
@@ -104,10 +104,8 @@ $worker->register_function(
 
         my $project = Smokingit::Model::Project->new;
         $project->load_by_cols( name => $project_name );
-        unless ($project->id) {
-            warn "No such project: $project_name\n";
-            return 0;
-        }
+        return "No such project: $project_name\n"
+            unless $project->id;
 
         # Update or clone, as need be
         if (-d $project->repository_path) {
@@ -125,7 +123,7 @@ $worker->register_function(
         my $tests = $project->sync_branches;
         Jifty->handle->commit;
 
-        return $tests;
+        return @{$tests} ? join("\n",@{$tests},"") : "No changes\n";
     },
 );
 $worker->register_function(
diff --git a/lib/Smokingit/Model/Project.pm b/lib/Smokingit/Model/Project.pm
index bb20f08..323e030 100644
--- a/lib/Smokingit/Model/Project.pm
+++ b/lib/Smokingit/Model/Project.pm
@@ -136,10 +136,12 @@ sub sync_branches {
         $branches{$_}++;
     }
 
+    my @messages;
     my $branches = $self->branches;
     while (my $branch = $branches->next) {
         if (not $branches{$branch->name}) {
             $branch->delete;
+            push @messages, $branch->name." deleted";
             next;
         }
         delete $branches{$branch->name};
@@ -151,6 +153,7 @@ sub sync_branches {
         my @revs = map {chomp; $_} `git rev-list ^$old_ref $new_ref`;
         $self->sha( $_ ) for reverse @revs;
         $branch->set_current_commit_id($self->sha($new_ref)->id);
+        push @messages, $branch->name." updated with @{[scalar @revs]} commits";
     }
 
     my $test_new = $branches->count ? 1 : 0;
@@ -174,8 +177,12 @@ sub sync_branches {
             plan_tests    => 0,
         );
         warn "Create failed: $msg" unless $ok;
+        push @messages, $branch->name." created, status $status";
     }
-    return $self->schedule_tests;
+
+    my $tests = $self->schedule_tests;
+    push @messages, "$tests commits scheduled for testing" if $tests;
+    return [map {$self->name.": $_"} @messages];
 }
 
 sub schedule_tests {

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list