Skip to content

Commit

Permalink
Improve readability of trace logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaputo committed Aug 20, 2012
1 parent 9adfe33 commit 32f0e4c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
5 changes: 4 additions & 1 deletion bin/snanalyze
Expand Up @@ -58,7 +58,10 @@ Log::Any::Adapter->set(
formatter => sub { formatter => sub {
my ($file, $line) = (caller(1))[1,2]; my ($file, $line) = (caller(1))[1,2];
$file =~ s!.*/!!; $file =~ s!.*/!!;
strftime('%F %T', localtime()) . " - $file:$line - $_[1]"; sprintf(
"%s - %5d %s - %s",
strftime('%F %T', localtime()), $line, $file, $_[1]
);
}, },
); );


Expand Down
5 changes: 4 additions & 1 deletion bin/snassign-auto
Expand Up @@ -46,7 +46,10 @@ Log::Any::Adapter->set(
formatter => sub { formatter => sub {
my ($file, $line) = (caller(1))[1,2]; my ($file, $line) = (caller(1))[1,2];
$file =~ s!.*/!!; $file =~ s!.*/!!;
strftime('%F %T', localtime()) . " - $file:$line - $_[1]"; sprintf(
"%s - %5d %s - %s",
strftime('%F %T', localtime()), $line, $file, $_[1]
);
}, },
); );


Expand Down
5 changes: 4 additions & 1 deletion bin/snerp
Expand Up @@ -135,7 +135,10 @@ Log::Any::Adapter->set(
formatter => sub { formatter => sub {
my ($file, $line) = (caller(1))[1,2]; my ($file, $line) = (caller(1))[1,2];
$file =~ s!.*/!!; $file =~ s!.*/!!;
strftime('%F %T', localtime()) . " - $file:$line - $_[1]"; sprintf(
"%s - %5d %s - %s",
strftime('%F %T', localtime()), $line, $file, $_[1]
);
}, },
); );


