From 4a3c947ee2e3b5a280d1d44eaff229256a9fd55f Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Thu, 22 Apr 2010 22:38:28 +0300 Subject: Proper formatting; diff num rb-patch can now generate a properly-formmated patch. * Still no description * Still a complete diff. No simple way to get a diff between two diffs (interdiff?) --- rb-patch | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/rb-patch b/rb-patch index c2157a6..96dbae1 100755 --- a/rb-patch +++ b/rb-patch @@ -2,14 +2,18 @@ use strict; use LWP::Simple; +use LWP::UserAgent; use Getopt::Long; use Pod::Usage; +use Digest::SHA1 qw /sha1_hex/; my %opt = ( + diff_num => 1, ); GetOptions( 'review-num|review|r=i' => \$opt{review_num}, + 'diff-num|diff|d=i' => \$opt{diff_num}, 'help|?' => \$opt{help}, man => \$opt{man} ) or pod2usage(2); @@ -24,9 +28,10 @@ pod2usage(-exitstatus => 0, -verbose => 2) if $opt{man}; my $BASE_URL="https://reviewboard.asterisk.org"; - -my $review_url = "$BASE_URL/r/$opt{review_num}"; -my $diff_page_url = "$review_url/diff"; +my $review_num = $opt{review_num}; +my $diff_num = $opt{diff_num}; +my $review_url = "$BASE_URL/r/$review_num"; +my $diff_page_url = "$review_url/diff/$diff_num"; my $diff_url = "$diff_page_url/raw"; my $content = get($diff_page_url); @@ -38,24 +43,40 @@ $content =~ m{

([^<]*)

}; my $summary = $1; $content =~ m{([^<]*)}; my ($url, $name) = ($1, $2); +$content =~ m{([^<]*)}; +my $branch = $1; $url = "$BASE_URL$url"; -$content =~ m{

Diff revision (\d+) \(Latest\)

}; -my $diff_count = $1; -my $raw_diff = get($diff_url); -die "$0: Failed to get raw diff $diff_url\n" unless defined $raw_diff; +my $ua = LWP::UserAgent->new; +my $response = $ua->get($diff_url); + +#my $raw_diff = get($diff_url); +die "$0: Failed to get raw diff $diff_url".($response->status_live)."\n" + unless $response->is_success; +my $raw_diff = $response->content; +my $date = $response->header('Date'); + +my $checksum = sha1_hex("$review_num::$diff_num::$name::$date"); +#my @head = head($diff_page_url); +##my $date = $head[2]; +#my $date = join '>|<', @head; # Fix patch-level from -p0 to -p1 # Alternatively you could use git-am -p0 +$raw_diff =~ m{\n--- [^\n]*\s\(revision (\d+)\)}; +my $revision = $1; $raw_diff =~ s{\n--- } {$&a/}g; $raw_diff =~ s{\n\+\+\+ }{$&b/}g; print -"From +"From $checksum $date From: $name <$url> -Date: +Date: $date Subject: [PATCH] $summary +Review No. $review_num. diff no. $diff_num. +Base branch: $branch, revision: $revision + $raw_diff -- cgit v1.2.3