[svk-commit] r3124 - branches/delta-refactor/lib/SVK
nobody at bestpractical.com
nobody at bestpractical.com
Mon Nov 3 12:11:17 EST 2008
Author: clkao
Date: Mon Nov 3 12:11:17 2008
New Revision: 3124
Modified:
branches/delta-refactor/lib/SVK/Delta.pm
Log:
Begin refactoring duplicated chunk of code in _delta_dir into _delta_entry.
Modified: branches/delta-refactor/lib/SVK/Delta.pm
==============================================================================
--- branches/delta-refactor/lib/SVK/Delta.pm (original)
+++ branches/delta-refactor/lib/SVK/Delta.pm Mon Nov 3 12:11:17 2008
@@ -225,94 +225,20 @@
$self->SUPER::_delta_file(%arg, %compatarg);
}
-sub _delta_dir2 {
- my ($self, $base_root, $base_path, $target, $editor, $ctx) = @_;
-
- my $source = $target->source;
- my %arg = (
- %$ctx
- );
-
- my %compatarg = _compat_args(@_);
-
- if ($arg{entry} && $arg{exclude} && exists $arg{exclude}{$arg{entry}}) {
- $arg{cb_exclude}->($target->path_anchor, $target->copath) if $arg{cb_exclude};
- return;
- }
- my $pool = SVN::Pool->new_default (undef);
- my $cinfo = $arg{cinfo};
- my $schedule = $cinfo->{'.schedule'} || '';
- $arg{add} = 1 if $arg{auto_add} && $arg{base_kind} == $SVN::Node::none ||
- $schedule eq 'replace';
+sub _delta_entry {
+ my ($self, $base_root, $base_path, $target, $editor, $opt, $ctx) = @_;
+ my $targets = $opt->{targets};
+ my $entries = $opt->{entries};
+ my $entry = $opt->{entry};
+ my $baton = $opt->{baton};
+ my $signature = $opt->{signature};
+ my $ignore = $opt->{ignore};
+ my %arg = %$ctx;
- # compute targets for children
- my $targets;
- for (@{$arg{targets} || []}) {
- my ($volume, $directories, $file) = splitpath ($_);
- if ( my @dirs = splitdir($directories) ) {
- my $path = $volume . shift(@dirs);
- $file = catdir(grep length, @dirs, $file);
- push @{$targets->{$path}}, $file
- }
- else {
- $targets->{$file} = undef;
- }
- }
- my $thisdir; # if we are performing delta on the this dir itself
- if ($targets) {
- if (exists $targets->{''}) {
- delete $targets->{''};
- $thisdir = 1;
- }
- }
- else {
- $thisdir = 1;
- }
- # if we are descending into children
- # don't use depth when we are still traversing through targets
- my $descend = defined $targets || !(defined $arg{depth} && $arg{depth} == 0);
- # XXX: the top level entry is undefined, which should be fixed.
- $self->cb_conflict->($editor, defined $arg{entry} ? $arg{entry} : '', $arg{baton}, $cinfo->{'.conflict'})
- if $thisdir && $self->cb_conflict && $cinfo->{'.conflict'};
-
- # XXX: later
- return 1 if $self->_node_deleted_or_absent(%compatarg, %arg, pool => $pool);
- # if a node is replaced, it has no base, unless it was replaced with history.
- $arg{base} = 0 if $schedule eq 'replace' && !$cinfo->{'.copyfrom'};
- my ($entries, $baton) = ({});
- if ($arg{add}) {
- $baton = $arg{root} ? $arg{baton} :
- $editor->add_directory($arg{entry}, $arg{baton},
- $cinfo->{'.copyfrom'}
- ? ($arg{cb_copyfrom}->(@{$cinfo}{qw/.copyfrom .copyfrom_rev/}))
- : (undef, -1), $pool);
- }
-
- $entries = $base_root->dir_entries($base_path)
- if $arg{base} && $arg{base_kind} == $SVN::Node::dir;
-
- $baton ||= $arg{root} ? $arg{baton}
- : $editor->open_directory($arg{entry}, $arg{baton},
- $self->_delta_rev2($target, $cinfo), $pool);
-
- # check scheduled addition
- # XXX: does this work with copied directory?
- my ($newprops, $fullprops) = $self->_node_props2($base_root, $base_path, $target, $editor, \%arg);
-
- if ($descend) {
-
- my $signature;
- if ($self->{signature} && $arg{base_root_is_xd}) {
- $signature = $self->{signature}->load ($arg{copath});
- # if we are not iterating over all entries, keep the old signatures
- $signature->{keepold} = 1 if defined $targets
- }
-
- # XXX: Merge this with @direntries so we have single entry to descendents
- for my $entry (sort keys %$entries) {
+ if ($opt->{existing}) {
my $newtarget;
if (defined $targets) {
- next unless exists $targets->{$entry};
+ return unless exists $targets->{$entry};
$newtarget = delete $targets->{$entry};
}
my $kind = $entries->{$entry}->kind;
@@ -325,7 +251,7 @@
if ($sche eq 'replace' && $ccinfo->{'.copyfrom'}) {
delete $entries->{$entry};
$targets->{$entry} = $newtarget if defined $targets;
- next;
+ return;
}
my $newentry = defined $arg{entry} ? "$arg{entry}/$entry" : $entry;
my $newpath = $entry_target->path_anchor;
@@ -333,10 +259,10 @@
$self->cb_unchanged->($editor, $newentry, $baton,
$self->_delta_rev2($target, $ccinfo)
) if $arg{cb_unchanged};
- next;
+ return;
}
my ($type, $st) = _node_type($entry_target->copath);
- next unless defined $type;
+ return unless defined $type;
my $delta = $type ? $type eq 'directory' ? '_delta_dir' : '_delta_file'
: $kind == $SVN::Node::file ? '_delta_file' : '_delta_dir';
@@ -363,25 +289,12 @@
cinfo => $ccinfo });
$ret and ($signature && $signature->invalidate ($entry));
- }
- if ($signature) {
- $signature->flush;
- undef $signature;
- }
- my $ignore = $self->xd->ignore($fullprops->{'svn:ignore'});
-
- my $new_entries;
- # if we are at somewhere arg{copath} not exist, $arg{type} is empty
- if ($arg{type} && !(defined $targets && !keys %$targets)) {
- $new_entries = $target->root->dir_entries($target->path_anchor, $pool);
- ;
}
-
- for my $entry (sort grep { !exists $entries->{$_} } keys %$new_entries) {
+ else {
my $newtarget;
if (defined $targets) {
- next unless exists $targets->{$entry};
+ return unless exists $targets->{$entry};
$newtarget = delete $targets->{$entry};
}
my $entry_target = $target->clone->descend($entry);
@@ -400,7 +313,7 @@
if ((!$add || $arg{auto_add}) && $entry =~ m/$ignore/) {
$self->cb_ignored->($editor, $newpaths{entry}, $arg{baton})
if $self->cb_ignored;
- next;
+ return;
}
}
if ($ccinfo->{'.conflict'}) {
@@ -410,15 +323,15 @@
unless ($add || $ccinfo->{'.conflict'}) {
if ($self->cb_unknown) {
$self->cb_unknown->($editor, $newpaths{entry}, $arg{baton});
- $self->_unknown_verbose(%arg, %newpaths, %compatarg,
+ $self->_unknown_verbose(%arg, %newpaths, %{$opt->{compatarg}},
copath => $entry_target->copath,
path => $target->path_anchor,
base_path => $base_path eq '/' ? "/$entry" : "$base_path/$entry")
if $arg{unknown_verbose};
}
- next;
+ return;
}
- my ($type, $st) = _node_type($entry_target->copath) or next;
+ my ($type, $st) = _node_type($entry_target->copath) or return;
my $delta = $type eq 'directory' ? '_delta_dir': '_delta_file';
my $copyfrom = $ccinfo->{'.copyfrom'};
my ($fromroot) = $copyfrom ? $base_root->get_revision_root($target->path_anchor, $ccinfo->{'.copyfrom_rev'}) : undef;
@@ -449,8 +362,130 @@
type => $type,
st => $st,
depth => defined $arg{depth} ? defined $targets ? $arg{depth} : $arg{depth} - 1: undef });
+
+ }
+ }
+
+}
+
+sub _delta_dir2 {
+ my ($self, $base_root, $base_path, $target, $editor, $ctx) = @_;
+
+ my $source = $target->source;
+ my %arg = (
+ %$ctx
+ );
+
+ my %compatarg = _compat_args(@_);
+
+ if ($arg{entry} && $arg{exclude} && exists $arg{exclude}{$arg{entry}}) {
+ $arg{cb_exclude}->($target->path_anchor, $target->copath) if $arg{cb_exclude};
+ return;
+ }
+ my $pool = SVN::Pool->new_default (undef);
+ my $cinfo = $arg{cinfo};
+ my $schedule = $cinfo->{'.schedule'} || '';
+ $arg{add} = 1 if $arg{auto_add} && $arg{base_kind} == $SVN::Node::none ||
+ $schedule eq 'replace';
+
+ # compute targets for children
+ my $targets;
+ for (@{$arg{targets} || []}) {
+ my ($volume, $directories, $file) = splitpath ($_);
+ if ( my @dirs = splitdir($directories) ) {
+ my $path = $volume . shift(@dirs);
+ $file = catdir(grep length, @dirs, $file);
+ push @{$targets->{$path}}, $file
}
+ else {
+ $targets->{$file} = undef;
+ }
+ }
+ my $thisdir; # if we are performing delta on the this dir itself
+ if ($targets) {
+ if (exists $targets->{''}) {
+ delete $targets->{''};
+ $thisdir = 1;
+ }
+ }
+ else {
+ $thisdir = 1;
+ }
+ # if we are descending into children
+ # don't use depth when we are still traversing through targets
+ my $descend = defined $targets || !(defined $arg{depth} && $arg{depth} == 0);
+ # XXX: the top level entry is undefined, which should be fixed.
+ $self->cb_conflict->($editor, defined $arg{entry} ? $arg{entry} : '', $arg{baton}, $cinfo->{'.conflict'})
+ if $thisdir && $self->cb_conflict && $cinfo->{'.conflict'};
+
+ # XXX: later
+ return 1 if $self->_node_deleted_or_absent(%compatarg, %arg, pool => $pool);
+ # if a node is replaced, it has no base, unless it was replaced with history.
+ $arg{base} = 0 if $schedule eq 'replace' && !$cinfo->{'.copyfrom'};
+ my ($entries, $baton) = ({});
+ if ($arg{add}) {
+ $baton = $arg{root} ? $arg{baton} :
+ $editor->add_directory($arg{entry}, $arg{baton},
+ $cinfo->{'.copyfrom'}
+ ? ($arg{cb_copyfrom}->(@{$cinfo}{qw/.copyfrom .copyfrom_rev/}))
+ : (undef, -1), $pool);
}
+
+ $entries = $base_root->dir_entries($base_path)
+ if $arg{base} && $arg{base_kind} == $SVN::Node::dir;
+
+ $baton ||= $arg{root} ? $arg{baton}
+ : $editor->open_directory($arg{entry}, $arg{baton},
+ $self->_delta_rev2($target, $cinfo), $pool);
+
+ # check scheduled addition
+ # XXX: does this work with copied directory?
+ my ($newprops, $fullprops) = $self->_node_props2($base_root, $base_path, $target, $editor, \%arg);
+
+ if ($descend) {
+
+ my $signature;
+ if ($self->{signature} && $arg{base_root_is_xd}) {
+ $signature = $self->{signature}->load ($arg{copath});
+ # if we are not iterating over all entries, keep the old signatures
+ $signature->{keepold} = 1 if defined $targets
+ }
+
+ for my $entry (sort keys %$entries) {
+ $self->_delta_entry( $base_root, $base_path, $target, $editor,
+ { existing => 1,
+ targets => $targets,
+ entries => $entries,
+ entry => $entry,
+ baton => $baton,
+ signature => $signature,
+ },
+ \%arg );
+ }
+
+ if ($signature) {
+ $signature->flush;
+ undef $signature;
+ }
+
+ # if we are at somewhere arg{copath} not exist, $arg{type} is empty
+ if ( $arg{type} && !( defined $targets && !keys %$targets ) ) {
+ my $ignore = $self->xd->ignore($fullprops->{'svn:ignore'});
+ my $new_entries = $target->root->dir_entries( $target->path_anchor, $pool );
+
+ for my $entry ( sort grep { !exists $entries->{$_} } keys %$new_entries ) {
+ $self->_delta_entry( $base_root, $base_path, $target, $editor,
+ { targets => $targets,
+ entries => $new_entries,
+ entry => $entry,
+ baton => $baton,
+ ignore => $ignore,
+ compatarg => \%compatarg,
+ },
+ \%arg );
+ }
+ }
+
}
if ($thisdir) {
More information about the svk-commit
mailing list