Changeset 305

Show
Ignore:
Timestamp:
03/16/2007 08:24:35 PM
Author:
luedi
Message:
  • better move handling
  • when sharing/copying from orphan, turn into a move instead.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/script/Vss2Svn/ActionHandler.pm

    r299 r305  
    252252    } 
    253253 
    254 #    # if this is not a share+pin action, then add this item to the sharedphys 
    255 #    # list. Otherwise, this item is pinned to a specific version and does not 
    256 #    # participate in shared actions 
    257 #    if (!defined $row->{version}) { 
    258 #        push @{ $physinfo->{sharedphys} }, $row->{parentphys}; 
    259 #    } 
    260      
    261254    my $version = $row->{version}; 
    262255    $version = $physinfo->{last_version} if (!defined $version); 
     
    284277    } 
    285278 
     279    # if this is a share from orphan, and not a share+pin action either, we can treat it as a move 
     280    elsif (!defined $row->{version} &&        # share+pin? 
     281           defined $physinfo->{orphaned}      # orphaned? 
     282#          scalar @{$physinfo->{order}} == 1  # only one parent? 
     283       ) { 
     284        $physinfo->{parents}->{'_' . $row->{physname}}->{deleted} = 1; 
     285        undef $physinfo->{orphaned}; 
     286        $self->{action} = 'MOVE'; 
     287    } 
     288     
    286289    # track the addition of the new parent 
    287290    $self->_add_parent ($physname, $row->{parentphys}); 
     
    290293    if (defined $row->{version}) { 
    291294        $physinfo->{parents}->{$row->{parentphys}}->{pinned} = $row->{version}; 
    292     }  
     295    } 
    293296 
    294297    $self->{itempaths} = [$itempath]; 
     
    411414    my $row = $self->{row}; 
    412415 
    413     # Get the existing paths before the move; parent sub will get the new 
    414     # name 
    415416    my $physname = $row->{physname}; 
    416417    my $physinfo = $gPhysInfo{$physname}; 
     
    423424    } 
    424425 
    425     if (!defined $row->{parentphys}) { 
     426    # row->{info} contains the source parent 
     427    # row->{parentphys} contains the target parent 
     428 
     429    # check the source path     
     430    if (!defined $row->{info}) { 
    426431      # Check if this is an orphaned item 
    427       if (scalar @{$physinfo->{order}} == 1) { 
    428         $row->{parentphys} = $physinfo->{order}[0]; 
     432      if (defined $physinfo->{orphaned}) { 
     433        $row->{info} = '_' . $physname; 
     434        undef $physinfo->{orphaned}; 
    429435      } else { 
    430436        # Don't know from where to move. Share it there instead 
    431         $row->{parentphys} = $row->{info}; 
    432         $row->{info} = undef; 
    433437        $self->{action} = 'SHARE'; 
    434438        return $self->_share_handler(); 
     
    437441 
    438442    # '$sourceinfo' is the path for the old location (the move source); 
    439     my $parentpath = $self->_get_current_parent_path (); 
    440     my $sourceinfo = $parentpath . $physinfo->{name}; # $row->{itemname}; 
    441  
    442     if (!defined ($row->{info})) { 
     443    my $sourceparent = $self->_get_parent_path ($row->{info}); 
     444    my $sourceinfo = $sourceparent . $row->{itemname}; 
     445 
     446 
     447    # check the target path 
     448    if (!defined ($row->{parentphys})) { 
    443449        # the target directory was destroyed, so there is no apropriate move 
    444450        # target information. Fall back to a move to the orphaned cache 
    445         $row->{info} = '_' . $row->{physname}; 
     451        $physinfo->{orphaned} = 1; 
     452        $row->{parentphys} = '_' . $row->{physname}; 
    446453    } 
    447454 
    448455    # '$itempath' contains the move target path 
    449     my $itempath = $self->_get_parent_path ($row->{info}) . $row->{itemname}; 
    450  
    451     if (!defined($parentpath)) { 
     456    my $parentpath = $self->_get_current_parent_path (); 
     457    my $itempath = $parentpath . $physinfo->{name}; # $row->{itemname}; 
     458 
     459 
     460    if (!defined($sourceparent)) { 
    452461        # We can't figure out the path for the parent that this move came from, 
    453462        # so it was either destroyed or corrupted. That means that this isn't 
     
    455464 
    456465        $self->{action} = 'ADD'; 
    457 #        $self->{version} = $version; 
    458 #        return $self->_add_handler(); 
    459          
    460         # we need to swap the source and the target path 
    461         $sourceinfo = $itempath; 
    462         undef $itempath; 
     466        undef $sourceinfo; 
    463467    } 
    464468    else { 
    465469        # set the old parent inactive 
    466         $physinfo->{parents}->{$row->{parentphys}}->{deleted} = 1; 
     470        $physinfo->{parents}->{$row->{info}}->{deleted} = 1; 
    467471    } 
    468472 
     
    471475 
    472476    # track the addition of the new parent 
    473     $self->_add_parent ($physname, $row->{info}); 
    474      
    475     $self->{itempaths} = [$sourceinfo]; 
    476     $self->{info} = $itempath
     477    $self->_add_parent ($physname, $row->{parentphys}); 
     478     
     479    $self->{itempaths} = [$itempath]; 
     480    $self->{info} = $sourceinfo
    477481 
    478482    # the move target is now also a valid "copy from" itempath 
     
    746750    } 
    747751 
    748     #todo: make the behavoir of orphaned file tracking configurable 
    749 #    if ($physinfo->{orphaned}) { 
    750 #        return undef; 
    751 #    } 
    752  
    753752    $self->{physname_seen} .= "$physname, "; 
    754753 
     
    878877        return undef; 
    879878    } 
    880  
    881     #todo: make the behavoir of orphaned file tracking configurable 
    882 #    if ($physinfo->{orphaned}) 
    883 #    { 
    884 #        return undef; 
    885 #       } 
    886879 
    887880    $self->{physname_seen} .= "$physname, "; 
     
    11701163 
    11711164    my $physinfo = $gPhysInfo{$physname}; 
    1172     if (!defined $physinfo) { 
    1173         return undef; 
    1174     } 
     1165  
    11751166    # 1. check the parent requested, if there was an item name for this version 
    11761167    #    we can use this item name, since it was valid in that time 
  • trunk/script/Vss2Svn/Dumpfile.pm

    r301 r305  
    393393    # moving in SVN is the same as renaming; add the new and delete the old 
    394394 
    395     my $newpath = $data->{info}; 
    396  
    397     if ($self->{repository}->exists ($newpath)) { 
    398         $self->add_error("Attempt to move item '$itempath' to '$newpath' at " 
     395    my $oldpath = $data->{info}; 
     396 
     397    if ($self->{repository}->exists ($itempath)) { 
     398        $self->add_error("Attempt to move item '$oldpath' to '$itempath' at " 
    399399            . "revision $data->{revision_id}, but destination already exists: possibly " 
    400400            . "missing delete; skipping"); 
     
    402402    } 
    403403 
    404     if (!$self->{repository}->exists ($itempath)) { 
    405         $self->add_error("Attempt to move item '$itempath' to '$newpath' at " 
     404    if (!$self->{repository}->exists ($oldpath)) { 
     405        $self->add_error("Attempt to move item '$oldpath' to '$itempath' at " 
    406406            . "revision $data->{revision_id}, but source doesn't exists: possibly " 
    407407            . "missing recover; skipping"); 
     
    410410     
    411411    my $node = Vss2Svn::Dumpfile::Node->new(); 
    412     $node->set_initial_props($newpath, $data); 
     412    $node->set_initial_props($itempath, $data); 
    413413    $node->{action} = 'add'; 
    414414 
     
    416416 
    417417    $copyrev = $data->{revision_id} - 1; 
    418     $copypath = $itempath; 
     418    $copypath = $oldpath; 
    419419 
    420420    $node->{copyrev} = $copyrev; 
     
    423423    push @$nodes, $node; 
    424424 
    425 #    $self->track_modified($data->{physname}, $data->{revision_id}, $newpath); 
    426 #    $self->track_version ($data->{physname}, $data->{version}, $newpath); 
     425    # the new move target is a valid path. 
     426    $self->track_version ($data->{physname}, $data->{version}, $itempath); 
    427427 
    428428    $node = Vss2Svn::Dumpfile::Node->new(); 
    429     $node->set_initial_props($itempath, $data); 
     429    $node->set_initial_props($oldpath, $data); 
    430430    $node->{action} = 'delete'; 
    431431    $node->{hideprops} = 1; 
     432 
     433#   Deleted tracking is only necessary to be able to recover the item. But a move 
     434#   does not set a recover point, so we don't need to track the delete here. Additionally 
     435#   we do not have enough information for this operation. 
     436#   $self->track_deleted($data->{oldparentphys}, $data->{physname}, 
     437#                        $data->{revision_id}, $oldpath); 
    432438 
    433439    push @$nodes, $node; 
     
    567573    if (defined ($label)) { 
    568574        $label =~ s:/:_:g; 
    569      
     575         
    570576        my $vssitempath = $itempath; 
    571577        $vssitempath =~ s/^$main::gCfg{trunkdir}//; 
  • trunk/script/vss2svn.pl

    r304 r305  
    612612 
    613613    my($childrecs, $child, $id); 
    614     my @delchild = (); 
    615614 
    616615    foreach $row (@$rows) { 
    617         $row->{actiontype} = 'MOVE'; 
     616        $row->{actiontype} = 'MOVE_TO'; 
    618617        $childrecs = &GetChildRecs($row, 1); 
    619618 
     619        my $source = undef; 
     620        my $target = $row->{parentphys}; 
     621 
    620622        if (scalar @$childrecs > 1) { 
    621             &ThrowWarning("Multiple chidl recs for parent MOVE rec " 
     623            &ThrowWarning("Multiple child recs for parent MOVE rec " 
    622624                          . "'$row->{action_id}'"); 
    623625        } 
    624626 
    625         foreach $child (@$childrecs) { 
    626             my $update; 
    627             $update = $gCfg{dbh}->prepare('UPDATE PhysicalAction SET info = ?' 
    628                                           . 'WHERE action_id = ?'); 
    629              
    630             $update->execute( $row->{parentphys}, $child->{action_id} ); 
    631         } 
    632  
    633         if (scalar @$childrecs == 0) { 
    634             my $sql = <<"EOSQL"; 
     627        if (scalar @$childrecs >= 1) { 
     628            # only merge MOVE records that have the same timestamp 
     629            if ($row->{timestamp} == @$childrecs[0]->{timestamp}) { 
     630                $source = @$childrecs[0]->{parentphys}; 
     631                &DeleteChildRec(@$childrecs[0]->{action_id}); 
     632            } 
     633        } 
     634         
     635        my $sql = <<"EOSQL"; 
    635636UPDATE 
    636637    PhysicalAction 
    637638SET 
     639    actiontype = 'MOVE', 
    638640    parentphys = ?, 
    639     actiontype = 'MOVE', 
    640641    info = ? 
    641642WHERE 
    642643    action_id = ? 
    643644EOSQL 
    644             my $update; 
    645             $update = $gCfg{dbh}->prepare($sql); 
    646             $update->execute( undef, $row->{parentphys}, 
    647             $row->{action_id}); 
    648         } else { 
    649             push(@delchild, $row->{action_id}); 
    650         } 
    651     } 
    652  
    653     foreach $id (@delchild) { 
    654         &DeleteChildRec($id); 
    655     } 
     645        my $update; 
     646        $update = $gCfg{dbh}->prepare($sql); 
     647         
     648        $update->execute( $target, $source, $row->{action_id}); 
     649    } 
     650 
     651 
     652    # change all remaining MOVE_TO records into MOVE records and swap the src and target 
     653    $sth = $gCfg{dbh}->prepare('SELECT * FROM PhysicalAction ' 
     654                               . 'WHERE actiontype = "MOVE_TO"'); 
     655    $sth->execute(); 
     656    $rows = $sth->fetchall_arrayref( {} ); 
     657 
     658    foreach $row (@$rows) { 
     659        my $update; 
     660        $update = $gCfg{dbh}->prepare('UPDATE PhysicalAction SET ' 
     661                                      . 'actiontype = "MOVE", ' 
     662                                      . 'parentphys = ?, ' 
     663                                      . 'info = ? ' 
     664                                      . 'WHERE action_id = ?'); 
     665        $update->execute($row->{info}, $row->{parentphys}, $row->{action_id}); 
     666    } 
     667 
    656668 
    657669    1; 
     
    765777        # RENAME: the new name (without path) 
    766778        # SHARE: the source path which was shared 
    767         # MOVE: the new path 
     779        # MOVE: the old path 
    768780        # PIN: the path of the version that was pinned       
    769781        # LABEL: the name of the label 
     
    13341346        RestoredProject => {type => 1, action => 'RESTOREDPROJECT'}, 
    13351347        RenamedProject => {type => 1, action => 'RENAME'}, 
    1336         MovedProjectTo => {type => 1, action => 'MOVE'}, 
     1348        MovedProjectTo => {type => 1, action => 'MOVE_TO'}, 
    13371349        MovedProjectFrom => {type => 1, action => 'MOVE_FROM'}, 
    13381350        DeletedProject => {type => 1, action => 'DELETE'}, 

These ads are automatically generated by Google based on the content of this page. Revenue from these ads helps to pay for hosting fees of this site; however, these ads do not constitute an endorsement by PumaCode.org.