summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir@cohens.org.il>2010-04-22 22:38:28 +0300
committerTzafrir Cohen <tzafrir@cohens.org.il>2010-04-22 22:38:28 +0300
commit4a3c947ee2e3b5a280d1d44eaff229256a9fd55f (patch)
treed0960aad48dca3691a1a22e8a9737e75f7d17196
parentcc95bf511e1d225e6a9a59951b23d93f85948267 (diff)
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?)
-rwxr-xr-xrb-patch39
1 files 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{<h1 id="summary" class="editable">([^<]*)</h1>};
my $summary = $1;
$content =~ m{<a id="submitter" href="([^"]*)">([^<]*)</a>};
my ($url, $name) = ($1, $2);
+$content =~ m{<span id="branch" class="editable">([^<]*)</a>};
+my $branch = $1;
$url = "$BASE_URL$url";
-$content =~ m{<h1>Diff revision (\d+) \(Latest\)</h1>};
-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 <Fill in cookie> <fill in date>
+"From $checksum $date
From: $name <$url>
-Date: <fill in date>
+Date: $date
Subject: [PATCH] $summary
+Review No. $review_num. diff no. $diff_num.
+Base branch: $branch, revision: $revision
+
<fill in further description>
$raw_diff