Expand Down
34 changes: 17 additions & 17 deletions lib/SVN/Analysis.pm
Expand Up @@ -129,7 +129,8 @@ sub reset {
sub consider_add { sub consider_add {
my ($self, $path, $revision, $kind) = @_; my ($self, $path, $revision, $kind) = @_;


$log->trace("add: $path $revision"); my $display_path = length($path) ? $path : '/';
$log->trace(" r$revision add $kind $display_path");


# Touch the parent directory of the thing being added. # Touch the parent directory of the thing being added.
$self->_touch_parent_directory($path, $revision); $self->_touch_parent_directory($path, $revision);
Expand All @@ -154,7 +155,6 @@ sub consider_add {
) )
") or die $self->dbh()->errstr(); ") or die $self->dbh()->errstr();


$log->trace("INSERT $path r$revision");
$sth->execute($path, $revision, $revision, "add", "add", 1, 1, 0, 0) or die ( $sth->execute($path, $revision, $revision, "add", "add", 1, 1, 0, 0) or die (
$sth->errstr() $sth->errstr()
); );
Expand All @@ -164,13 +164,16 @@ sub consider_add {


sub consider_change { sub consider_change {
my ($self, $path, $revision, $kind) = @_; my ($self, $path, $revision, $kind) = @_;
$log->trace(" r$revision change $kind $path");
return $self->_touch_parent_directory($path, $revision) if $kind ne "dir"; return $self->_touch_parent_directory($path, $revision) if $kind ne "dir";
return $self->_touch_directory($path, $revision); return $self->_touch_directory($path, $revision);
} }


sub consider_copy { sub consider_copy {
my ($self, $dst_path, $dst_rev, $kind, $src_path, $src_rev) = @_; my ($self, $dst_path, $dst_rev, $kind, $src_path, $src_rev) = @_;


$log->trace(" r$dst_rev copy $kind $dst_path from $src_path at r$src_rev");

my $sth_copy = $self->dbh()->prepare_cached(" my $sth_copy = $self->dbh()->prepare_cached("
INSERT INTO copy (src_path, src_rev, kind, dst_path, dst_rev) INSERT INTO copy (src_path, src_rev, kind, dst_path, dst_rev)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
Expand All @@ -191,16 +194,14 @@ sub consider_copy {
# If this is a file, we're done. # If this is a file, we're done.
return if $kind ne "dir"; return if $kind ne "dir";


$log->trace("copy: $src_path $src_rev > $dst_path $dst_rev");

# Copy the source path and all the entire tree below. # Copy the source path and all the entire tree below.
foreach my $path_to_copy ($self->_get_tree_paths($src_path, $src_rev)) { foreach my $path_to_copy ($self->_get_tree_paths($src_path, $src_rev)) {
my $relocated_path = $path_to_copy; my $relocated_path = $path_to_copy;
$relocated_path =~ s/^\Q$src_path\E(\/|$)/$dst_path$1/ or confess( $relocated_path =~ s/^\Q$src_path\E(\/|$)/$dst_path$1/ or confess(
"can't relocate $path_to_copy from $src_path to $dst_path" "can't relocate $path_to_copy from $src_path to $dst_path"
); );


$log->trace("copy includes: $path_to_copy > $relocated_path"); $log->trace(" copy includes: $relocated_path from $path_to_copy");


my $sth = $self->dbh()->prepare_cached(" my $sth = $self->dbh()->prepare_cached("
INSERT INTO dir ( INSERT INTO dir (
Expand Down Expand Up @@ -230,6 +231,8 @@ sub consider_copy {
sub consider_delete { sub consider_delete {
my ($self, $path, $revision) = @_; my ($self, $path, $revision) = @_;


$log->trace(" r$revision delete $path");

# Touch the parent directory and all its ancestors back to the root. # Touch the parent directory and all its ancestors back to the root.
$self->_touch_parent_directory($path, $revision); $self->_touch_parent_directory($path, $revision);


Expand All @@ -245,8 +248,6 @@ sub consider_delete {
$self->_path_exists($path_to_delete, $revision) $self->_path_exists($path_to_delete, $revision)
); );


$log->trace("UPDATE $path $revision (is_active=0)");

my $sth = $self->dbh()->prepare_cached(" my $sth = $self->dbh()->prepare_cached("
UPDATE dir SET rev_last = ?, op_last = ?, is_active = ? UPDATE dir SET rev_last = ?, op_last = ?, is_active = ?
WHERE path = ? and rev_first <= ? and is_active = 1 WHERE path = ? and rev_first <= ? and is_active = 1
Expand Down Expand Up @@ -574,7 +575,7 @@ sub get_tree {
) or die $sth_node->errstr(); ) or die $sth_node->errstr();


$sth_node->fetch() or die $sth_node->errstr(); $sth_node->fetch() or die $sth_node->errstr();
$sth_node->fetch() and die "more than one node for $path r$rev"; $sth_node->fetch() and die "more than one node for $path at r$rev";


# Traverse to the new node. # Traverse to the new node.


Expand All @@ -583,12 +584,12 @@ sub get_tree {
my $final = pop(@segments); my $final = pop(@segments);
foreach (@segments) { foreach (@segments) {
$iter = $iter->children()->{$_} or die( $iter = $iter->children()->{$_} or die(
"segment $_ from $path r$rev not found" "segment $_ from $path at r$rev not found"
); );
} }


if (defined $final) { if (defined $final) {
die "duplicate segment $final in $path r$rev" if exists( die "duplicate segment $final in $path at r$rev" if exists(
$iter->children()->{$final} $iter->children()->{$final}
); );


Expand Down Expand Up @@ -806,7 +807,8 @@ sub _touch_directory {


foreach my $dir_path ($self->_get_container_paths($path, $revision)) { foreach my $dir_path ($self->_get_container_paths($path, $revision)) {


$log->trace("touchdir: $dir_path $revision"); my $display_path = length($dir_path) ? $dir_path : '/';
$log->trace(" r$revision touching directory $display_path");


my $sth_query = $self->dbh()->prepare_cached(" my $sth_query = $self->dbh()->prepare_cached("
SELECT op_last, rev_first SELECT op_last, rev_first
Expand All @@ -826,11 +828,9 @@ sub _touch_directory {


$sth_query->fetch() or die $sth_query->errstr(); $sth_query->fetch() or die $sth_query->errstr();
$sth_query->fetch() and die( $sth_query->fetch() and die(
"more than one active row for $path r$revision" "more than one active row for $path at r$revision"
); );


$log->trace("UPDATE $dir_path $rev_first -> $revision");

my $sth_update = $self->dbh()->prepare_cached(" my $sth_update = $self->dbh()->prepare_cached("
UPDATE dir UPDATE dir
SET op_last = ?, rev_last = ?, is_modified = 1 SET op_last = ?, rev_last = ?, is_modified = 1
Expand Down Expand Up @@ -882,8 +882,8 @@ sub _path_exists {
$sth->bind_columns(\$exists) or die $sth->errstr(); $sth->bind_columns(\$exists) or die $sth->errstr();


$sth->fetch(); $sth->fetch();
die "$path r$revision exists more than once" if $exists > 1; die "$path at r$revision exists more than once" if $exists > 1;
$sth->fetch() and die "more than one active row for $path r$revision"; $sth->fetch() and die "more than one active row for $path at r$revision";


return $exists; return $exists;
} }
Expand All @@ -906,7 +906,7 @@ sub _get_tree_paths {


my @found_paths; my @found_paths;
while ($sth->fetch()) { while ($sth->fetch()) {
$log->trace("... $path = $found_path ($found_rev)"); $log->trace(" ... $path = $found_path (r$found_rev)");
push @found_paths, $found_path; push @found_paths, $found_path;
} }


Expand Down
10 changes: 6 additions & 4 deletions lib/SVN/Dump/Analyzer.pm
Expand Up @@ -44,7 +44,7 @@ sub on_node_add {


sub on_node_change { sub on_node_change {
my ($self, $revision, $path, $kind, $data) = @_; my ($self, $revision, $path, $kind, $data) = @_;
$log->trace("ANL) r$revision edit $kind $path"); $log->trace("r$revision edit $kind $path");
$self->analysis()->consider_change($path, $revision, $kind); $self->analysis()->consider_change($path, $revision, $kind);
} }


Expand All @@ -56,22 +56,22 @@ sub on_node_change {
# and addition in the same revision is confusing. # and addition in the same revision is confusing.
sub on_node_replace { sub on_node_replace {
my ($self, $revision, $path, $kind, $data) = @_; my ($self, $revision, $path, $kind, $data) = @_;
$log->trace("ANL) r$revision replace $kind $path"); $log->trace("r$revision replace $kind $path");
$self->analysis()->consider_delete($path, $revision); $self->analysis()->consider_delete($path, $revision);
$self->analysis()->consider_add($path, $revision, $kind); $self->analysis()->consider_add($path, $revision, $kind);
} }


sub on_node_copy { sub on_node_copy {
my ($self, $dst_rev, $dst_path, $kind, $src_rev, $src_path, $text) = @_; my ($self, $dst_rev, $dst_path, $kind, $src_rev, $src_path, $text) = @_;
$log->trace("ANL) r$dst_rev copy $kind $dst_path from $src_path r$src_rev"); $log->trace("r$dst_rev copy $kind $dst_path from $src_path at r$src_rev");
$self->analysis()->consider_copy( $self->analysis()->consider_copy(
$dst_path, $dst_rev, $kind, $src_path, $src_rev, $dst_path, $dst_rev, $kind, $src_path, $src_rev,
); );
} }


sub on_node_delete { sub on_node_delete {
my ($self, $revision, $path) = @_; my ($self, $revision, $path) = @_;
$log->trace("ANL) r$revision delete $path"); $log->trace("r$revision delete $path");
$self->analysis()->consider_delete($path, $revision); $self->analysis()->consider_delete($path, $revision);
} }


Expand All @@ -83,6 +83,8 @@ sub on_walk_done {
sub on_walk_begin { sub on_walk_begin {
my $self = shift; my $self = shift;


$log->trace("r0 add dir /");

# The repository needs a root directory. # The repository needs a root directory.
$self->analysis()->consider_add("", 0, "dir"); $self->analysis()->consider_add("", 0, "dir");
} }
Expand Down

0 comments on commit 32f0e4c

Please sign in to comment.