All pastes #1541579 Raw Edit

git pasteapply

public text v1 · immutable
#1541579 ·published 2009-08-24 13:57 UTC
rendered paste body
#!/usr/bin/env perl
use strict;
use WWW::Mechanize;
use Config;

unless (scalar @ARGV) {
    print "Usage: git pasteapply [options] <number> [<number>...]\n" .
	"Fetches the paste from pastebin.ca numbered <number> and applies\n" .
	"Options are passed directly to git am\n" .
	"\n" .
	"Useful options:\n" .
	" -s, --signoff		Add Signed-off-by: line to the commit message\n" .
	" -3, --3way		When the patch does not apply cleanly, fall back on 3-way merge\n" .
	" -p<n>			Strip <n> elements of the paths (default 1)\n" .
	" --whitespace=<nowarn,warn,fix,error,error-all>\n";
    exit 0;
}
my @pastes;
my @args;
my $pastebin_root = "http://pastebin.ca/raw/";

for (@ARGV) {
    if (m/^-/) {
	push @args, $_;
    } else {
	push @pastes, $_;
    }
}

open GIT_AM, "|-", "git", "am", @args, "-"
    or die "Cannot start git-am: $!";

my $www = WWW::Mechanize->new();
foreach my $paste (@pastes) {
    $www->get($pastebin_root . $paste);
    my $content = $www->content();
    $content =~ s/\r\n/\n/g;
    print GIT_AM $content;
}

close GIT_AM;
exit $?