[BACK]Return to p_mod2git CVS log [TXT][DIR] Up to [Development] / xfs-cmds / xfsmisc

File: [Development] / xfs-cmds / xfsmisc / Attic / p_mod2git (download)

Revision 1.6, Wed Jun 28 03:53:13 2006 UTC (11 years, 3 months ago) by nathans.longdrop.melbourne.sgi.com
Branch: MAIN
Changes since 1.5: +6 -20 lines

Update git merge scripts for more recent versions of git.
Merge of master-melb:xfs-cmds:26365a by kenmcd.

#!/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.
#
# TODO: incorporate use of GIT_AUTHOR_DATE
# TODO: use 'git remove' when files removed

use strict;
use Text::Wrap;
use File::Basename;
unshift @INC, "/home/$ENV{'USER'}/bin";
require 'developers.pl';

if ($#ARGV != 1) {
	print STDERR "Usage: p_mod2git </path/to/git> <modid>\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;

#
# 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;

my @FILES;
open FILELIST, "p_modinfo -b -m $MODID |" or die "modinfo for affected files";
while (<FILELIST>) {
	if (($KERNEL == 2.4) && (m/^linux-2.6/)) {
		next;
	} elsif (($KERNEL == 2.6) && (m/^linux-2.4/)) {
		next;
	} elsif (($KERNEL == 2.6) && (m,^quota/Makefile-linux-2.4,)) {
		next;
	} elsif (($KERNEL == 2.6) && (m/^xfs_refcache.[c|h]/)) {
		next;
	} elsif ((m/^xfsidbg.c/) || (m/^Makefile/)) {
		next;
	} elsif ((m,^dmapi/*,) || (m/^xfs_dmapi.c/)) {
		next;
	} elsif (m,^linux-2.[4|6]/xfs_ksyms.c, || m,^quota/xfs_qm_ksyms.c,) {
		next;
	}
	push @FILES, $_;
}
close FILELIST;

# 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/(\w+).*\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 = <MODINFO>;
$/ = "\n";
close MODINFO;
$Text::Wrap::columns = 75;

# 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);

$_ = $SIGN[0];
if (defined($_) && /^Signed-off-by: (.+) <(.+)>/) {
	$ENV{'GIT_AUTHOR_NAME'} = $1;
	$ENV{'GIT_AUTHOR_EMAIL'} = $2;
}

$DESCRIPTION = wrap('[XFS] ', '', @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; }
print CSET "Signed-off-by: $MODSIGN\n";
print CSET "Signed-off-by: $OWNSIGN\n" unless ($MODSIGN eq $OWNSIGN);
close CSET;

# Generate a -p1 patch from the mod, extracting unwanted pieces as we go
open PRDIFF, "p_rdiff -puM ${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-linux-2.4,)) {
		$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";

# Apply the patch - dryrun first, to check if OK
my $CWD = $ENV{'PWD'};
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";
	exit 1;
}
# If we got this far, looks good, so really apply it now
`patch -p1 -g1 < "$CWD/$SUMMARY"`;

print "git-commit -a -F $CWD/changeset\n";
`git-commit -a -F "$CWD/changeset"`;
`git-log --max-count=1 | awk '{ if (/commit/) {print $2} }' >> $CWD/commitset`;