diff options
author | Wayne Davison <wayned@samba.org> | 2008-03-24 19:30:51 -0700 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2008-03-24 20:30:09 -0700 |
commit | c202b4fa967c3cf98a9504a9ac98d5b931819a5e (patch) | |
tree | 5aa35d4e1635462fa23706ac1316e43ec908aab9 /support | |
parent | 1df02d13d304ea5a35ecc81b26a5419904aacd95 (diff) | |
download | rsync-c202b4fa967c3cf98a9504a9ac98d5b931819a5e.tar.gz rsync-c202b4fa967c3cf98a9504a9ac98d5b931819a5e.tar.bz2 rsync-c202b4fa967c3cf98a9504a9ac98d5b931819a5e.zip |
Some improvements for support/patch-update:
- Added a --shell option which starts a sub-shell on each patch branch.
- Don't allow the user to exit a sub-shell if the branch is not clean.
- If the sub-shell exited with a non-zero exit status, prompt to see if
the user wanted to abort rather than assuming that.
- Wait to start the new patch-file output until after the shell runs.
- Always return to the starting branch on exit.
Diffstat (limited to 'support')
-rwxr-xr-x | support/patch-update | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/support/patch-update b/support/patch-update index f6eb47fe..4892d668 100755 --- a/support/patch-update +++ b/support/patch-update @@ -14,6 +14,7 @@ my $tmp_dir = "patches.$$"; &Getopt::Long::Configure('bundling'); &usage if !&GetOptions( 'skip-check' => \( my $skip_branch_check ), + 'shell|s' => \( my $launch_shell ), 'gen:s' => \( my $incl_generated_files ), 'help|h' => \( my $help_opt ), ); @@ -27,13 +28,10 @@ if (defined $incl_generated_files) { die "No '$patches_dir' directory was found.\n" unless -d $patches_dir; die "No '.git' directory present in the current dir.\n" unless -d '.git'; -open(IN, '-|', 'git status') or die $!; -my $status = join('', <IN>); -close IN; -unless ($skip_branch_check) { - die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/; +my($status, $is_clean, $starting_branch) = &check_git_status; +if (!$skip_branch_check && !$is_clean) { + die "The checkout is not clean:\n", $status; } -my($starting_branch) = $status =~ /^# On branch (.+)\n/; my @extra_files; open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n"; @@ -101,7 +99,7 @@ if (@ARGV) { my %completed; foreach my $patch (@patches) { next if $completed{$patch}++; - update_patch($patch); + last unless update_patch($patch); } if ($incl_generated_files) { @@ -132,22 +130,33 @@ sub update_patch sleep 1 if $incl_generated_files && $last_touch == time; if ($local_patch{$patch}) { - system "git checkout patch/$patch" and exit 1; + system "git checkout patch/$patch" and return 0; } else { - system "git checkout --track -b patch/$patch origin/patch/$patch" and exit 1; + system "git checkout --track -b patch/$patch origin/patch/$patch" and return 0; } - open(OUT, '>', "$patches_dir/$patch.diff") or die $!; - print OUT $description{$patch}, "\n"; - - if (system("git merge $parent") != 0) { - print qq|"git merge $parent" incomplete -- please fix.\n|; + my $ok = system("git merge $parent") == 0; + if (!$ok || $launch_shell) { + print qq|"git merge $parent" incomplete -- please fix.\n| if !$ok; $ENV{PS1} = "[$parent] patch/$patch: "; - system $ENV{SHELL} and exit 1; + while (1) { + if (system($ENV{SHELL}) != 0) { + print "Abort? [n/y] "; + $_ = <STDIN>; + next unless /^y/i; + return 0; + } + ($status, $is_clean) = &check_git_status; + last if $is_clean; + print $status; + } } + open(OUT, '>', "$patches_dir/$patch.diff") or die $!; + print OUT $description{$patch}, "\n"; + if ($incl_generated_files) { - system "./config.status Makefile && make gen && rsync -a @extra_files $tmp_dir/$patch/" and exit 1; + system "./config.status Makefile && make gen && rsync -a @extra_files $tmp_dir/$patch/"; } $last_touch = time; @@ -177,10 +186,22 @@ sub update_patch } close OUT; + + 1; } exit; +sub check_git_status +{ + open(IN, '-|', 'git status') or die $!; + my $status = join('', <IN>); + close IN; + my $is_clean = $status =~ /\nnothing to commit \(working directory clean\)/; + my($starting_branch) = $status =~ /^# On branch (.+)\n/; + ($status, $is_clean, $starting_branch); +} + sub usage { die <<EOT; |