Commit a6886bab authored by Leigh B Stoller's avatar Leigh B Stoller

Merge branch 'master' of git-public.flux.utah.edu:/flux/git/emulab-devel

parents b63cb055 e25f7049
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2009 University of Utah and the Flux Group.
* Copyright (c) 2000-2010 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -19,9 +19,6 @@
#include <zlib.h>
#include <sys/types.h>
#include <sys/time.h>
#ifndef linux
#include <sys/disklabel.h>
#endif
#include "imagehdr.h"
#include "queue.h"
#ifndef NOTHREADS
......@@ -1632,12 +1629,12 @@ fixmbr(int slice, int dtype)
static struct blockreloc *reloctable;
static int numrelocs;
#ifndef linux
static void reloc_bsdlabel(struct disklabel *label, int reloctype);
#endif
static void reloc_lilo(void *addr, int reloctype, uint32_t size);
static void reloc_lilocksum(void *addr, uint32_t off, uint32_t size);
#include "ffs/disklabel.h" /* XXX doesn't belong here */
static void reloc_bsdlabel(struct disklabel *label, int reloctype);
static void
getrelocinfo(const blockhdr_t *hdr)
{
......@@ -1701,14 +1698,12 @@ applyrelocs(off_t offset, size_t size, void *buf)
switch (reloc->type) {
case RELOC_NONE:
break;
#ifndef linux
case RELOC_FBSDDISKLABEL:
case RELOC_OBSDDISKLABEL:
assert(reloc->size >= sizeof(struct disklabel));
reloc_bsdlabel((struct disklabel *)((char *)buf+coff),
reloc->type);
break;
#endif
case RELOC_LILOSADDR:
case RELOC_LILOMAPSECT:
reloc_lilo((char *)buf+coff, reloc->type,
......@@ -1734,7 +1729,6 @@ applyrelocs(off_t offset, size_t size, void *buf)
return nsize;
}
#ifndef linux
static void
reloc_bsdlabel(struct disklabel *label, int reloctype)
{
......@@ -1803,7 +1797,6 @@ reloc_bsdlabel(struct disklabel *label, int reloctype)
label->d_checksum = 0;
label->d_checksum = dkcksum(label);
}
#endif
#include "extfs/lilo.h"
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2003, 2005, 2007, 2008 University of Utah and the Flux Group.
# Copyright (c) 2003-2010 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -59,12 +59,12 @@ if (!TBAdmin($>)) {
die "Sorry, only admins can use this script\n";
}
my %opt = ();
GetOptions(\%opt, 'v');
my (@test_switches, @control_switches);
my $debug = 0;
if ($opt{v}) {
$debug = 1;
}
my %opt = ("v+" => \$debug,
"E=s" => \@test_switches,
"C=s" => \@control_switches);
GetOptions(%opt);
sub DEBUG {
if ($debug) {
......@@ -110,14 +110,27 @@ if ($ELABINELAB) {
&SNMP::initMib();
#
# Yeah, it's slow, but we want to use all the test switches so that we don't
# have to worry about missing something, and don't have to get the user to
# guess which switch they're using
# If explicit switches were listed, we use them as listed in the roles
# specified with no checking. The caller had better know what they are
# doing!
#
my @test_switches = map {[$_,"experimental"]} getTestSwitches();
if (!@test_switches) {
die "Error: No experimental net switches found in database - you need\n" .
"to add them before running this script\n";
if (@test_switches > 0) {
if ($test_switches[0] eq "none") {
@test_switches = ();
} else {
@test_switches = map {[$_,"experimental"]} @test_switches;
}
} else {
#
# Yeah, it's slow, but we want to use all the test switches so that we don't
# have to worry about missing something, and don't have to get the user to
# guess which switch they're using
#
@test_switches = map {[$_,"experimental"]} getTestSwitches();
if (!@test_switches) {
die "Error: No experimental net switches found in database - you need\n" .
"to add them before running this script\n";
}
}
#
......@@ -125,10 +138,18 @@ if (!@test_switches) {
#
my %trunks = getTrunkHash();
my @control_switches = map {[$_,"control"]} getControlSwitches();
if (!@control_switches) {
warn "Warning - No control switches found - you probably want to add them " .
"to the nodes table\n";
if (@control_switches > 0) {
if ($control_switches[0] eq "none") {
@control_switches = ();
} else {
@control_switches = map {[$_,"control"]} @control_switches;
}
} else {
@control_switches = map {[$_,"control"]} getControlSwitches();
if (!@control_switches) {
warn "Warning - No control switches found - you probably want to add them " .
"to the nodes table\n";
}
}
my @switches = (@test_switches, @control_switches);
......@@ -142,7 +163,7 @@ if ($debug) {
}
#
# Loop through each switch indvidually
# Loop through each switch individually
#
SWITCHLOOP:
foreach my $switchref (@switches) {
......
......@@ -147,6 +147,16 @@ my $separate_mail = get_config("separatemail",undef);
#
my $showcommit_extra = get_config("showcommitextra",undef);
#
# If set, check all commit objects to see if they exist in the repository
# at the specified path. If a commit object exists in this repository,
# do not include its log in the email message.
# Note: This should point at the .git directory - for a 'bare' repository,
# this is just the path the repository. For a 'reglar' repository, this is the
# .git/ directory *inside* the repositry.
#
my $exclude_repo = get_config("excluderepo",undef);
######################################################################
# Constants
######################################################################
......@@ -168,6 +178,7 @@ my $EMPTYREV = "0"x40;
my $CT_CREATE = "create";
my $CT_UPDATE = "update";
my $CT_DELETE = "delete";
my $CT_FORCED_UPDATE = "force-update";
#
# Tired of typing this and getting it wrong
......@@ -181,15 +192,19 @@ sub change_type($$);
sub rev_type($);
sub revparse($);
sub changed_files($$);
sub changed_files_single_revision($);
sub get_mail_addresses($@);
sub get_merge_base($$);
sub uniq(@);
sub flatten_arrayref($);
sub commit_mail($$$@);
sub commit_mail($\@$@);
sub get_commits($$$);
sub send_mail($$@);
sub short_refname($);
sub debug(@);
sub rev_string($$);
sub object_exists($$);
sub filter_out_objects_in_repo($@);
######################################################################
# Main Body
......@@ -306,9 +321,22 @@ foreach my $refline (@reflines) {
}
#
# Get a list of all of the files that changed
# Get all commits between these two revisions
# and all files that changed
#
my @changed_files = changed_files($oldrev,$newrev);
my @commits = get_commits($oldrev,$newrev,$refname);
debug("commits are: ", join(" ",@commits));
my @changed_files;
if (defined $exclude_repo || $ct eq $CT_FORCED_UPDATE) {
if (defined $exclude_repo) {
@commits = filter_out_objects_in_repo($exclude_repo, @commits);
next unless (@commits);
}
@changed_files = map { changed_files_single_revision($_) } @commits;
} else {
@changed_files = changed_files($oldrev,$newrev);
}
debug("Changed files: ", join(",",@changed_files));
#
......@@ -322,7 +350,7 @@ foreach my $refline (@reflines) {
#
if (@mailaddrs) {
print "Sending email notification to ", join(",",@mailaddrs), "\n";
commit_mail($oldrev,$newrev,$refname,@mailaddrs);
commit_mail($ct,@commits,$refname,@mailaddrs);
}
}
......@@ -348,7 +376,13 @@ sub change_type($$) {
} elsif ($newrev eq $EMPTYREV) {
return $CT_DELETE;
} else {
return $CT_UPDATE;
my $merge_base = get_merge_base($oldrev,$newrev);
my $oldrev = revparse($oldrev);
if ($merge_base eq $oldrev) {
return $CT_UPDATE;
} else {
return $CT_FORCED_UPDATE;
}
}
}
......@@ -379,7 +413,7 @@ sub revparse($) {
}
#
# Given two revisions, return an list of the files that were changed between
# Given two revisions, return a list of the files that were changed between
# them
#
sub changed_files($$) {
......@@ -392,6 +426,19 @@ sub changed_files($$) {
return @lines;
}
#
# Given one revision, return a list of the files that were changed between
# it and its parents
#
sub changed_files_single_revision($) {
my ($rev) = @_;
debug("running '$GIT diff-tree -r --name-only '$rev''");
my @lines = `$GIT diff-tree -r --name-only '$rev' $STDERRNULL`;
chomp @lines;
return @lines;
}
#
# Given a refname and a list of filenames, return the set of email addresses
# the report should be sent to
......@@ -529,20 +576,8 @@ sub flatten_arrayref($) {
#
# Send mail about a regular update commit
#
sub commit_mail($$$@) {
my ($oldrev,$newrev,$refname,@mailaddrs) = @_;
#
# What type of chage was this?
#
my $ct = change_type($oldrev,$newrev);
#
# Get all commits between these two revisions
#
my @revs = get_commits($oldrev,$newrev,$refname);
debug("commits are: ", join(" ",@revs));
sub commit_mail($\@$@) {
my ($ct,$commits,$refname,@mailaddrs) = @_;
#
# Construct the subject line. For now, we just say what repo (if defined)
......@@ -556,6 +591,8 @@ sub commit_mail($$$@) {
if ($ct eq $CT_UPDATE) {
$subject .= " updated";
} elsif ($ct eq $CT_FORCED_UPDATE) {
$subject .= " force-updated";
} elsif ($ct eq $CT_CREATE) {
$subject .= " created";
} elsif ($ct eq $CT_DELETE) {
......@@ -565,8 +602,12 @@ sub commit_mail($$$@) {
my $actionstring = "Branch " . short_refname($refname) .
" has been ${ct}d\n\n";
if ($ct eq $CT_FORCED_UPDATE) {
$actionstring .= "New and/or modified commits shown below\n\n";
}
my @fullbody;
foreach my $rev (@revs) {
foreach my $rev (@$commits) {
#
# Just use regular git show command, with purty +/- summary at the
# bottom (formatted to be narrow enough for email)
......@@ -609,14 +650,23 @@ sub get_commits($$$) {
#
# If this is an update, we can just ask git for the revisions between the
# two revisions we were given
#
if ($ct eq $CT_UPDATE) {
my $revstring = rev_string($oldrev,$newrev);
debug("running '$GIT rev-list --reverse --date-order '$revstring'");
my @revs = `$GIT rev-list --reverse --date-order '$revstring'`;
chomp @revs;
# two revisions we were given. We call git-cherry for this information
# so that we can identify if a particular commit already exists in the
# repository with a different commit hash (for the rebase case).
#
if ($ct eq $CT_UPDATE || $ct eq $CT_FORCED_UPDATE) {
debug("running '$GIT cherry '$oldrev' '$newrev'");
# Only return revs prefixed with a '+' since commits prefixed with a
# '-' are already in the repository with a different commit hash. We
# should have seen those already, so we don't want to see them here.
# Note that '+' commits may not be "new" per-se, but they are not the
# same as the existing commit with the same commit message due to
# rebasing.
my @revs;
for (`$GIT cherry '$oldrev' '$newrev'`) {
chomp;
unshift @revs, $1 if (/^\+\s+(.*)$/);
}
return @revs;
} elsif ($ct eq $CT_CREATE) {
......@@ -729,7 +779,7 @@ sub debug(@) {
#
sub get_config($$) {
my ($var,$default) = @_;
#
# Allow the user to override on command line
#
......@@ -772,3 +822,45 @@ sub rev_string($$) {
return undef;
}
}
#
# Returns the merge base (i.e., common ancestor) of
# the two supplied revisions.
#
sub get_merge_base($$)
{
my ($rev_a, $rev_b) = @_;
my $mb = `git merge-base '$rev_a' '$rev_b'`;
chomp $mb;
return $mb
}
#
# Returns 1 if the given object (identified by hash) exists in the given
# repository (identified by path); 0 if it does not .
#
sub object_exists($$) {
my ($obj, $repo) = @_;
#
# 'cat-file -e' is like 'test -e', and don't be fooled by the name, it
# works on non-files too
#
debug("running $GIT --git-dir='$repo' cat-file -e $obj");
my $rv = system "$GIT --git-dir='$repo' cat-file -e $obj";
if ($rv) {
return 0;
} else {
return 1;
}
}
#
# Return a list of all objects from the input list that do *not* exist in
# the given repo
#
sub filter_out_objects_in_repo($@) {
my $repo = shift @_;
return grep { !object_exists($_,$repo)} @_;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment