Re: Towards CVS code-exchange and gateways
- From
Martin Langhoff <martin.langhoff@gmail.com>
- Date
- Oct 26, 2005, 03:35 UTC
- Message-ID
- <46a038f90510252035yb4167e1w2ee54d82896e5906@mail.gmail.com>
- In-Reply-To
- <46a038f90510251357l23886747s8024a4326ad4e392@mail.gmail.com>
Update here: Sven sent me a cool 4 line shell script that has the basics. Next thing I know, and I was dumped into a boring presentation -- so I turned it into a more complete Perl script. Still incomplete & extremely untested, but showing the basics.
Give me a couple more boring presentations and we'll be done ;-)
cheers,
martin --- #!/usr/bin/perl -w
use strict; use Getopt::Std;
unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR}){
die "GIT_DIR is not defined or is unreadable";
}our ($opt_h, $opt_p);
getopt('hp');$opt_h && usage();
die "Need at least one commit identifier!" unless @ARGV;
# resolve target commit
my $commit;
$commit = pop @ARGV;
$commit = `git-rev-parse --verify "$commit"^0"`;
chomp $commit;
if ($?) {
die "The commit reference did not resolve!";
}# resolve what parent we want
my $parent;
if (@ARGV) {
$parent = pop @ARGV;
$parent = `git-rev-parse --verify "$parent"^0"`;
chomp $parent;
if ($?) {
die "The parent reference did not resolve!";
}
}# parents from the commit itself my @parents = `git-cat-file commmit $commit | grep -E '^parent \\w{40}\$' | sed -e 's/^parent //'`; @parents = map { chomp } @parents;
if ($parent) {
# double check that it's a valid parent
foreach my $p (@parents) {
my $found;
if ($p eq $parent) {
$found = 1;
last;
}; # found it
die "Did not find $parent in the parents for this commit!";
}
} else { # we don't have a parent from the cmdline...
if (@parents == 1) { # it's safe to get it from the commit
$parent = $parents[0];
} else { # or perhaps not!
die "This commit has more than one parent -- please name the parent
you want to use explicitly";
}
}# grab the commit message `git-cat-file commit $commit | sed -e '1,/^$/d' > .msg`; $? && die "Error extraction the commit message";
my @files = `git-diff-tree -r $parent $commit | cut -f 2`; $? && die "Error in git-diff-tree"; @files = map { chomp } @files;
# check that the files are clean and up to date according to cvs
my $dirty;
foreach my $f (@files) {
# TODO:we need to handle removed in cvs and/or new (from git)
my $status = `cvs status $f`; unless ($status =~ m/Up to date/) {
$dirty = 1;
warn "File $f not up to date!\n";
}
}
if ($dirty) {
die "Exiting: your CVS tree is not clean for this merge.";
}### ### NOTE: if you are planning to die() past this point ### you MUST call cleanupcvs(@files) before die() ###
## apply changes to binary files
my @bfiles = `git-diff-tree -p $parent $commit | grep '^Binary'`;
@bfiles = map { chomp } @bfiles;
foreach my $f (@bfiles) {
# check that the file in cvs matches the "old" file# replace with the new file
}
## apply non-binary changes ## (git-diff-tree -p $1 | patch -p1) && cvs commit -F .msg
sub usage {
print STDERR <<END;
Usage: GIT_DIR=/path/to/.gi ${\basename $0} # fetch/update GIT from CVS
[-h] [-p] [ parent ] commit
END
exit(1);
}# ensure cvs is clean before we die
sub cleanupcvs {
my @files = @_;
foreach my $f (@files) {
`cvs -q update -C "$f"`;
if ($?) {
warn "Warning! Failed to cleanup state of $f\n";
}
}
}