Changeset 237 for trunk/dasscm


Ignore:
Timestamp:
Oct 8, 2008, 8:49:03 PM (16 years ago)
Author:
joergs
Message:

handle directories in add

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dasscm/dasscm

    r236 r237  
    1212use File::Compare;
    1313use File::Copy;
     14use File::Find;
    1415use File::stat;
    1516use File::Path;
     
    3637my $svnCheckoutCredentials = "";
    3738my $svnPasswordCredentials = "";
     39my $DIFF                   = "diff --exclude .svn ";
    3840
    3941# command line options get stored in options hash
     
    218220{
    219221    my $filename_prod = $_[0];
     222
     223    # remove leading './' from relative directories
     224    #$filename_prod =~ s/^\.\///;
     225
    220226    if ( !( $filename_prod =~ m/^\// ) ) {
    221227        $filename_prod = cwd() . "/" . $filename_prod;
     
    224230    if( not -r $filename_prod ) {
    225231        fatalerror( $filename_prod  . " is not accessable" );
    226     } elsif( -l $filename_prod ) {
    227         my $dest = readlink($filename_prod);
    228         # TODO:
    229         #   default: disallow, but offer cmd switch to activate
    230         #   (or check, if file is already checked in and has been a link before)
    231         warning( "'$filename_prod' is a link to '$dest'.", "Please check, if '$dest' should be stored in repository instead" );
    232         if( ! -f $dest ) {
    233             fatalerror( "link target '$dest' is not a regular file. Giving up" );
    234         }
    235     } elsif( ! -f $filename_prod ) {
    236         fatalerror( $filename_prod . " is not a regular file. Only regular files can be checked in." );
    237     }
     232    }
     233    #      elsif( -l $filename_prod ) {
     234    #         my $dest = readlink($filename_prod);
     235    #         # TODO:
     236    #         #   default: disallow, but offer cmd switch to activate
     237    #         #   (or check, if file is already checked in and has been a link before)
     238    #         warning( "'$filename_prod' is a link to '$dest'.", "Please check, if '$dest' should be stored in repository instead" );
     239    #         if( ! -f $dest ) {
     240    #             fatalerror( "link target '$dest' is not a regular file. Giving up" );
     241    #         }
     242    #     } elsif( ! -f $filename_prod ) {
     243    #         #fatalerror( $filename_prod . " is not a regular file" );
     244    #     }
    238245
    239246    # TODO: dirname buggy: eg. "/etc/" is reduced to "/",
    240247    #   "/etc" is used as filename
    241248    my $dirname_prod = dirname($filename_prod);
     249    my $oldpath = cwd();
    242250    chdir $dirname_prod or die $!;
    243251    $dirname_prod = cwd();
     252    chdir $oldpath;
    244253    my $basename = basename($filename_prod);
    245254
     
    407416}
    408417
     418
     419sub get_files( @ )
     420{
     421    my @files  = ();
     422    my @links  = ();
     423    my @dirs   = ();
     424    my @others = ();
     425
     426    if( @_ ) {
     427        find( { wanted => sub {
     428            my $fullname = cwd() . "/" . $_;
     429            if ( -l $_ ) {
     430                # soft link
     431                # important: check for links first
     432                #   to exclude them from further checks
     433                push( @links, $fullname );
     434            } elsif ( -d $_ ) {
     435                push( @dirs, $fullname );
     436            } elsif( -f $_ ) {
     437                # regular file
     438                push( @files, $fullname );
     439            } else {
     440                push( @others, $fullname );
     441            }
     442        } }, @_ );
     443    }
     444
     445    # don't rely on others.
     446    # If more specific file types are needed,
     447    # they will be added
     448    return {
     449        files   => \@files,
     450        links   => \@links,
     451        dirs    => \@dirs,
     452        others  => \@others
     453     };
     454}
     455
     456
     457
    409458#####################################################################
    410459#
     
    502551}
    503552
     553
     554
     555#
     556# helper function for "add" command
     557#
    504558sub add_helper(@)
    505559{
     
    517571    }
    518572
    519     copy( $filename_prod, $filename_repo ) or die "failed to copy $filename_prod to repository: $!";
     573    copy( $filename_prod, $filename_repo ) or error "failed to copy $filename_prod to repository: $!";
    520574
    521575    if ( $command eq "add" ) {
    522576
     577        my $oldpath = cwd();
    523578        # already checked in?
    524579        chdir($DASSCM_REPO);
     
    538593            print join( "\n", @out );
    539594        }
    540     }
    541 }
     595        chdir($oldpath);
     596    }
     597}
     598
    542599
    543600#
     
    554611    svn_update();
    555612
    556     # TODO: check all files
    557 
    558     for my $file (@_) {
     613    # get all regular files and links
     614    my $href_files = get_files( @_ );
     615
     616    #print Dumper( $href_files );
     617
     618    my @files = @{$href_files->{files}};
     619    my @links = @{$href_files->{links}};
     620
     621    if( @files ) {
     622        my $number = $#files + 1;
     623        print "files to check-in ($number): \n";
     624        print join( "\n", @files );
     625        print "\n";
     626    }
     627
     628    if( @links ) {
     629        my $number = $#links + 1;
     630        print "\n";
     631        print "ignoring links ($number):\n";
     632        print join( "\n", @links );
     633        print "\n";
     634    }
     635
     636    # copy files one by one to local repository
     637    for my $file (@files) {
    559638        # add file
    560639        add_helper( $file );
     
    571650    }
    572651
    573     # commit calls $EDITOR. uses "interactive" here, to display output
     652    # commit calls $EDITOR.
     653    # use "interactive" here, to display output
    574654    my $retcode =
    575655      run_interactive(
     
    621701
    622702    ( my $rc_diff, my @diff ) =
    623       run_command("diff $filename_repo $filename_prod");
     703      run_command( $DIFF . " $filename_repo $filename_prod");
    624704    print @diff;
    625705}
Note: See TracChangeset for help on using the changeset viewer.