File: [Development] / xfs-cmds / xfsmisc / Attic / p_mod2git (download)
Revision 1.13, Mon Nov 13 05:06:05 2006 UTC (10 years, 11 months ago) by tes.longdrop.melbourne.sgi.com
Branch: MAIN
Changes since 1.12: +26 -2
lines
Update to handle multiple reviewers and add some more developers.
Merge of master-melb:xfs-cmds:27416a by kenmcd.
Allow multiple reviewers.
Next checkin todo: space/comma delimited users.
This checkin only handled multi line ones.
|
#!/usr/bin/perl -w
# Convert from a ptools XFS/DMAPI mod to a git changeset.
#
# Adds in two "Signed-off-by:" lines now also, one for the person
# who commits the mod, and one for the person running this script
# (unless they're the same).
#
# If mod description has any #-prefixed lines, those are now used
# to keep Signed-off-by: (Acked-by:, ...) lines around (ie. so we
# better keep track of the code flow from non-SGI folks. Used to
# be done by hand.
#
use strict;
use Text::Wrap;
use File::Basename;
unshift @INC, "/home/$ENV{'USER'}/bin";
require 'developers.pl';
if ($#ARGV != 2) {
print STDERR "Usage: p_mod2git </path/to/git> <modid> <commitset>\n";
exit 1;
}
if (!defined($ENV{'WORKAREA'})) {
print STDERR "Error: WORKAREA must be set to workarea for <modid>\n";
exit 1;
}
my $GIT_TREE = $ARGV[0];
my $MODID = $ARGV[1];
my $TREEID = $ARGV[1];
my $MODNUMBER = $ARGV[1];
$MODNUMBER =~ s/(\S+):(\S+):(\S+)/$3/g;
my $COMMITSET = $ARGV[2];
my $CWD = $ENV{'PWD'};
#
# Find kernel version (if its a kernel), then create patch file name by
# plucking a prefix from modid - X:dmapi:Y, X:xfs-kern:Y or xfs-cmds:X:Y
# then appending the mod number and the one-line-summary.
#
my $KERNEL = 0;
if ( -d "$GIT_TREE/fs/xfs/linux-2.4" ) {
$KERNEL = 2.4;
} elsif ( -d "$GIT_TREE/fs/xfs/linux-2.6" ) {
$KERNEL = 2.6;
}
if ($KERNEL == 0) { # xfs-cmds
$TREEID =~ s/(\S+):(\S+):(\S+)/$1/g;
print "Target: non-kernel tree\n";
} else { # xfs-kern/dmapi
$TREEID =~ s/(\S+):(\S+):(\S+)/$2/g;
print "Target: $KERNEL kernel tree\n";
}
my $SUMMARY = 'git-' . $TREEID . '-' . $MODNUMBER;
# Create patch file and input stream from p_modinfo
open PATCH, ">$SUMMARY" or die "cannot open summary patch file\n";
open MODINFO, "p_modinfo -b -H Author,PV,Description $MODID |" or die "modinfo";
my $AUTHOR = <MODINFO>;
$AUTHOR =~ s/([-.0-9a-z_A-Z]+).*\n/$1/;
my $PVNUMBER = <MODINFO>;
$PVNUMBER =~ s/(\d+).*\n/$1/;
# Set some environment variables for git
my $MODSIGN = &developers::developer($AUTHOR);
my $OWNSIGN = &developers::developer($ENV{'USER'});
$ENV{'GIT_AUTHOR_NAME'} = &developers::developer_name($AUTHOR);
$ENV{'GIT_AUTHOR_EMAIL'} = &developers::developer_email($AUTHOR);
$ENV{'GIT_COMMITTER_NAME'} = &developers::developer_name($ENV{'USER'});
$ENV{'GIT_COMMITTER_EMAIL'} = &developers::developer_email($ENV{'USER'});
# Create the changeset description
undef $/;
my $DESCRIPTION = '[XFS] ' . <MODINFO>;
$/ = "\n";
close MODINFO;
# Could have multiple reviewers
my $REV;
my $REVSIGN;
my %REVIEWERS;
open MODINFO, "p_modinfo -b -H Inspected $MODID |" or die "modinfo";
while ($REV = <MODINFO>) {
$REV =~ s/([-.0-9a-z_A-Z]+).*\n/$1/;
$REVSIGN = &developers::developer($REV);
$REVIEWERS{$REV} = $REVSIGN;
}
close MODINFO;
# extract existing signed-off-by clauses
my @desc = split(/\n/, $DESCRIPTION);
my @DESC = grep(!/^Signed-off-by/, @desc);
my @SIGN = grep(/^(Signed-off|Acked)-by/, @desc);
# if have signed-off clause in description,
# then make it the author
$_ = $SIGN[0];
if (defined($_) && /^Signed-off-by: (.+) <(.+)>/) {
$ENV{'GIT_AUTHOR_NAME'} = $1;
$ENV{'GIT_AUTHOR_EMAIL'} = $2;
}
$Text::Wrap::columns = 75;
$DESCRIPTION = Text::Wrap::fill('', '', @DESC);
# Create the changeset file contents
open CSET, ">changeset" or die "cannot open changeset file";
print CSET "$DESCRIPTION\n";
print CSET "\n";
print CSET "SGI-PV: $PVNUMBER\n";
print CSET "SGI-Modid: $MODID\n";
print CSET "\n";
foreach (@SIGN) { s/^#//; s/$/\n/; print CSET; }
# the author
print CSET "Signed-off-by: $MODSIGN\n";
# the reviewers
foreach $REV (sort(keys %REVIEWERS)) {
$REVSIGN = $REVIEWERS{$REV};
print CSET "Signed-off-by: $REVSIGN\n" unless ($REVSIGN eq $MODSIGN);
}
# our own = $USER
print CSET "Signed-off-by: $OWNSIGN\n" unless (($OWNSIGN eq $MODSIGN) || ($REVIEWERS{$ENV{'USER'}}));
close CSET;
# Generate a -p1 patch from the mod, extracting unwanted pieces as we go
open PRDIFF, "p_rdiff -PpuM ${MODID} |" or die "rdiff";
$/ = "\n===========================================================================\n";
my $skip = 0;
while (<PRDIFF>) {
if ($skip == 1) {
$skip = 0;
} elsif (($KERNEL == 2.4) &&
((m/^(Index: |)linux-2.6/) ||
(m/^(Index: |)Makefile-linux-2.6/))) {
$skip = 1;
} elsif (($KERNEL == 2.6) &&
((m/^(Index: |)linux-2.4/) ||
(m/^(Index: |)Makefile-linux-2.4/))) {
$skip = 1;
} elsif (($KERNEL == 2.6) &&
(m,^(Index: |)quota/Makefile.*,)) {
$skip = 1;
} elsif (($KERNEL == 2.6) &&
(m/^(Index: |)xfs_refcache.[c|h]/)) {
$skip = 1;
} elsif ((m/^(Index: |)xfsidbg.c/) || (m/^(Index: |)Makefile/)) {
$skip = 1;
} elsif ((m,^(Index: |)dmapi/,) || (m/^(Index: |)xfs_dmapi.c/)) {
$skip = 1;
} elsif (m,^(Index: |)linux-2.[4|6]/xfs_ksyms.c,) {
$skip = 1;
} elsif (m,^(Index: |)quota/xfs_qm_ksyms.c,) {
$skip = 1;
} elsif ($TREEID eq 'dmapi') {
s,^\-\-\- a/(\S+),--- a/fs/dmapi/$1,m;
s,^\+\+\+ b/(\S+),+++ b/fs/dmapi/$1,m;
print PATCH;
} elsif ($TREEID eq 'xfs-kern') {
s,^\-\-\- a/(\S+),--- a/fs/xfs/$1,m;
s,^\+\+\+ b/(\S+),+++ b/fs/xfs/$1,m;
print PATCH;
} else {
print PATCH;
}
}
$/ = "\n";
close PRDIFF;
# The patch is now complete
close PATCH;
print "Created patch: $SUMMARY\n";
`/usr/bin/diffstat "$SUMMARY"`;
# Apply the patch - dryrun first, to check if OK
chdir $GIT_TREE;
`patch --dry-run -p1 -g1 < "$CWD/$SUMMARY"`;
if ($? != 0) {
print STDERR "WARNING: patch won't apply cleanly, needs manual merge\n";
print STDERR "setenv GIT_AUTHOR_NAME \"$ENV{'GIT_AUTHOR_NAME'}\"\n";
print STDERR "setenv GIT_AUTHOR_EMAIL $ENV{'GIT_AUTHOR_EMAIL'}\n";
print STDERR "setenv GIT_COMMITTER_NAME \"$ENV{'GIT_COMMITTER_NAME'}\"\n";
print STDERR "setenv GIT_COMMITTER_EMAIL $ENV{'GIT_COMMITTER_EMAIL'}\n";
print STDERR "patch -p1 -g1 < $CWD/$SUMMARY\n";
print STDERR "git-commit -a -F $CWD/changeset\n";
print STDERR "git-log --max-count=1 | awk '{ if (/commit/) { print \$2 } }' >> $COMMITSET\n";
exit 1;
}
# If we got this far, looks good, so really apply it now
`patch -p1 -g1 < "$CWD/$SUMMARY"`;
# handle the new files
my $fetal_files = "";
my $file = "";
my @words;
open PATCH, "<$CWD/$SUMMARY" or die "reading patch";
while (<PATCH>) {
if (m#^\+\+\+ b/#) {
@words = split;
$file = $words[1];
$file =~ s#^b/##;
}
elsif (m#^@@ -0,0 #) {
if (!$fetal_files) {
$fetal_files = $file;
}
else {
$fetal_files = $fetal_files . " " . $file;
}
}
}
close PATCH;
if ($fetal_files) {
print "git add $fetal_files\n";
`git add $fetal_files`;
}
print "git-commit -a -F $CWD/changeset\n";
`git-commit -a -F "$CWD/changeset"`;
`git-log --max-count=1 | awk '{ if (/commit/) { print \$2 } }' >> "$COMMITSET"`;