package VCP::Filter::map; =head1 NAME VCP::Filter::map - rewrite name and branch number. =head1 SYNOPSIS ## From the command line: vcp map: p1 r1 p2 r2 -- ## In a .vcp file: Map: path_glob_1 path_out_1 path_glob_2 path_out_2 # ... etc ... =head1 DESCRIPTION Maps source files, revisions, and branches to destination files and branches while copying a repository. This is done by rewriting the name and branch_id of revisions according to a list of rules. =head2 Rules A rule is a pair of expressions specifying a pattern to match against the each incoming revision's name and branch_id and a result to use to replace the revision's name and branch_id. The list of rules is evaluated top down; the last rule in the list that matches is used to generate the new name and branch_id. There is a default rule that applies to all files Note that sorting is performed in the destination, so the map will affect the sort order and the original file name and branch_id are lost. =head2 Patterns and Rule Expressions Patterns and rules are composed of two subexpressions, the C and the C like so: path_expr The C<< >> (including angle brackets) is optional and may be forbidden by some sources or destinations that embed the concept of a branch in the path_part. (See L for an example, though this may be changed in the future). For now, the symbols C<#> and C<@> are reserved for future used in all expressions and must be escaped using C<\>, and various shell-like wildcards are implemented in pattern expressions. =head2 Pattern Expressions Both the C and C specify patterns using shell regular expression syntax with the extension that parenthesese are used to extract portions of the match in to numbered variables which may be used in the result construction, like Perl regular expressions: ? Matches one character other than "/" * Matches zero or more characters other than "/" ... Matches zero or more characters, including "/" (foo) Matches "foo" and stores it in the $1, $2, etc Some example pattern Cs are: Pattern path_expr Matches ========= ======= foo the top level file "foo" foo/bar the file "foo/bar" ... all files (like a missing path_expr) foo/... all files under "foo/" .../bar all files named "bar" anywhere */bar all files named "bar" one dir down ....pm all files ending in ".pm" ?.pm all top level 4 char files ending in ".pm" \?.pm the top level file "?.pm" (*)/... all files in subdirs, puts the top level dirname in $1 Unix-style slashes are used, even on operating systems where that may not be the preferred local custom. The characters C<#>, C<@>, C<[>, C<]>, C<{>, C<}>, C>, C> and C<$> are not permitted in pattern expressions and must be escaped using a C<\>, as must any wildcard characters meant to be taken literally (this is true in result expressions as well). Relative paths are taken relative to the rev_root indicated in the source specification for pattern Cs (or in the destination specification for result Cs). For now, a relative path is a path that does not begin with the character C, so be aware that the pattern C<(/)> is relative. This is a limitation of the implementation and may change, until it does, don't rely on a leading "(" making a path relative and use multiple rules to match multiple absolute paths. If no C is provided, C<...> is assumed and the pattern will match on all filenames. Some example pattern Cs are: Pattern branch_expr Matches files on =========== ================ <> no branch <...> all branches (like a missing branch "foo" branches beginning with "R" branches beginning with "R", the other chars in $1 If no C is provided, files on all branches are matched. C<*> and C<...> still match differently in pattern Cs, as in patterns, but this is likely to make no difference, as I've not yet seen a branch label with a "/" in it. Still, it is wise to avoid "*" in C patterns. Some example composite patterns are (any $ variables set are given in parenthesis): Pattern Matches ======= ======= foo<> top level files named "foo" not on a branch (...)<> all files not on a branch ($1) (...)/(...)<> all files not on a branch ($1,$2) ... all files on branch "R1" .../foo all files "foo" on branches beginning with "R" (...)/foo all files "foo" on branches beginning with "R" ($1, $2) =head2 Result Expressions Result expressions look a lot like patthern expressions except that wildcards are not allowed and C<$1> and C<${1}> style variable interpolation is. The characters C<@>, C<#>, C>, C> must be escaped, and C<$> must be escaped if meant to be taken literally. =head2 Command Line Parsing For large maps or repeated use, the map is best specified in a .vcp file. For quick one-offs or scripted situations, however, the map: scheme may be used on the command line. In this case, each parameter is a "word" and every pair of words is a ( pattern, result ) pair. Because L command line parsing is performed incrementally and the next filter or destination specifications can look exactly like a pattern or result, the special token "--" is used to terminate the list of patterns if map: is from on the command line. This may also be the last word in the C section of a .vcp file, but that is superfluous. It is an error to use "--" before the last word in a .vcp file. =for test_script t/61map.t =cut $VERSION = 1 ; use strict ; use VCP::Filter; use Getopt::Long; use base qw( VCP::Filter ); use fields ( 'MAP_RULES', ## The rules to apply ); sub new { my $class = shift ; $class = ref $class || $class ; my $self = $class->SUPER::new( @_ ) ; ## Parse the options my ( $spec, $options ) = @_ ; { local *ARGV = $options ; GetOptions( "NoFreakinOptionsAllowed" => \undef, ) or $self->usage_and_exit ; } while ( @$options && $options->[0] ne "--" ) { } return $self ; } sub handle_rev { my VCP::Filter::map $self = shift; $self->dest->handle_rev( @_ ); } =head1 AUTHOR Barrie Slaymaker =head1 COPYRIGHT Copyright (c) 2000, 2001, 2002 Perforce Software, Inc. All rights reserved. See L (C) for the terms of use. =cut 1