Patchwork [1/3] UBUNTU: git-ubuntu-log -- commonise duplicated log handling

login
register
mail settings
Submitter Andy Whitcroft
Date Feb. 10, 2010, 12:23 p.m.
Message ID <1265804627-21720-2-git-send-email-apw@canonical.com>
Download mbox | patch
Permalink /patch/45027/
State Accepted
Delegated to: Stefan Bader
Headers show

Comments

Andy Whitcroft - Feb. 10, 2010, 12:23 p.m.
We have two copies of the handling for Bug: et al in get-ubuntu-log
only differing in whether Ignore: handling is active.  Refactor this
code to share a single copy of this processing.

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 debian/scripts/misc/git-ubuntu-log |   43 +++++++++++++----------------------
 1 files changed, 16 insertions(+), 27 deletions(-)
Stefan Bader - Feb. 10, 2010, 1:08 p.m.
This looks much better to me. Even I understand it now.

Andy Whitcroft wrote:
> We have two copies of the handling for Bug: et al in get-ubuntu-log
> only differing in whether Ignore: handling is active.  Refactor this
> code to share a single copy of this processing.
> 
> Signed-off-by: Andy Whitcroft <apw@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  debian/scripts/misc/git-ubuntu-log |   43 +++++++++++++----------------------
>  1 files changed, 16 insertions(+), 27 deletions(-)
> 
> diff --git a/debian/scripts/misc/git-ubuntu-log b/debian/scripts/misc/git-ubuntu-log
> index 666e831..2ac19bc 100755
> --- a/debian/scripts/misc/git-ubuntu-log
> +++ b/debian/scripts/misc/git-ubuntu-log
> @@ -168,6 +168,7 @@ sub changelog_input {
>  		elsif ($pstate == 4) {
>  			next unless /^\s*?(.*)/;
>  			my $ignore = 0;
> +			my $do_ignore = 0;
>  			my $bug = undef;
>  			my %bugz = ();
>  			my $k;
> @@ -180,38 +181,26 @@ sub changelog_input {
>  			$desc = $1;
>  
>  			if ($desc =~ /^ *(Revert "|)UBUNTU:/) {
> -				while (<STDIN>) {
> -					$ignore  =  1 if /^ *Ignore: yes/i;
> -					if    (/^ *Bug: *(#|)(.*)/i) {
> -						foreach $k (split('(,|)*\s*#', $2)) {
> -							$bugz{$k} = 1 if (($k ne '') and ($k =~ /[0-9]+/));
> -						}
> -					}
> -					elsif (/^ *BugLink: *http.*:\/\/.*\/([0-9]+)/i) {
> -						$bugz{$1} = 1;
> -					}
> -					elsif (/^ *(CVE-.*)/) {
> -						$cve = $1
> -					}
> -					last if /^commit /;
> -				}
> +				$do_ignore = 1;
>  			} else {
> +				$do_ignore = 0;
>  				$author = $kernel_auth;
>  				$ignore = 1 if $desc =~ /Merge /;
> -				while (<STDIN>) {
> -					if    (/^ *Bug: *(#|)(.*)/i) {
> -						foreach $k (split('(,|)*\s*#', $2)) {
> -							$bugz{$k} = 1 if (($k ne '') and ($k =~ /[0-9]+/));
> -						}
> -					}
> -					elsif (/^ *BugLink: *http.*:\/\/.*\/([0-9]+)/i) {
> -						$bugz{$1} = 1;
> -					}
> -					elsif (/^ *(CVE-.*)/) {
> -						$cve = $1
> +			}
> +			while (<STDIN>) {
> +				$ignore  =  1 if ($do_ignore && /^ *Ignore: yes/i);
> +				if    (/^ *Bug: *(#|)(.*)/i) {
> +					foreach $k (split('(,|)*\s*#', $2)) {
> +						$bugz{$k} = 1 if (($k ne '') and ($k =~ /[0-9]+/));
>  					}
> -					last if /^commit /;
>  				}
> +				elsif (/^ *BugLink: *http.*:\/\/.*\/([0-9]+)/i) {
> +					$bugz{$1} = 1;
> +				}
> +				elsif (/^ *(CVE-.*)/) {
> +					$cve = $1
> +				}
> +				last if /^commit /;
>  			}
>  
>                          $bug = join(", #", keys(%bugz));

Patch

diff --git a/debian/scripts/misc/git-ubuntu-log b/debian/scripts/misc/git-ubuntu-log
index 666e831..2ac19bc 100755
--- a/debian/scripts/misc/git-ubuntu-log
+++ b/debian/scripts/misc/git-ubuntu-log
@@ -168,6 +168,7 @@  sub changelog_input {
 		elsif ($pstate == 4) {
 			next unless /^\s*?(.*)/;
 			my $ignore = 0;
+			my $do_ignore = 0;
 			my $bug = undef;
 			my %bugz = ();
 			my $k;
@@ -180,38 +181,26 @@  sub changelog_input {
 			$desc = $1;
 
 			if ($desc =~ /^ *(Revert "|)UBUNTU:/) {
-				while (<STDIN>) {
-					$ignore  =  1 if /^ *Ignore: yes/i;
-					if    (/^ *Bug: *(#|)(.*)/i) {
-						foreach $k (split('(,|)*\s*#', $2)) {
-							$bugz{$k} = 1 if (($k ne '') and ($k =~ /[0-9]+/));
-						}
-					}
-					elsif (/^ *BugLink: *http.*:\/\/.*\/([0-9]+)/i) {
-						$bugz{$1} = 1;
-					}
-					elsif (/^ *(CVE-.*)/) {
-						$cve = $1
-					}
-					last if /^commit /;
-				}
+				$do_ignore = 1;
 			} else {
+				$do_ignore = 0;
 				$author = $kernel_auth;
 				$ignore = 1 if $desc =~ /Merge /;
-				while (<STDIN>) {
-					if    (/^ *Bug: *(#|)(.*)/i) {
-						foreach $k (split('(,|)*\s*#', $2)) {
-							$bugz{$k} = 1 if (($k ne '') and ($k =~ /[0-9]+/));
-						}
-					}
-					elsif (/^ *BugLink: *http.*:\/\/.*\/([0-9]+)/i) {
-						$bugz{$1} = 1;
-					}
-					elsif (/^ *(CVE-.*)/) {
-						$cve = $1
+			}
+			while (<STDIN>) {
+				$ignore  =  1 if ($do_ignore && /^ *Ignore: yes/i);
+				if    (/^ *Bug: *(#|)(.*)/i) {
+					foreach $k (split('(,|)*\s*#', $2)) {
+						$bugz{$k} = 1 if (($k ne '') and ($k =~ /[0-9]+/));
 					}
-					last if /^commit /;
 				}
+				elsif (/^ *BugLink: *http.*:\/\/.*\/([0-9]+)/i) {
+					$bugz{$1} = 1;
+				}
+				elsif (/^ *(CVE-.*)/) {
+					$cve = $1
+				}
+				last if /^commit /;
 			}
 
                         $bug = join(", #", keys(%bugz));