Changeset 800 for dasscm


Ignore:
Timestamp:
Nov 10, 2009, 6:00:44 PM (14 years ago)
Author:
joergs
Message:

added revert

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dasscm/trunk/dasscm

    r797 r800  
    9191    print "   add <path>\n";
    9292    print "   commit <path>\n";
     93    print "   revert <path>\n";
    9394    print "   diff <path>\n";
    9495    print "   status <path>\n";
     
    9798    print "   permissions\n";
    9899    print "\n";
    99     print "preparation:\n", "  if dasscm is already configured,\n",
    100       "  use 'dasscm login' and then eg. 'add'.\n",
    101       "  The environment variables\n", "    DASSCM_REPO\n", "    DASSCM_PROD\n",
    102       "    DASSCM_USERNAME\n", "    DASSCM_PASSWORD\n",
    103       "  are evaluated, but set automatically by 'dasscm login'.\n", "\n",
    104       "  If dasscm is not yet configured, read", "  $doc_file\n";
     100    print "If dasscm is not yet configured, read $doc_file\n";
    105101}
    106102
     
    321317    }
    322318
    323     if ( not -r $filename_prod ) {
    324         fatalerror( $filename_prod . " is not accessable" );
     319    # file must be readable. Only exception is, when file should be reverted
     320    if ( $command ne "revert" ) {
     321        if ( not -r $filename_prod ) {
     322            fatalerror( $filename_prod . " is not accessable" );
     323        }
    325324    }
    326325
     
    333332    ( my $basename, my $dirname_prod ) = fileparse($filename_prod);
    334333
    335     # uses chdir to determine real directory in a unique way
    336     chdir $dirname_prod or die $!;
    337     $dirname_prod = normalize_path( cwd() );
    338     chdir $StartDirectory;
     334    # normalize path.
     335    # not done for reverting, because in this case, the directory may not exist
     336    # and the correct path should already be stored in the repository
     337    if ( $command ne "revert" ) {
     338        # uses chdir to determine real directory in a unique way
     339        chdir $dirname_prod or fatalerror( "failed to access directory $dirname_prod: " . $! );
     340        $dirname_prod = normalize_path( cwd() );
     341        chdir $StartDirectory;
     342    }
    339343
    340344    my $dirname_repo  = normalize_path( $DASSCM_REPO . "/" . $dirname_prod );
     
    372376      or error "failed to copy $filename_prod to repository: $!";
    373377}
     378
    374379
    375380#
     
    639644                # remove it
    640645                print "removing $_\n";
    641                 unlink($_);
     646                # unlink doesn't work recursive, there "rm -rf" is used
     647                #unlink($_);
     648                system( "rm -rf $_" );
    642649            }
    643650        }
     
    10321039}
    10331040
    1034 sub blame(@)
     1041
     1042
     1043#
     1044# revert: copies files back from repository to system
     1045#
     1046sub revert(@)
    10351047{
    10361048    check_parameter( @_, 1 );
     
    10461058      = get_filenames( $_[0] );
    10471059
    1048     my $retcode = run_interactive("$SVN blame $svnOptions $filename_repo");
    1049 }
    1050 
    1051 sub diff(@)
     1060    # return code for the shell
     1061    # default: error
     1062    my $return_code = $RETURN_OK;
     1063
     1064
     1065    # cleanup repository
     1066    ##cleanup();
     1067    #svn_update();
     1068
     1069    ( my $refChangedFiles, my $refRemovedFiles, my $refUnknownFiles ) =
     1070      getModifiedFiles($filename_prod);
     1071    my %changedfiles = %{$refChangedFiles};
     1072    my %removedfiles = %{$refRemovedFiles};
     1073    my %unknownfiles = %{$refUnknownFiles};
     1074
     1075    if ( %removedfiles or %changedfiles or %unknownfiles ) {
     1076
     1077        if (%removedfiles) {
     1078            print "DELETED files and directories. Recreated from repository:\n";
     1079            my @removedPaths = ( sort { length $a > length $b } keys %removedfiles );
     1080            print join( "\n", @removedPaths ) . "\n\n";
     1081
     1082            # copy files one by one from local repository to system
     1083            # and also create directories
     1084            # paths are sorted, so that directories are created first
     1085            for my $real_path ( @removedPaths ) {
     1086                if( -d $removedfiles{"$real_path"} ) {
     1087                    mkpath("$real_path");
     1088                } else {
     1089                    copy( $removedfiles{"$real_path"}, $real_path ) or error( "failed to copy " .  $removedfiles{"$real_path"} . " to " . $real_path . ": " . $! );
     1090                }
     1091            }
     1092        }
     1093
     1094        if (%changedfiles) {
     1095            print "MODIFIED files. Copied from repository to the system:\n";
     1096            print join( "\n", ( keys %changedfiles ) ) . "\n\n";
     1097
     1098            # copy files one by one from local repository to system
     1099            for my $real_file ( keys(%changedfiles) ) {
     1100                copy( $changedfiles{"$real_file"}, $real_file );
     1101            }
     1102
     1103        }
     1104
     1105        if (%unknownfiles) {
     1106            print "UNKNOWN: insufficient permission to check files:\n";
     1107            print join( "\n", ( keys %unknownfiles ) ) . "\n\n";
     1108
     1109            $return_code = $RETURN_NOK;
     1110        }
     1111
     1112    } else {
     1113        print "no modified files found in $dirname_repo\n";
     1114    }
     1115
     1116    return $return_code;
     1117}
     1118
     1119
     1120
     1121sub blame(@)
    10521122{
    10531123    check_parameter( @_, 1 );
     
    10631133      = get_filenames( $_[0] );
    10641134
     1135    my $retcode = run_interactive("$SVN blame $svnOptions $filename_repo");
     1136}
     1137
     1138sub diff(@)
     1139{
     1140    check_parameter( @_, 1 );
     1141    check_env();
     1142
     1143    (
     1144        my $basename,
     1145        my $dirname_prod,
     1146        my $dirname_repo,
     1147        my $filename_prod,
     1148        my $filename_repo
     1149      )
     1150      = get_filenames( $_[0] );
     1151
    10651152    #print "$basename,$dirname_prod,$dirname_repo\n";
    10661153
     
    11101197        if (%removedfiles) {
    11111198            print "DELETED: files found in repository, but not in system:\n";
    1112             print join( "\n", ( keys %removedfiles ) ) . "\n\n";
     1199            print join( "\n", sort ( keys %removedfiles ) ) . "\n\n";
    11131200        }
    11141201
     
    13251412        $command = "commit";
    13261413        commit(@ARGV);
     1414    } elsif (m/^revert$/i) {
     1415        $command = "revert";
     1416        $return_code = revert(@ARGV);
    13271417    } elsif (m/^blame$/i) {
    13281418        $command = "blame";
     
    13491439        $return_code = $RETURN_NOK;
    13501440    }
    1351 
    1352     # revert
    1353 
    13541441}
    13551442
Note: See TracChangeset for help on using the changeset viewer.