зеркало из https://github.com/mozilla/gecko-dev.git
Patch for bug 277622: Move DiffStrings() out of globals.pl into Bugzilla/Util.pm; patch by Max K-A <mkanat@kerio.com>, r=vladd, a=myk.
This commit is contained in:
Родитель
56e5c6a014
Коммит
25a26afdfc
|
@ -307,7 +307,7 @@ sub process {
|
||||||
|
|
||||||
my $old_summaries = join(", ", @old_summaries);
|
my $old_summaries = join(", ", @old_summaries);
|
||||||
my $new_summaries = join(", ", @new_summaries);
|
my $new_summaries = join(", ", @new_summaries);
|
||||||
my ($removed, $added) = &::DiffStrings($old_summaries, $new_summaries);
|
my ($removed, $added) = diff_strings($old_summaries, $new_summaries);
|
||||||
if ($removed ne $added) {
|
if ($removed ne $added) {
|
||||||
my $sql_removed = &::SqlQuote($removed);
|
my $sql_removed = &::SqlQuote($removed);
|
||||||
my $sql_added = &::SqlQuote($added);
|
my $sql_added = &::SqlQuote($added);
|
||||||
|
|
|
@ -32,7 +32,7 @@ use base qw(Exporter);
|
||||||
html_quote url_quote value_quote xml_quote
|
html_quote url_quote value_quote xml_quote
|
||||||
css_class_quote
|
css_class_quote
|
||||||
lsearch max min
|
lsearch max min
|
||||||
trim format_time);
|
trim diff_strings format_time);
|
||||||
|
|
||||||
use Bugzilla::Config;
|
use Bugzilla::Config;
|
||||||
|
|
||||||
|
@ -146,6 +146,33 @@ sub trim {
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub diff_strings {
|
||||||
|
my ($oldstr, $newstr) = @_;
|
||||||
|
|
||||||
|
# Split the old and new strings into arrays containing their values.
|
||||||
|
$oldstr =~ s/[\s,]+/ /g;
|
||||||
|
$newstr =~ s/[\s,]+/ /g;
|
||||||
|
my @old = split(" ", $oldstr);
|
||||||
|
my @new = split(" ", $newstr);
|
||||||
|
|
||||||
|
# For each pair of (old, new) entries:
|
||||||
|
# If they're equal, set them to empty. When done, @old contains entries
|
||||||
|
# that were removed; @new contains ones that got added.
|
||||||
|
|
||||||
|
foreach my $oldv (@old) {
|
||||||
|
foreach my $newv (@new) {
|
||||||
|
next if ($newv eq '');
|
||||||
|
if ($oldv eq $newv) {
|
||||||
|
$newv = $oldv = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my $removed = join (", ", grep { $_ ne '' } @old);
|
||||||
|
my $added = join (", ", grep { $_ ne '' } @new);
|
||||||
|
|
||||||
|
return ($removed, $added);
|
||||||
|
}
|
||||||
|
|
||||||
sub format_time {
|
sub format_time {
|
||||||
my ($time) = @_;
|
my ($time) = @_;
|
||||||
|
|
||||||
|
@ -208,8 +235,9 @@ Bugzilla::Util - Generic utility functions for bugzilla
|
||||||
$val = max($a, $b, $c);
|
$val = max($a, $b, $c);
|
||||||
$val = min($a, $b, $c);
|
$val = min($a, $b, $c);
|
||||||
|
|
||||||
# Functions for trimming variables
|
# Functions for manipulating strings
|
||||||
$val = trim(" abc ");
|
$val = trim(" abc ");
|
||||||
|
($removed, $added) = diff_strings($old, $new);
|
||||||
|
|
||||||
# Functions for formatting time
|
# Functions for formatting time
|
||||||
format_time($time);
|
format_time($time);
|
||||||
|
@ -315,7 +343,7 @@ Returns the minimum from a set of values.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head2 Trimming
|
=head2 String Manipulation
|
||||||
|
|
||||||
=over 4
|
=over 4
|
||||||
|
|
||||||
|
@ -324,6 +352,14 @@ Returns the minimum from a set of values.
|
||||||
Removes any leading or trailing whitespace from a string. This routine does not
|
Removes any leading or trailing whitespace from a string. This routine does not
|
||||||
modify the existing string.
|
modify the existing string.
|
||||||
|
|
||||||
|
=item C<diff_strings($oldstr, $newstr)>
|
||||||
|
|
||||||
|
Takes two strings containing a list of comma- or space-separated items
|
||||||
|
and returns what items were removed from or added to the new one,
|
||||||
|
compared to the old one. Returns a list, where the first entry is a scalar
|
||||||
|
containing removed items, and the second entry is a scalar containing added
|
||||||
|
items.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head2 Formatting Time
|
=head2 Formatting Time
|
||||||
|
|
|
@ -1442,35 +1442,6 @@ sub RemoveVotes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Take two comma or space separated strings and return what
|
|
||||||
# values were removed from or added to the new one.
|
|
||||||
sub DiffStrings {
|
|
||||||
my ($oldstr, $newstr) = @_;
|
|
||||||
|
|
||||||
# Split the old and new strings into arrays containing their values.
|
|
||||||
$oldstr =~ s/[\s,]+/ /g;
|
|
||||||
$newstr =~ s/[\s,]+/ /g;
|
|
||||||
my @old = split(" ", $oldstr);
|
|
||||||
my @new = split(" ", $newstr);
|
|
||||||
|
|
||||||
# For each pair of (old, new) entries:
|
|
||||||
# If they're equal, set them to empty. When done, @old contains entries
|
|
||||||
# that were removed; @new contains ones that got added.
|
|
||||||
|
|
||||||
foreach my $oldv (@old) {
|
|
||||||
foreach my $newv (@new) {
|
|
||||||
next if ($newv eq '');
|
|
||||||
if ($oldv eq $newv) {
|
|
||||||
$newv = $oldv = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
my $removed = join (", ", grep { $_ ne '' } @old);
|
|
||||||
my $added = join (", ", grep { $_ ne '' } @new);
|
|
||||||
|
|
||||||
return ($removed, $added);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub PerformSubsts {
|
sub PerformSubsts {
|
||||||
my ($str, $substs) = (@_);
|
my ($str, $substs) = (@_);
|
||||||
$str =~ s/%([a-z]*)%/(defined $substs->{$1} ? $substs->{$1} : Param($1))/eg;
|
$str =~ s/%([a-z]*)%/(defined $substs->{$1} ? $substs->{$1} : Param($1))/eg;
|
||||||
|
|
|
@ -37,6 +37,7 @@ require "CGI.pl";
|
||||||
|
|
||||||
use Bugzilla::Bug;
|
use Bugzilla::Bug;
|
||||||
use Bugzilla::User;
|
use Bugzilla::User;
|
||||||
|
use Bugzilla::Util;
|
||||||
use Bugzilla::RelationSet;
|
use Bugzilla::RelationSet;
|
||||||
|
|
||||||
# Use the Flag module to modify flag data if the user set flags.
|
# Use the Flag module to modify flag data if the user set flags.
|
||||||
|
@ -1082,7 +1083,7 @@ sub LogDependencyActivity {
|
||||||
my $newstr = SnapShotDeps($i, $target, $me);
|
my $newstr = SnapShotDeps($i, $target, $me);
|
||||||
if ($oldstr ne $newstr) {
|
if ($oldstr ne $newstr) {
|
||||||
# Figure out what's really different...
|
# Figure out what's really different...
|
||||||
my ($removed, $added) = DiffStrings($oldstr, $newstr);
|
my ($removed, $added) = diff_strings($oldstr, $newstr);
|
||||||
LogActivityEntry($i,$target,$removed,$added,$whoid,$timestamp);
|
LogActivityEntry($i,$target,$removed,$added,$whoid,$timestamp);
|
||||||
# update timestamp on target bug so midairs will be triggered
|
# update timestamp on target bug so midairs will be triggered
|
||||||
SendSQL("UPDATE bugs SET delta_ts=NOW() WHERE bug_id=$i");
|
SendSQL("UPDATE bugs SET delta_ts=NOW() WHERE bug_id=$i");
|
||||||
|
@ -1687,7 +1688,7 @@ foreach my $id (@idlist) {
|
||||||
|
|
||||||
# If this is the keyword field, only record the changes, not everything.
|
# If this is the keyword field, only record the changes, not everything.
|
||||||
if ($col eq 'keywords') {
|
if ($col eq 'keywords') {
|
||||||
($old, $new) = DiffStrings($old, $new);
|
($old, $new) = diff_strings($old, $new);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($col eq 'product') {
|
if ($col eq 'product') {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче