URL: https://linuxfr.org/users/zaurus/journaux/renommage-de-fichier-sous-cvs-script-bash Title: renommage de fichier sous CVS [script bash] Authors: zaurus Date: 2006年12月05日T17:19:40+01:00 Tags: Score: 0 Bonjour, On à eu un stagiaire ces jours-ci. Il a fait un script pour renommer des fichiers sous CVS (en conservant l'historique du fichier plus ses messages de commit). Vu que notre projet est sous CVS et qu'on ne peut pas passer sous un autre gestionnaire de version, ça nous est utile (et on n'a pas trouvé d'équivalent sur internet). Vos commentaires et améliorations sont les bienvenus. Merci, François. #!/bin/bash # Description: a tool to rename a file under CVS, without losing its history # and log history information # this software is under the GNU General Public License # Authors: Valentin Barbe and François Bérenger #set -x #echo "usage: cvs_move [old_name] [new_name] [--dry-run]" # we need at least 2 parameters if [ $# == 3 ] then £spaces£ £/spaces£if [ 3ドル == "--dry-run" ] £spaces£ £/spaces£then £spaces£ £/spaces£echo "cvs_name: here is what I plan to do:" £spaces£ £/spaces£DRY_RUN="echo" £spaces£ £/spaces£fi else £spaces£ £/spaces£echo "I am going to really do cvs manipulations, are you sure? {yes|no}" £spaces£ £/spaces£read ANSWER £spaces£ £/spaces£if [ $ANSWER == "yes" ] £spaces£ £/spaces£then £spaces£ £/spaces£DRY_RUN="" £spaces£ £/spaces£else £spaces£ £/spaces£echo "cvs_name: here is what I plan to do:" £spaces£ £/spaces£DRY_RUN="echo" £spaces£ £/spaces£fi fi if [[ $# < 2 ]] then £spaces£ £/spaces£echo "I need 2 parameters!" £spaces£ £/spaces£echo "usage: cvs_move [old_name] [new_name]" £spaces£ £/spaces£exit 1 fi # old_name must exist if [ ! -e 1ドル ] then £spaces£ £/spaces£echo 1ドル" does not exist!" £spaces£ £/spaces£echo "usage: cvs_move [old_name] [new_name]" £spaces£ £/spaces£exit 1 fi # old_name directory must exist if [ ! -e `dirname 2ドル` ] then £spaces£ £/spaces£echo 2ドル"'s directory doesn't exist!" £spaces£ £/spaces£echo "usage: cvs_move [old_name] [new_name]" £spaces£ £/spaces£exit 1 fi #maximum version number nb_version=`cvs status 1ドル | grep "Repository revision" | cut -f2` #get this version #get its log #create a shorter log prefixed by "cvs_move:" for i in `awk "BEGIN { for (i = 1.1 ; i <= \""$nb_version"\" ; i += 0.1) { printf (\"%.1f\n\", i) } }"` do £spaces£ £/spaces£cvs update -p -r $i 1ドル > 1ドル.v$i £spaces£ £/spaces£cvs log -h -r$i 1ドル > header_log £spaces£ £/spaces£cvs log -r$i 1ドル > complete_log £spaces£ £/spaces£comm -1 -3 header_log complete_log | awk '{print "cvs_move:"0ドル}' > log_1ドル.v$i done #create new_name and put it under CVS control $DRY_RUN cp 1ドル.v1.1 2ドル here=`pwd` there=`dirname 2ドル` $DRY_RUN cd $there ; $DRY_RUN cvs add `basename 2ドル` ; $DRY_RUN cd $here #commit each old_name version with its associated log into new_name for i in `ls 1ドル.v*` do £spaces£ £/spaces£$DRY_RUN cp -f $i 2ドル £spaces£ £/spaces£$DRY_RUN cd $there £spaces£ £/spaces£$DRY_RUN cvs commit -F $here/log_$i `basename 2ドル` £spaces£ £/spaces£$DRY_RUN cd $here done