package VCP::Dest::vss ; =head1 NAME VCP::Dest::vss - vss destination driver =head1 SYNOPSIS vcp <source> vss:module vcp <source> vss:VSSROOT:module where module is a module or directory that already exists within VSS. This destination driver will check out the indicated destination in a temporary directory and use it to add, delete, and alter files. =head1 DESCRIPTION B<Experimental>. See L<NOTES|/NOTES> for details. This driver allows L<vcp|vcp> to insert revisions in to a VSS repository. There are no options at this time. =cut $VERSION = 1 ; use strict ; use vars qw( $debug ) ; $debug = 0 ; use Carp ; use File::Basename ; use File::Path ; use VCP::Debug ':debug' ; use VCP::Rev ; use File::Spec ; use File::Spec::Unix ; use base qw( VCP::Dest VCP::Utils::vss ) ; use fields ( 'VSS_FILES', ## HASH of all VSS files, managed by VCP::Utils::vss 'VSS_CHECKED_OUT', ## HASH of whether or not a file has been checked out. ) ; ## Optimization note: The slowest thing is the call to "vss commit" when ## something's been added or altered. After all the changed files have ## been checked in by VSS, there's a huge pause (at least with a VSSROOT ## on the local filesystem). So, we issue "vss add" whenever we need to, ## but we queue up the files until a non-add is seem. Same for when ## a file is edited. This preserves the order of the files, without causing ## lots of commits. Note that we commit before each delete to make sure ## that the order of adds/edits and deletes is maintained. #=item new # #Creates a new instance of a VCP::Dest::vss. Contacts the vssd using the vss #command and gets some initial information ('vss info' and 'vss labels'). # #=cut sub new { my $class = shift ; $class = ref $class || $class ; my VCP::Dest::vss $self = $class->SUPER::new( @_ ) ; ## Parse the options my ( $spec, $options ) = @_ ; $self->parse_repo_spec( $spec ) ; $self->repo_id( "vss:" . $self->repo_server ); $self->deduce_rev_root( $self->repo_filespec ) ; $self->parse_options( $options, "NoFreakinOptionsAllowed" => \undef, ); ## We need to know about the hierarchy under the target path. my $dest_path = $self->repo_filespec; $dest_path =~ s{([\\/]|[\\/](\.\.\.|\*\*))?\z}{/...}; $self->get_vss_file_list( $dest_path ); return $self ; } sub handle_header { my VCP::Dest::vss $self = shift ; debug "vcp: first rev" if debugging $self ; $self->rev_root( $self->header->{rev_root} ) unless defined $self->rev_root ; $self->create_vss_workspace ; $self->{VSS_CHECKED_OUT} = {}; $self->SUPER::handle_header( @_ ) ; } sub checkout_file { my VCP::Dest::vss $self = shift ; my VCP::Rev $r ; ( $r ) = @_ ; debug "vcp: checking out ", $r->as_string, " from vss dest repo" if debugging $self ; my $fn = $self->denormalize_name( $r->name ) ; my $work_path = $self->work_path( "co", $fn ) ; debug "vcp: work_path '$work_path'" if debugging $self ; my $saw = $self->last_seen( $r ) ; Carp::confess "Can't backfill already seen file '", $r->name, "'" if $saw ; die "Can't backfill already seen file '", $r->name, "'" if $saw ; my ( $file, $work_dir ) = fileparse( $work_path ) ; $self->mkpdir( $work_path ) unless -d $work_dir ; $work_dir =~ s{[\\/]+$}{}g; # my $tag = "r_" . $r->rev_id ; # $tag =~ s/\W+/_/g ; # my ( undef, $dirs ) = fileparse( $fn ); $self->ss( [ "cp", "\$/$dirs" ] ); ## This -GN is a hack; it's here because the test suite uses ## Unix lineends and the checksums require it. $self->ss( [ "Get", $file, "-GL$work_dir", "-GN" ] ); die "'$work_path' not created by vss checkout" unless -e $work_path ; return $work_path ; } sub handle_rev { my VCP::Dest::vss $self = shift ; my VCP::Rev $r ; ( $r ) = @_ ; $self->compare_base_revs( $r ) if $r->is_base_rev && defined $r->work_path ; ## Don't save the reference. This forces the DESTROY to happen here, ## if possible. TODO: Keep VCP::Rev from deleting files prematurely. my $saw = ! ! $self->last_seen( $r ); return if $r->is_base_rev ; my $fn = File::Spec->catfile( $self->rev_root, $r->name ); my $work_path = $self->work_path( "co", $fn ) ; my ( $vol, $work_dir, undef ) = File::Spec->splitpath( $work_path ) ; $work_dir = File::Spec->catpath( $vol, $work_dir, "" ); $self->mkdir( $work_dir ); $work_dir =~ s{[\\/]+$}{}; ## vss is picky about trailing slashes in -GLpath if ( -e $work_path ) { unlink $work_path or die "$! unlinking $work_path" ; } ## Add the directories we need to VSS as projects my ( $file, $dirs ) = fileparse( $fn ); $dirs =~ s{\\}{/}g; ## Make debugging output pretty, ss is cool with / { my @dirs = File::Spec::Unix->splitdir( $dirs ); shift @dirs while @dirs && ! length $dirs[0]; pop @dirs while @dirs && ! length $dirs[-1]; my $cur_project = ""; for ( @dirs ) { $cur_project .= "/" if length $cur_project; $cur_project .= $_; unless ( $self->vss_file( $cur_project ) ) { $self->ss( [ "Create", "\$/$cur_project", "-C-" ] ); $self->vss_file( $cur_project, "project" ); } } } $self->ss( [ "cp", "\$/$dirs" ] ); if ( $r->action eq "delete" ) { $self->ss( [ 'Delete', $file, "-I-y" ], stderr_filter => qr{^You have.*checked out.*Y[\r\n]*$}s, ); $self->vss_file( $fn, 0 ); $self->{VSS_CHECKED_OUT}->{$fn} = 0; ## TODO: Restore the file instead of adding it if it comes back? } else { debug "vcp: linking ", $r->work_path, " to $work_path" if debugging $self ; link $r->work_path, $work_path or die "$! linking '", $r->work_path, "' -> $work_path" ; if ( defined $r->mod_time ) { utime $r->mod_time, $r->mod_time, $work_path or die "$! changing times on $work_path" ; } my $comment_flag = "-C-"; if ( defined $r->comment ) { my $cfn = $self->work_path( "comment.txt" ) ; open COMMENT, ">$cfn" or die "$!: $cfn"; print COMMENT $r->comment or die "$!: $cfn"; close COMMENT or die "$!: $cfn"; $comment_flag = "-C\@$cfn"; } my $check_it_in = 1; if ( ! $self->{VSS_CHECKED_OUT}->{$fn} ) { my $bin_flag = $r->type ne "text" ? "-B" : "-B-"; # my $tmp_f = $self->command_stderr_filter; # $self->command_stderr_filter( # qr{^A deleted file of the same name already exists.*|[\r\n]*$}s # ) ; my $stderr = ""; if ( ! $self->vss_file_is_active( $fn ) ) { ## If the file has been deleted before, -I-y causes ss to recover it ## instead of adding it anew. $check_it_in = 0; $self->ss( [ "Add", $work_path, "-K", $bin_flag, $comment_flag, "-I-y" ], '2>', \$stderr, ); } if ( $stderr =~ /A deleted file of the same name already exists/ ) { $check_it_in = 1; $self->ss( [ "Checkout", $file, "-G-" ] ); } elsif ( length $stderr ) { die "unexpected stderr from ss Add:\n", $stderr; } $self->vss_file( $fn, "file" ); $self->{VSS_CHECKED_OUT}->{$fn}++; # $self->command_stderr_filter( $tmp_f ); } if ( $check_it_in ) { ## TODO: Don't assume same filesystem or working link(). $self->ss( [ "Checkin", $file, "-GL$work_dir", "-K", "-I-y", $comment_flag ], stderr_filter => qr{^.*was checked out from.*not from the current folder\.\r?\nContinue.*\r?\n}, ); } my @labels = map { s/^([^a-zA-Z])/tag_$1/ ; s/\W/_/g ; $_ ; }( $r->labels, ## Put the existing label (if any) first defined $r->rev_id ? "r_" . $r->rev_id : (), defined $r->change_id ? "ch_" . $r->change_id : (), ) ; my $version; $self->ss( [ "cp", "\$/$dirs" ] ); $self->ss( [ "History", $file, "-#1" ], ">", \$version ); undef $version unless $version =~ s/.*^\*+\s+Version\s+(\d+)\s+\*+$(.*)/$1/ms; ## Don't replace existing labels; this can happen if the version ## was recovered from a previous delete, for instance. undef $version if $2 =~ /^Label:\s+/m; for ( @labels ) { $self->ss( [ "Label", $file, "-L$_", "-C-", "-I-y", ## Yes, please reuse the label defined $version ? "-V$version" : () ]); undef $version; } } } =head1 TODO This module is here purely to support the VCP test suite, which must import a bunch of files in to VSS before it can test the export. It works, but is not field tested. While I'm sure there exist pressing reasons for importing files in to VSS from other repositories, I have never had such a request and do not wish to invest a lot of effort in advance of such a request. Therefore, this module does not batch checkins, cope with branches, optimize comment settings, etc. Patches or contracts welcome. =head1 NOTES VSS does not flag individual revisions as binary vs. text; the change is made on a per-file basis. This module does not alter the filetype on C<Checkin>, however it does set binary (-B) vs. text (-B-) on C<Add>. VSS allows one label per file, and adding a label (by default) causes a new versions of the file. This module adds the first label it receives for a file (which is first may or may not be predictable depending on the source repository) to the existing version unless the existing version already has a label, then it just adds new versions as needed. This leads to the backfilling issue: when backfilling, there are no labels to request, so backfilling always assumes that the most recent rev is the base rev for incremental imports. The C<ss Delete> command does not allow a comment. Files are recalled from deleted status when added again if they were deleted. =head1 AUTHOR Barrie Slaymaker <barries@slaysys.com> =head1 COPYRIGHT Copyright (c) 2000, 2001, 2002 Perforce Software, Inc. All rights reserved. See L<VCP::License|VCP::License> (C<vcp help license>) for the terms of use. =cut 1
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#31 | 4497 | Barrie Slaymaker |
- --rev-root documented - All destinations handle rev_root defaulting now |
||
#30 | 4021 | Barrie Slaymaker |
- Remove all phashes and all base & fields pragmas - Work around SWASHGET error |
||
#29 | 4012 | Barrie Slaymaker | - Remove dependance on pseudohashes (deprecated Perl feature) | ||
#28 | 3921 | Barrie Slaymaker |
- VCP::Source::vss uses "0." and "1." prefixes on all rev_ids to properly handle VSS's idea of deleted files. - VCP::Dest::vss now offers --dont-recover-deleted-files to allow VSS-like sources to be trasnferred more completely |
||
#27 | 3908 | Barrie Slaymaker | - Debugging cleanups | ||
#26 | 3864 | Barrie Slaymaker | - UI tweaks | ||
#25 | 3855 | Barrie Slaymaker |
- vcp scan, filter, transfer basically functional - Need more work in re: storage format, etc, but functional |
||
#24 | 3850 | Barrie Slaymaker | - No longer stores all revs in memory | ||
#23 | 3813 | Barrie Slaymaker | - VCP::Rev::previous() is no more | ||
#22 | 3812 | Barrie Slaymaker | - VCP::Dest::* no longer need VCP::Rev->previous() | ||
#21 | 3811 | Barrie Slaymaker | - fetch_*() and get_rev() renamed get_source_file() | ||
#20 | 3805 | Barrie Slaymaker | - VCP::Revs::fetch_files() removed | ||
#19 | 3751 | Barrie Slaymaker | - VCP::Dest::vss dies if a file is branched to itself | ||
#18 | 3750 | Barrie Slaymaker | - VCP::Dest::vss fetches source files | ||
#17 | 3706 | Barrie Slaymaker | - VCP gives some indication of output progress (need more) | ||
#16 | 3677 | Barrie Slaymaker |
- rev_root sanity check is now case insensitive on Win32 - Parens in source filespecs are now treated as regular characters, not capture groups - ** is not treated as '...' |
||
#15 | 3496 | Barrie Slaymaker | - VSS branching | ||
#14 | 3460 | Barrie Slaymaker |
- Revamp Plugin/Source/Dest hierarchy to allow for reguritating options in to .vcp files |
||
#13 | 3454 | Barrie Slaymaker | - Submit branches using "Share -E" and "Checkout" | ||
#12 | 3433 | Barrie Slaymaker | - Merge in new VSS code. | ||
#11 | 3286 | John Fetkovich |
In 'sub new' constructors of vss source and dest with a new sub, parse_vss_repo_spec in Utils/vss.pm. This also will set the repo_id. Only call parse_vss_repo_spec if the $spec is non-empty. |
||
#10 | 3279 | John Fetkovich | split 'sub init' out from 'sub new' | ||
#9 | 3155 | Barrie Slaymaker |
Convert to logging using VCP::Logger to reduce stdout/err spew. Simplify & speed up debugging quite a bit. Provide more verbose information in logs. Print to STDERR progress reports to keep users from wondering what's going on. Breaks test; halfway through upgrading run3() to an inline function for speed and for VCP specific features. |
||
#8 | 2838 | John Fetkovich | Use parse_options rather than using Getopt::Long directly. | ||
#7 | 2802 | John Fetkovich |
Added a source_repo_id to each revision, and repo_id to each Source and Dest. The repo_ids include repository type (cvs,p4,revml,vss,...) and the repo_server fields. Changed the $self->...->set() and $self->...->get() lines in VCP::Dest::* to pass in a conglomerated key value, by passing in the key as an ARRAY ref. Also various restructuring in VCP::DB.pm, VCP::DB_file.pm and VCP::DB_file::sdbm.pm related to this change. |
||
#6 | 2389 | John Fetkovich |
removed calls to methods: command_stderr_filter command_ok_result_codes command_chdir and replaced with named Plugin::run_safely method parameters stderr_filter ok_result_codes in_dir respectively, where possible. |
||
#5 | 2042 | Barrie Slaymaker | Basic source::p4 branching support | ||
#4 | 2009 | Barrie Slaymaker |
lots of fixes, improve core support for branches and VCP::Source::cvs now supports branches. |
||
#3 | 1855 | Barrie Slaymaker |
Major VSS checkin. Works on Win32 |
||
#2 | 1822 | Barrie Slaymaker |
Get all other tests passing but VSS. Add agvcommenttime sort field. |
||
#1 | 1810 | Barrie Slaymaker | Preliminary VSS checkin |