Changeset 271 for trunk/dasscm


Ignore:
Timestamp:
Mar 4, 2009, 9:40:36 PM (15 years ago)
Author:
joergs
Message:

added specific function commit, to handle things more like plain svn

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dasscm/dasscm

    r270 r271  
    323323
    324324
     325sub copy_file_to_repository( $ )
     326{
     327    my $filename = shift;
     328
     329    (
     330        my $basename,
     331        my $dirname_prod,
     332        my $dirname_repo,
     333        my $filename_prod,
     334        my $filename_repo
     335    )
     336    = get_filenames( $filename );
     337
     338    # TODO: are permissions also copied?
     339
     340    print "$filename: $filename_prod, $filename_repo\n";
     341    copy( $filename_prod, $filename_repo )
     342        or error "failed to copy $filename_prod to repository: $!";
     343}
     344
    325345
    326346#
     
    494514
    495515
    496 sub svn_getStoredFiles( ;@ )
     516sub svn_ls( ;@ )
    497517{
    498518    (
     
    508528    # ( my $rc, my @result ) = run_command("$SVN ls --recursive $svnCheckoutCredentials $path");
    509529
    510     # without the last true, run_command returns an error, if result is empty (?)
    511     # TODO: replace by perl find
    512     ( my $rc, my @result ) =
    513       run_command(
    514         "cd $dirname_repo && find | grep -v '/.svn' | sed -e 's|\.\\/||' | grep -v '^[\.]\$'; true"
    515       );
    516     if ( $rc != 0 ) {
    517         print @result;
    518         fatalerror('failed to get stored files');
    519     }
    520     chomp(@result);
    521     return @result;
     530    my @files  = ();
     531    my @links  = ();
     532    my @dirs   = ();
     533    my @others = ();
     534
     535    if( -f $filename_prod ) {
     536        @files = ( $filename_prod );
     537    } elsif ( -d $dirname_repo ) {
     538        find(
     539            {
     540                wanted => sub {
     541                    my $name = $File::Find::name;
     542                    $name =~ s|^$dirname_repo||;
     543                    if ( $name =~ m/\.svn/ ) {
     544                        # skip svn meta data
     545                    } elsif ( -l $_ ) {
     546   
     547                        # soft link
     548                        # important: check for links first
     549                        #   to exclude them from further checks
     550                        push( @links, $name );
     551                    } elsif ( -d $_ ) {
     552   
     553                        # directories
     554                        push( @dirs, $name );
     555                    } elsif ( -f $_ ) {
     556   
     557                        # regular file
     558                        push( @files, $name );
     559                    } else {
     560                        push( @others, $name );
     561                    }
     562                    }
     563            },
     564            ( $dirname_repo )
     565        );
     566    }
     567
     568    return @files;
    522569}
    523570
     
    534581      = get_filenames( $_[0] );
    535582
    536     my @files = svn_getStoredFiles( $dirname_prod );
     583    my @files = svn_ls( $filename_prod );
    537584
    538585    # stores result from status (cvscheck)
     
    545592        foreach my $file (@files) {
    546593
    547             my $realfile    = "/" . $file;
    548             my $cvsworkfile = "${DASSCM_REPO}/${file}";
     594            my $realfile    = $dirname_prod . $file;
     595            my $cvsworkfile = $dirname_repo . $file;
    549596
    550597            if ( -d $realfile ) {
     
    590637                        push( @links, $fullname );
    591638                    } elsif ( -d $_ ) {
     639
     640                        # directories
    592641                        push( @dirs, $fullname );
    593642                    } elsif ( -f $_ ) {
     
    706755    check_env();
    707756
    708     my @files = svn_getStoredFiles(@_);
     757    my @files = svn_ls(@_);
    709758
    710759    print join( "\n", @files );
     
    870919
    871920
     921#
     922# checks in all modified files
     923#
     924sub commit(@)
     925{
     926    check_parameter( @_, 1 );
     927    check_env();
     928
     929    (
     930        my $basename,
     931        my $dirname_prod,
     932        my $dirname_repo,
     933        my $filename_prod,
     934        my $filename_repo
     935    )
     936    = get_filenames( $_[0] );
     937
     938
     939    #
     940    # update local repository
     941    #
     942    svn_update();
     943
     944    ( my $refChangedFiles, my $refRemovedFiles ) = getModifiedFiles( $filename_prod );
     945    my %changedfiles = %{$refChangedFiles};
     946    my %removedfiles = %{$refRemovedFiles};
     947
     948    if( %removedfiles ) {
     949        my $removedFilesString = '"' . join( '" "', values(%removedfiles) ) . '"';
     950        my ( $rc, @out ) = run_command( "$SVN rm $removedFilesString" );
     951        if ( $rc > 0 ) {
     952            print join( "\n", @out );
     953        }
     954    }
     955
     956    # copy files one by one to local repository
     957    for my $file ( keys(%changedfiles) ) {
     958        copy_file_to_repository( $file );
     959    }
     960
     961    # create new permissions file
     962    permissions();
     963
     964    # add permissions file
     965    add_helper($permissions_file);
     966
     967    if ( $options{'message'} ) {
     968        $svnOptions .= " --message \"$options{'message'}\" ";
     969    }
     970
     971    # commit calls $EDITOR.
     972    # use "interactive" here, to display output
     973    my $retcode =
     974      run_interactive(
     975        "$SVN commit $svnOptions --username '$DASSCM_USERNAME' $svnPasswordCredentials $DASSCM_REPO"
     976      );
     977}
     978
     979
     980
    872981sub blame(@)
    873982{
     
    9791088
    9801089    my $dir   = $DASSCM_REPO;
    981     my @files = svn_getStoredFiles( "/" );
     1090    my @files = svn_ls( "/" );
    9821091
    9831092    if (@files) {
     
    10931202    } elsif ( (m/commit/i) || (m/checkin/i) || (m/ci/i) ) {
    10941203        $command = "commit";
    1095         add(@ARGV);
     1204        commit(@ARGV);
    10961205    } elsif (m/blame/i) {
    10971206        $command = "blame";
Note: See TracChangeset for help on using the changeset viewer.