# 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.
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 (<README_GIT>) {
+ ($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";
print NEWFILE <<EOF;
Changes from $repo_version to $version:
- * Built automatically from commit $revision
- in branch $branch by builder $builder
+ * Built from PSPP commit $revision
+ in branch $branch on host $build_host.
+
+ * Built from Gnulib commit $gnulib_commit.
EOF
}
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 (<README_GIT>) {
- ($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");
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");
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 <<EOF;
-$0, for importing a tarball as a Git branch or tag
-usage: $0 [OPTIONS] TARBALL REFNAME
-where TARBALL is the name of a tarball
- and REF is a Git tag (refs/tags/...) or branch (refs/heads/...).
+$0, for importing a tarball as a Git branch
+usage: $0 [OPTIONS] TARBALL BRANCH
+where TARBALL is the name of a tarball and BRANCH is a branch to create or
+update. (If you want it to be a normal user-visible Git branch then BRANCH
+should start with "refs/heads".)
Options:
+ -F FILE Read commit message from FILE.
+ -m MESSAGE Use MESSAGE as commit message.
--help Print this usage message and exit
EOF
exit(0);
die "$0: exactly two nonoption arguments are required (use --help for help)\n"
if @ARGV != 2;
-our $tarball = $ARGV[0];
-our $refname = $ARGV[1];
-die "$0: \"$refname\" does not start with refs/tags or refs/heads\n"
- if $refname !~ /^refs/(tags|heads)/;
+our ($tarball, $branch) = @ARGV;
-my $branch = $ENV{'branch'};
-$branch = "refs/heads/$branch" if $branch !~ m(/);
-my $new_branch = system("git rev-parse --verify $branch >/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('', <MESSAGE>);
-close(MESSAGE);
+if (defined ($message_file)) {
+ open (MESSAGE, '<', $message_file)
+ or die "$0: failed to open \"$message_file\": $!\n";
+ $message .= join ('', <MESSAGE>);
+ 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;
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.
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) = @_;
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;
# 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.
return (TYPE => $type,
NAME => $name,
MODE => $mode,
- MTIME => $mtime,
SIZE => $size,
LINKNAME => $linkname,
TYPE => $type);