Changeset 268 for trunk/dasscm


Ignore:
Timestamp:
Mar 3, 2009, 6:18:03 PM (15 years ago)
Author:
joergs
Message:

added command commitall

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dasscm/dasscm

    r267 r268  
    3636# commands that require write access (and therefore a login)
    3737# to the repository server
    38 my @COMMANDS_REQUIRE_WRITE = ( "add", "commit" );
     38my @COMMANDS_REQUIRE_WRITE = ( "add", "commit", "commitall" );
    3939
    4040# configuration file
     
    5050my $StartDirectory = cwd();
    5151
     52my $diff                   = "diff --exclude .svn ";
    5253my $SVN                    = "svn ";
    5354my $svnOptions             = "";
    5455my $svnCheckoutCredentials = "";
    5556my $svnPasswordCredentials = "";
    56 my $diff                   = "diff --exclude .svn ";
     57# flag. Set to true by svn_update
     58# This prevents, that svn_update is called multiple times
     59my $svnRepositoryIsUptodate = 0;
    5760
    5861# command line options get stored in options hash
     
    6164# subcommand, that gets executed (add, commit, ...)
    6265my $command;
     66
    6367
    6468my $verbose = 0;
     
    8286    print "   add <filename>\n";
    8387    print "   commit <filename>\n";
     88    print "   commitall\n";
    8489    print "   diff <filename>\n";
    8590    print "   status\n";
     
    455460sub svn_update( ;$ )
    456461{
    457     my $update_path = shift || $DASSCM_REPO;
    458     ( my $rc_update, my @result ) =
    459       run_command(
    460         "$SVN update --non-interactive $svnCheckoutCredentials $update_path");
    461     print @result;
    462     if ( $rc_update != 0 ) {
    463         fatalerror();
    464     }
    465 }
     462    if( ! $svnRepositoryIsUptodate ) {
     463        my $update_path = shift || $DASSCM_REPO;
     464        ( my $rc_update, my @result ) =
     465        run_command(
     466            "$SVN update --non-interactive $svnCheckoutCredentials $update_path");
     467        print @result;
     468        if ( $rc_update != 0 ) {
     469            fatalerror();
     470        } else {
     471            $svnRepositoryIsUptodate = 1;
     472        }
     473    }
     474}
     475
     476
    466477
    467478sub svn_getStoredFiles( ;$ )
     
    486497    return @result;
    487498}
     499
     500
     501sub getModifiedFiles( ;$ )
     502{
     503    # TODO: get_filenames?
     504    #my $rel_path = shift || "";
     505    #my $path = "${DASSCM_REPO}/${rel_path}";
     506    my $path = ${DASSCM_REPO};
     507    my @files = svn_getStoredFiles($path);
     508
     509    # stores result from status (cvscheck)
     510    my %removedfiles = ();
     511    my %changedfiles = ();
     512
     513    # create list of modified files
     514    if (@files) {
     515
     516        foreach my $file (@files) {
     517
     518            my $realfile    = "/" . $file;
     519            my $cvsworkfile = "${DASSCM_REPO}/${file}";
     520
     521            if ( -d $realfile ) {
     522                ## directory. do nothing
     523            } elsif ( !-r $realfile ) {
     524                $removedfiles{"$realfile"} = $cvsworkfile;
     525            } else {
     526                ( -r "$cvsworkfile" )
     527                  || die("Fehler: $cvsworkfile ist nicht lesbar");
     528                if ( compare( $cvsworkfile, $realfile ) != 0 ) {
     529                    $changedfiles{"$realfile"} = $cvsworkfile;
     530                }
     531            }
     532        }
     533    }
     534
     535    return ( \%changedfiles, \%removedfiles );
     536}
     537
    488538
    489539#
     
    692742}
    693743
     744
     745
    694746#
    695747# add (is used for command add and commit)
     
    720772    }
    721773
     774    # TODO: check in links and also link target? At least warn about link target
    722775    if (@links) {
    723776        my $number = $#links + 1;
     
    753806        "$SVN commit $svnOptions --username '$DASSCM_USERNAME' $svnPasswordCredentials $DASSCM_REPO"
    754807      );
    755 
    756     #print $filename_prod. "\n";
    757     #print $dirname_repo. "\n";
    758 }
     808}
     809
     810
     811
     812#
     813# checks in all modified files
     814#
     815sub commitall(@)
     816{
     817    check_parameter( @_, 1 );
     818    check_env();
     819
     820    # TODO: get_filenames?
     821    #my $rel_path = shift || "";
     822    #my $path = "${DASSCM_REPO}/${rel_path}";
     823    my $dir = ${DASSCM_REPO};
     824
     825    #
     826    # update local repository
     827    #
     828    svn_update();
     829
     830    ( my $refChangedFiles, my $refRemovedFiles ) = getModifiedFiles( $dir );
     831    my %changedfiles = %{$refChangedFiles};
     832    my %removedfiles = %{$refRemovedFiles};
     833
     834    if( %removedfiles ) {
     835        my $removedFilesString = '"' . join( '" "', values(%removedfiles) ) . '"';
     836        my ( $rc, @out ) = run_command( "$SVN rm $removedFilesString" );
     837        if ( $rc > 0 ) {
     838            print join( "\n", @out );
     839        }
     840    }
     841
     842    # add will care about the rest, including permission file and commiting
     843    add( keys %changedfiles );
     844}
     845
     846
    759847
    760848sub blame(@)
     
    819907    # TODO: start at subdirectories ?
    820908    my $dir   = $DASSCM_REPO;
    821     my @files = svn_getStoredFiles($dir);
    822 
    823     # Liste der geänderten Files ausgeben, falls nicht leer
    824     if (@files) {
    825 
    826         # stores result from status (cvscheck)
    827         my %removedfiles = ();
    828         my %changedfiles = ();
    829 
    830         foreach my $file (@files) {
    831 
    832             my $realfile    = "/" . $file;
    833             my $cvsworkfile = "${DASSCM_REPO}/${file}";
    834 
    835             if ( -d $realfile ) {
    836 
    837                 # directory. do nothing
    838             } elsif ( !-r $realfile ) {
    839                 $removedfiles{"$realfile"} = $cvsworkfile;
    840             } else {
    841                 ( -r "$cvsworkfile" )
    842                   || die("Fehler: $cvsworkfile ist nicht lesbar");
    843                 if ( compare( $cvsworkfile, $realfile ) != 0 ) {
    844                     $changedfiles{"$realfile"} = $cvsworkfile;
    845                 }
    846             }
    847         }
    848 
     909    ( my $refChangedFiles, my $refRemovedFiles ) = getModifiedFiles( $dir );
     910    my %changedfiles = %{$refChangedFiles};
     911    my %removedfiles = %{$refRemovedFiles};
     912
     913    if( %removedfiles or %changedfiles ) {
    849914        if (%removedfiles) {
    850915            print "deleted files (found in repository, but not in system):\n";
     
    866931    }
    867932
    868     print "\n";
    869 
    870933    return $return_code;
    871934}
     935
     936
    872937
    873938sub permissions(@)
     
    918983    }
    919984}
     985
     986
    920987
    921988#####################################################################
     
    9871054        $command = "update";
    9881055        update(@ARGV);
     1056    } elsif ( (m/commitall/i) || (m/cia/i) ) {
     1057        $command = "commitall";
     1058        commitall(@ARGV);
    9891059    } elsif (m/add/i) {
    9901060        $command = "add";
    9911061        add(@ARGV);
    992     } elsif ( (m/commit/i) || (m/ci/i) ) {
     1062    } elsif ( (m/commit/i) || (m/checkin/i) || (m/ci/i) ) {
    9931063        $command = "commit";
    9941064        add(@ARGV);
     
    10131083
    10141084    # cleanup (svn-commit.tmp)
    1015     # commitall
    10161085    # revert
    10171086    # activate
Note: See TracChangeset for help on using the changeset viewer.