[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.2, Tue Jun 21 16:06:37 2005 UTC (12 years, 4 months ago) by nathans.longdrop.melbourne.sgi.com
Branch: MAIN
Changes since 1.1: +21 -9 lines

Tweak the p_mod2git script a bit.
Merge of master-melb:xfs-cmds:22930a 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).
# 
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 ((m/^xfsidbg.c/) || (m/^Makefile/) || (m/^xfs_dmapi.c/)) {
		next;
	} elsif (m,^linux-2.[4|6]/xfs_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;
$DESCRIPTION = wrap('[XFS] ', '', split(/\n/, $DESCRIPTION));

# 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";
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 ((m/^Index: xfsidbg.c/) || (m/^Index: Makefile/)) {
		$skip = 1;
	} elsif ((m/^Index: xfs_dmapi.c/)) {
		$skip = 1;
	} elsif (m,^Index: linux-2.[4|6]/xfs_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"`;

# TODO: need '--add' and/or '--remove' if files are being added and/or removed
my $path; my $prefix;
$prefix = '';
if ($TREEID eq 'xfs-kern') {
	$prefix = 'fs/xfs/';
} elsif ($TREEID eq 'dmapi') {
	$prefix = 'fs/dmapi/';
}
foreach my $f (@FILES) {
	chomp($path = $prefix . $f);
	print "git-update-cache $path\n";
	`git-update-cache $path`;
}
 
# Finally, run the git commit tool
my $tree; my $parent;
chomp($tree = `git-write-tree`);
chomp($parent = `cat .git/HEAD`);
print "git-commit-tree $tree -p $parent\n";
`git-commit-tree "$tree" -p "$parent" < "$CWD/changeset" > .git/HEAD`;