From 0a04c891c69cc5851b657208c958c68d1336b977 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 17 Feb 2010 07:23:09 -0800 Subject: [PATCH] use refs/builds instead of refs/heads add gnulib commit number to NEWS --- build-pspp | 47 +++++++++++---------- git-import-tar | 110 +++++++++++++++++++++++++++++-------------------- 2 files changed, 91 insertions(+), 66 deletions(-) diff --git a/build-pspp b/build-pspp index f151cc1f88..6c5a4b5eb9 100755 --- a/build-pspp +++ b/build-pspp @@ -112,17 +112,17 @@ if (@ARGV == 2) { # Fetch branch start_step ("Fetch $repo, branch $branch"); - run ("git fetch $repo +$branch:buildtmp/$$/pspp"); + run ("git fetch $repo +$branch:refs/builds/$build_number/pspp"); # Get revision number. - my $revision = `git rev-parse buildtmp/$$/pspp`; + my $revision = `git rev-parse refs/builds/$build_number/pspp`; chomp $revision; set_var ("pspp_commit", $revision); my $abbrev_commit = substr ($revision, 0, 6); # Extract source. - start_step ("Extract branch into $builddir/pspp$build_number"); - run ("git archive --format=tar --prefix=pspp$build_number/ buildtmp/$$/pspp | (cd $builddir && tar xf -)"); + start_step ("Extract branch into source directory"); + run ("git archive --format=tar --prefix=pspp$build_number/ refs/builds/$build_number/pspp | (cd $builddir && tar xf -)"); run ("git branch -D buildtmp/$$/pspp"); # Extract version number. @@ -176,6 +176,19 @@ if (@ARGV == 2) { rename ("$fullname.new", $fullname) or die "rename $fullname.new to $fullname failed: $!\n"; + # Get Gnulib commit number. + start_step ("Reading README.Git to find Gnulib commit number"); + my $gnulib_commit; + $fullname = "$builddir/pspp$build_number/README.Git"; + open (README_GIT, '<', $fullname) + or die "opening $fullname failed: $!\n"; + while () { + ($gnulib_commit) = /^\s+commit ([0-9a-fA-F]{8,})/ and last; + } + die "$fullname does not specify a Git commit number\n" + if !defined ($gnulib_commit); + set_var ("gnulib_commit", $gnulib_commit); + # Add note to beginning of NEWS (otherwise "make dist" fails). start_step ("Updating NEWS"); $fullname = "$builddir/pspp$build_number/NEWS"; @@ -190,8 +203,10 @@ if (@ARGV == 2) { print NEWFILE <) { - ($gnulib_commit) = /^\s+commit ([0-9a-fA-F]{8,})/ and last; - } - die "$fullname does not specify a Git commit number\n" - if !defined ($gnulib_commit); - set_var ("gnulib_commit", $gnulib_commit); - # If we don't already have that Gnulib commit, update Gnulib. - `git rev-parse $gnulib_commit`; + system ("git rev-parse --verify --quiet $gnulib_commit"); if ($? != 0) { start_step ("Updating Gnulib to obtain commit"); run ("git fetch gnulib"); } + run ("git update-ref refs/builds/$build_number/gnulib $gnulib_commit"); # Extract gnulib source. start_step ("Extract Gnulib source"); @@ -260,14 +263,14 @@ if ($build_binary) { my ($tarball_dir) = $sample_filename =~ m%^(?:[./])*([^/]+)/%; set_var ("dist_dir", $tarball_dir); - start_step ("Extracting $tarball into $builddir/$tarball_dir"); + start_step ("Extracting source tarball"); run ("zcat $tarball | (cd $builddir && tar xf -)"); start_step ("Extracting tar version"); my ($version) = `cd $builddir/$tarball_dir && ./configure --version | head -1` =~ /configure (\S+)$/; set_var ("dist_version", $version); - my ($binary_version) = "$version-$builder-build$build_number"; + my ($binary_version) = "$version-$build_host-build$build_number"; set_var ("binary_version", $binary_version); start_step ("Configuring"); diff --git a/git-import-tar b/git-import-tar index 5d92e4cd4c..30cd9fa3b1 100755 --- a/git-import-tar +++ b/git-import-tar @@ -5,22 +5,25 @@ use warnings; use Getopt::Long qw(:config bundling no_ignore_case); my $help = 0; -my $build_binary = 1; -my $batch = 0; -my $builddir; -my $build_number; -GetOptions ("h|help" => \$help); +my $message_file; +my $message; +GetOptions ("F=s" => \$message_file, + "m=s" => \$message, + "h|help" => \$help); usage () if $help; sub usage { print </dev/null 2>&1") != 0; +my $new_branch = system ("git rev-parse --verify $branch >/dev/null 2>&1") != 0; -open(MESSAGE, '<', $ARGV[0]) or die "$ARGV[0]: open: $!\n"; -my $message = join('', ); -close(MESSAGE); +if (defined ($message_file)) { + open (MESSAGE, '<', $message_file) + or die "$0: failed to open \"$message_file\": $!\n"; + $message .= join ('', ); + close (MESSAGE); +} elsif (!defined ($message)) { + $message = "Import of $tarball.\n"; +} + +if (! -e $tarball) { + die "$0: $tarball: not found\n"; +} elsif ($tarball =~ /gz$/) { + open (TARBALL, "-|", "zcat $tarball") + or die "$0: \"zcat $tarball\" failed to start: $!\n"; +} else { + open (TARBALL, '<', $tarball) + or die "$0: failed to open \"$tarball\": $!\n"; +} + +my $commit_user = `git config --get user.name`; +chomp $commit_user; +my $commit_email = `git config --get user.email`; +chomp $commit_email; +my $committer = "$commit_user <$commit_email>"; + +open (GFI, "|-", "git fast-import --date-format=raw --quiet") + or die "$0: \"git fast-import\" failed to start: $!\n"; my $mark = 1; our $offset = 0; @@ -48,7 +70,7 @@ my @commit; my @metadata; my @gitignore; for (;;) { - my (%member) = read_tar_header(); + my (%member) = read_tar_header (); last if !%member; next if $member{NAME} eq '.'; # Skip root directory. @@ -61,45 +83,47 @@ for (;;) { push(@commit, "M $gitmode :$mark $member{NAME}\n"); my $size = $member{SIZE}; - print "blob\n"; - print "mark :", $mark++, "\n"; - print "data $size\n"; + print GFI "blob\n"; + print GFI "mark :", $mark++, "\n"; + print GFI "data $size\n"; my $remaining = $size; while ($remaining > 0) { my $chunk = $remaining > 65536 ? 65536 : $remaining; - my $data = read_fully($chunk); - print $data; + my $data = read_fully ($chunk); + print GFI $data; $remaining -= $chunk; } read_fully(512 - $size % 512) if $size % 512; - print "\n"; + print GFI "\n"; } elsif ($type eq 'l') { push(@commit, "M 120000 :$mark $member{NAME}\n"); - print "blob\n"; - print "mark :", $mark++, "\n"; - print "data ", length($member{LINKNAME}), "\n"; - print $member{LINKNAME}, "\n"; + print GFI "blob\n"; + print GFI "mark :", $mark++, "\n"; + print GFI "data ", length($member{LINKNAME}), "\n"; + print GFI $member{LINKNAME}, "\n"; } elsif ($type eq 'd') { # We don't do anything about directories. In particular, # ignoring them is a bad idea because files added under them # will then also be ignored. } else { - print STDERR "$member{NAME}: Git cannot represent tar member of type '$type', ignoring\n" + print STDERR "$0: tar member $member{NAME} has type '$type' that Git cannot represent, ignoring\n" } } my $commit = $mark++; -print "commit $branch\n"; -print "mark :$commit\n"; -print "committer $ENV{GIT_COMMITTER_NAME} <$ENV{GIT_COMMITTER_EMAIL}> ", - time(), " +0000\n"; -print "data ", length($message), "\n"; -print $message, "\n"; -print "merge $branch^0\n" if !$new_branch; -print "deleteall\n"; -print $_ foreach @commit; -print "\n"; +print GFI "commit $branch\n"; +print GFI "mark :$commit\n"; +print GFI "committer $committer ", time(), " +0000\n"; +print GFI "data ", length($message), "\n"; +print GFI $message, "\n"; +print GFI "merge $branch^0\n" if !$new_branch; +print GFI "deleteall\n"; +print GFI $_ foreach @commit; +print GFI "\n"; + +close (TARBALL) or die "$0: \"zcat $tarball\" exited with status $?\n"; +close (GFI) or die "$0: \"git fast-import\" exited with status $?\n"; sub check_header { my ($header) = @_; @@ -125,7 +149,7 @@ sub read_fully { my $data = ''; while (length($data) < $nbytes) { my $chunk = $nbytes - length($data); - my $bytes_read = sysread(STDIN, $data, $chunk, length($data)); + my $bytes_read = sysread (TARBALL, $data, $chunk, length($data)); $offset += $bytes_read; fail("$tarball: read error: $!") if !defined($bytes_read); fail("$tarball: unexpected end of file") if !$bytes_read; @@ -200,7 +224,6 @@ sub read_tar_header { # Get other information. my ($mode) = oct(substr($header, 100, 8)); - my ($mtime) = oct(substr($header, 136, 12)); if ($type !~ /[-hlcbdp]/) { # Read and discard any data. @@ -216,7 +239,6 @@ sub read_tar_header { return (TYPE => $type, NAME => $name, MODE => $mode, - MTIME => $mtime, SIZE => $size, LINKNAME => $linkname, TYPE => $type); -- 2.30.2