summaryrefslogtreecommitdiff
path: root/scripts/vyatta-config-mgmt.pl
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@vyatta.com>2010-11-20 11:29:26 -0800
committerStig Thormodsrud <stig@vyatta.com>2010-11-20 11:29:26 -0800
commit3ab9bba26a12ff5ff09a868854eaf1da5e42668d (patch)
tree88a8d3e47317000d6286617a1b4c433c0e50e83b /scripts/vyatta-config-mgmt.pl
parent79adeac0435366200ed57d24edbfd84ce6d7d5cb (diff)
downloadvyatta-config-mgmt-3ab9bba26a12ff5ff09a868854eaf1da5e42668d.tar.gz
vyatta-config-mgmt-3ab9bba26a12ff5ff09a868854eaf1da5e42668d.zip
Filter suprious temp file lines from diff output.
Diffstat (limited to 'scripts/vyatta-config-mgmt.pl')
-rwxr-xr-xscripts/vyatta-config-mgmt.pl32
1 files changed, 23 insertions, 9 deletions
diff --git a/scripts/vyatta-config-mgmt.pl b/scripts/vyatta-config-mgmt.pl
index ae4344d..d643aef 100755
--- a/scripts/vyatta-config-mgmt.pl
+++ b/scripts/vyatta-config-mgmt.pl
@@ -91,21 +91,32 @@ sub parse_at_output {
return (1, '', '');
}
-sub filter_version_string {
+sub filter_file_lines {
my ($diff) = @_;
my @lines = split("\n", $diff);
+ my $line1 = shift @lines;
+ my $line2 = shift @lines;
+ unshift(@lines, $line2) if $line2 !~ /^\+\+\+ /;
+ unshift(@lines, $line1) if $line1 !~ /^\-\-\- /;
+ return join("\n", @lines);
+}
+
+sub filter_version_string {
+ my ($diff) = @_;
- my @new_lines = ();
+ # find last diff hunk, skip it if it's the version string
+ my @lines = split("\n", $diff);
+ my @last_hunk = ();
my $found = 0;
while (my $line = pop(@lines)) {
- if (! $found) {
- $found = 1 if $line =~ /^@@/;
- } else {
- unshift(@new_lines, $line);
- }
+ unshift(@last_hunk, $line);
+ $found = 1 if $line =~ /vyatta-config-version/;
+ last if $line =~ /^@@/;
}
- return join("\n", @new_lines);
+ return join("\n", @lines) if $found;
+ push(@lines, @last_hunk);
+ return join("\n", @lines);
}
@@ -261,6 +272,7 @@ if ($action eq 'diff') {
system("cli-shell-api showCfg --show-active-only > $tmp_config_file");
system("cli-shell-api showCfg --show-working-only > $tmp_config_file2");
my $diff = `diff -u -w $tmp_config_file $tmp_config_file2`;
+ $diff = filter_file_lines($diff);
print $diff;
system("rm $tmp_config_file $tmp_config_file2");
} elsif ($args eq 0) {
@@ -270,8 +282,9 @@ if ($action eq 'diff') {
system("cli-shell-api showCfg --show-working-only > $tmp_config_file");
my $filename1 = cm_commit_get_file_name($rev1);
my $diff = `zdiff -u $filename1 $tmp_config_file`;
+ $diff = filter_file_lines($diff);
+ $diff = filter_version_string($diff);
if (defined $diff and length($diff) > 0) {
- $diff = filter_version_string($diff);
print $diff;
} else {
print "No changes between working and "
@@ -286,6 +299,7 @@ if ($action eq 'diff') {
my $filename = cm_commit_get_file_name($rev1);
my $filename2 = cm_commit_get_file_name($rev2);
my $diff = `zdiff -u $filename2 $filename`;
+ $diff = filter_file_lines($diff);
print $diff;
}
exit 0;