my $patches_dir = 'patches';
my $tmp_dir = "patches.$$";
+my $make_gen_cmd = 'make -f prepare-source.mak conf && ./config.status && make gen';
&Getopt::Long::Configure('bundling');
&usage if !&GetOptions(
die "The checkout is not clean:\n", $status;
}
+my $master_commit;
+open PIPE, '-|', "git log -1 --no-color $master_branch" or die $!;
+while (<PIPE>) {
+ if (/^commit (\S+)/) {
+ $master_commit = $1;
+ last;
+ }
+}
+close PIPE;
+die "Unable to determine commit hash for master branch: $master_branch\n" unless defined $master_commit;
+
my @extra_files;
open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
while (<IN>) {
if ($incl_generated_files) {
die "'$tmp_dir' must not exist in the current directory.\n" if -e $tmp_dir;
mkdir($tmp_dir, 0700) or die "Unable to mkdir($tmp_dir): $!\n";
- system "./config.status Makefile && make gen && rsync -a @extra_files $tmp_dir/master/" and exit 1;
+ system "$make_gen_cmd && rsync -a @extra_files $tmp_dir/master/" and exit 1;
}
our $last_touch = time;
my($patch) = @_;
my $parent = $parent{$patch};
+ my $based_on;
if (defined $parent) {
unless ($completed{$parent}++) {
update_patch($parent);
}
- $parent = "patch/$parent";
+ $based_on = $parent = "patch/$parent";
} else {
$parent = $master_branch;
+ $based_on = $master_commit;
}
print "======== $patch ========\n";
sleep 1 while $incl_generated_files && $last_touch >= time;
system "git checkout patch/$patch" and return 0;
- my $ok = system("git merge $parent") == 0;
+ my $ok = system("git merge $based_on") == 0;
if (!$ok || $launch_shell) {
- print qq|"git merge $parent" incomplete -- please fix.\n| if !$ok;
+ print qq|"git merge $based_on" incomplete -- please fix.\n| if !$ok;
$ENV{PS1} = "[$parent] patch/$patch: ";
while (1) {
if (system($ENV{SHELL}) != 0) {
}
open(OUT, '>', "$patches_dir/$patch.diff") or die $!;
- print OUT $description{$patch}, "\n";
+ print OUT $description{$patch}, "\nbased-on: $based_on\n";
if ($incl_generated_files) {
- system "./config.status Makefile && make gen && rsync -a @extra_files $tmp_dir/$patch/" and exit 1;
+ system "$make_gen_cmd && rsync -a @extra_files $tmp_dir/$patch/" and exit 1;
}
$last_touch = time;
- open(PIPE, '-|', 'git', 'diff', $parent) or die $!;
+ open(PIPE, '-|', 'git', 'diff', $based_on) or die $!;
DIFF: while (<PIPE>) {
while (m{^diff --git a/PATCH}) {
while (<PIPE>) {
sub usage
{
die <<EOT;
-Usage: patch-update [OPTIONS]
-
---gen[=DIR] Include generated files. Optional dest DIR overrides "patches".
---skip-check Skip the check that ensures starting with a clean branch.
+Usage: patch-update [OPTIONS] [patches/DIFF...]
+
+Options:
+-b, --branch=BRANCH The master branch to merge into the patch/* branches.
+ --gen[=DIR] Include generated files. Optional destination DIR
+ arg overrides the default of using the "patches" dir.
+ --skip-check Skip the check that ensures starting with a clean branch.
+-s, --shell Launch a shell for every patch/* branch updated, not
+ just when a conflict occurs.
+-h, --help Output this help message.
EOT
}