#!/usr/bin/perl use strict; use warnings; use Getopt::Long; &Getopt::Long::Configure('bundling'); &usage if !&GetOptions( 'branch|b=s' => \( my $master_branch = 'master' ), 'skip-check' => \( my $skip_branch_check ), 'delete' => \( my $delete_local_branches ), 'help|h' => \( my $help_opt ), ); &usage if $help_opt; my %local_branch; open PIPE, '-|', 'git branch -l' or die "Unable to fork: $!\n"; while () { if (m# patch/\Q$master_branch\E/(.*)#o) { $local_branch{$1} = 1; } } close PIPE; if ($delete_local_branches) { foreach my $name (sort keys %local_branch) { my $branch = "patch/$master_branch/$name"; system 'git', 'branch', '-D', $branch and exit 1; } %local_branch = ( ); } require 'packaging/git-status.pl'; check_git_state($master_branch, !$skip_branch_check, 1); my @patch_list; foreach (@ARGV) { if (!-f $_) { die "File not found: $_\n"; } die "Filename is not a .diff file: $_\n" unless /\.diff$/; push @patch_list, $_; } exit unless @patch_list; my(%scanned, %created, %info); foreach my $patch (@patch_list) { my($where, $name) = $patch =~ m{^(.*?)([^/]+)\.diff$}; next if $scanned{$name}++; open IN, '<', $patch or die "Unable to open $patch: $!\n"; my $info = ''; my $commit; while () { if (m#^based-on: (\S+)#) { $commit = $1; last; } last if m#^index .*\.\..* \d#; last if m#^diff --git #; last if m#^--- (old|a)/#; $info .= $_; } close IN; $info =~ s/\s+\Z/\n/; my $parent = $master_branch; my @patches = $info =~ m#patch -p1 ', "PATCH.$name" or die $!; print OUT $info; close OUT; system 'git', 'add', "PATCH.$name" and exit 1; open IN, '<', $patch or die "Unable to open $patch: $!\n"; $_ = join('', ); close IN; open PIPE, '|-', 'patch -p1' or die $!; print PIPE $_; close PIPE; system 'rm -f *.orig */*.orig'; while (m#\nnew file mode (\d+)\s+--- /dev/null\s+\Q+++\E b/(.*)#g) { chmod oct($1), $2; system 'git', 'add', $2; } while (1) { system 'git status'; print 'Press Enter to commit, Ctrl-C to abort, or type a wild-name to add a new file: '; $_ = ; last if /^$/; chomp; system "git add $_"; } while (system 'git', 'commit', '-a', '-m', "Creating branch from $name.diff.") { exit 1 if system '/bin/zsh'; } } sub usage { die <