From 9302bdcdf624c514659addbc7a43ebd93dc57f43 Mon Sep 17 00:00:00 2001 From: thierry Date: Mon, 3 Sep 2007 10:56:16 +0000 Subject: [PATCH 1/1] tag function : commit all relevant *-tags.mk in a single commit -- various other minor improvements --- scripts/import-module.sh | 210 +++++++++++++++++++++------------------ 1 file changed, 111 insertions(+), 99 deletions(-) diff --git a/scripts/import-module.sh b/scripts/import-module.sh index 32e4c36..121d5be 100755 --- a/scripts/import-module.sh +++ b/scripts/import-module.sh @@ -6,108 +6,109 @@ date=$(date +%Y-%m-%d) #### REVIEW this carefully -cvstag=planetlab-4_0-rc3 +# to be provided on the command line +#cvstag=planetlab-4_0-rc3 #### svn="svn+ssh://thierry@svn.one-lab.org/svn" cvs=":pserver:anon@cvs.planet-lab.org:/cvs" function message () { - echo -n '-------------------- ' - echo $@ - echo -n 'Enter return to proceed .. ' - read x + echo '===' $@ } function run () { - echo -n '-------------------- ' - message="$1" ; shift - echo $message - - echo -n 'PWD=' ; pwd - echo RUNNING $@ - $@ + message="$1" ; shift + echo '===' $message + + echo "= In $(pwd)" + echo RUNNING $@ + $@ } +# returns 1 for true and 0 for no +function my_prompt () { + default="$1" ; shift + question="$@" ; shift + case "$default" in + y|Y) label="[y]/n" ; retcod=1 ;; + n|N) label="y/[n]" ; retcod=0 ;; + *) label="y/n (no default)" ;; + esac + + while true; do + echo "= In $(pwd)" + echo -n "$question $label ? " + read answer + case $answer in + y|Y) + return 1 ; break ;; + n|N) + return 0 ; break ;; + '') + return $retcod ; break ;; + *) + echo 'Please enter y or n' ;; + esac + done +} + function run_prompt () { - default="$1" ; shift - message="$1" ; shift - case "$default" in - y|Y) label="[y]/n" ;; - n|N) label="y/[n]" ;; - *) label="y/n (no default)" ;; - esac - - echo -n '-------------------- ' - echo $message - - echo -n 'PWD= ' ; pwd - echo -n "want to run $@ $label ? " - read answer - [ -z "$answer" ] && answer=$default - while true; do - case $answer in - y|Y) + default="$1" ; shift + message="$1" ; shift + prompt_message="want to run $@" + + echo "===" $message + my_prompt "$default" "$prompt_message" + if [ "$?" == 1 ] ; then $@ - break - ;; - n|N) + else echo 'Skipped' - break - ;; - *) - echo 'Please enter y or n' - ;; - esac - done + fi } function run_loop () { - message="$1" ; shift - while true; do - echo -n '-------------------- ' - echo $message - echo -n PWD= ; pwd - echo Running $@ - $@ - echo -n 'OK ? y/[n] ' - read answer - [ -z "$answer" ] && answer=n - case $answer in - y|Y) - break ;; - *) ;; - esac -done + default=$1; shift + message="$1" ; shift + while true; do + echo '===' $message + echo "= In $(pwd)" + echo Running $@ + $@ + my_prompt $default "OK" + if [ "$?" == 1 ] ; then + break + fi + done } ### echoes OK on stdout if url exists function svn_url_check () { - url=$1; shift - svn list $url &> /dev/null && echo OK + url=$1; shift + svn list $url &> /dev/null && echo OK } ### return 'y' or 'n' for being used as prompt function svn_url_needs_creation () { - url=$1; shift - if [ -n "$(svn_url_check $url)" ] ; then echo n ; else echo y ; fi + url=$1; shift + if [ -n "$(svn_url_check $url)" ] ; then echo n ; else echo y ; fi } function dir_needs_creation () { - dir=$1; shift - if [ -d "$dir" ] ; then echo n ; else echo y ; fi + dir=$1; shift + if [ -d "$dir" ] ; then echo n ; else echo y ; fi } function svn_dir_needs_revert () { - dir=$1; shift - output=$(svn status $dir 2>&1) - if [ -n "$output" ] ; then echo y ; else echo n ; fi + dir=$1; shift + output=$(svn status $dir 2>&1) + if [ -n "$output" ] ; then echo y ; else echo n ; fi } function svn_file_needs_commit () { - dir=$1; shift - output=$(svn status $dir 2>&1) - if [ -n "$output" ] ; then echo y ; else echo n ; fi + dir=$1; shift + output=$(svn status $dir 2>&1) + if [ -n "$output" ] ; then echo y ; else echo n ; fi } ############################## @@ -121,7 +122,7 @@ function figure_module_spec () { else nbspecs=$(ls $src/*.spec | wc -l) if [ $nbspecs = 1 ] ; then - echo $(ls $src/*.spec) + echo $(ls $src/*.spec) else echo "$0: could not guess spec file in $src" exit 1 @@ -133,8 +134,8 @@ function extract_from_spec () { specfile=$1; shift varname=$1; shift if [ ! -f $specfile ] ; then - echo "Could not locate $specfile -- exiting" - exit 1 + echo "Could not locate $specfile -- exiting" + exit 1 fi line=$(grep "^%define[ \t][ \t]*$varname" $specfile) value=$(echo $line | sed -e "s,%define[ \t][ \t]*$varname[ \t][ \t]*,,") @@ -168,8 +169,8 @@ function print_warning () { ========== Your input : module=$module -========== Hard-wired : cvstag=$cvstag +========== Hard-wired : svn=$svn cvs=$cvs ========== Computed : @@ -183,17 +184,17 @@ EOF } function run_test () { - message Hi there - run_prompt n "going to /etc" cd /etc - run_prompt y "going to /etc" cd /etc - run_prompt y "Cleaning up /foobar" rmdir /foobar - run_prompt $(dir_needs_creation /foobar) "create unexisting dir /foobar" mkdir /foobar - run_prompt $(dir_needs_creation /var) "create existing dir /var" mkdir /var - run_prompt y "Cleaning up /foobar" rmdir /foobar - - run_loop "Check this and that" ls -ls passwd - run "Listing passwd" ls -ls passwd - exit 0 + message Hi there + run_prompt n "going to /etc" cd /etc + run_prompt y "going to /etc" cd /etc + run_prompt y "Cleaning up /foobar" rmdir /foobar + run_prompt $(dir_needs_creation /foobar) "create unexisting dir /foobar" mkdir /foobar + run_prompt $(dir_needs_creation /var) "create existing dir /var" mkdir /var + run_prompt y "Cleaning up /foobar" rmdir /foobar + + run_loop y "Check this and that" ls -ls passwd + run "Listing passwd" ls -ls passwd + exit 0 } function figure_last_import () { @@ -212,7 +213,7 @@ function figure_next_import () { } function import_usage () { - echo "Usage: $0 module" + echo "Usage: $0 module tag" echo "All other parameters to be entered in the source file for now - sorry" exit 1 } @@ -221,8 +222,10 @@ function import_module () { [[ -z "$@" ]] && import_usage module=$1; shift - import=$HOME/import-$module-$date + [[ -z "$@" ]] && import_usage + cvstag=$1; shift [[ -n "$@" ]] && import_usage + import=$HOME/import-$module-$date echo -n 'Figuring previous import ..' previous=$(figure_last_import $module) @@ -269,7 +272,7 @@ function import_module () { run "Going to import-$next" \ cd $import/$module/imports/import-$next - run_loop "Check the changes in import-$next -- no conflict expected" \ + run_loop n "Check the changes in import-$next -- no conflict expected" \ svn status $import/$module/imports/import-$next run_prompt n "CHECKING IN imported changes in import-$next" \ @@ -285,7 +288,7 @@ function import_module () { run_prompt n "Merging changes from import-$previous to import-$next into trunk" \ svn merge $svn/$module/imports/import-$previous $svn/$module/imports/import-$next trunk - run_loop "CHECK CHANGES in $import/$module/trunk -- conflicts should get resolved" \ + run_loop n "CHECK CHANGES in $import/$module/trunk -- conflicts should get resolved" \ svn status trunk run_prompt n "CHECKING IN changes in trunk" \ @@ -344,26 +347,26 @@ function tag_module () { echo -n "Checking tags status ..." old_check=$(svn_url_check $oldtag) if [ -z "$old_check" ] ; then - echo "Former tag does not exist -- exiting" - echo "URL was $oldtag" - exit 1 + echo "Former tag does not exist -- exiting" + echo "URL was $oldtag" + exit 1 fi echo -n " old tag OK ... " new_check=$(svn_url_check $newtag) if [ -n "$new_check" ] ; then - echo "New tag does exist -- exiting" - echo "URL was $newtag" - exit 1 + echo "New tag does exist -- exiting" + echo "URL was $newtag" + exit 1 fi echo " new tag OK" patch_in_spec $spec subversion $newsubversion - run_loop "Checking differences" \ + run_loop y "Checking differences" \ svn diff $tagtrunk - run_prompt y "Display differences from previous tag" \ + run_prompt n "Display differences from previous tag" \ svn diff $oldtag $svn/$module/trunk run_prompt y "Committing changes in $tagtrunk" \ @@ -390,16 +393,24 @@ function tag_module () { run "cd $tagbuild" \ cd $tagbuild + # committing tags files + files_to_commit="" for tagsmk in *-tags.mk; do - echo "Managing $tagsmk" + echo "=== Managing $tagsmk" sed -i -e "s,$oldname,$newname,g" $tagsmk if [ $(svn_file_needs_commit $tagsmk) = "y" ] ; then echo "Changes in $tagsmk" svn diff $tagsmk - run_prompt y "Adopt $newname in $tagsmk " \ - svn commit -m"Adopting-$newname" $tagsmk + my_prompt y "Adopt $newname in $tagsmk" + if [ "$?" == 1 ] ; then + files_to_commit="$files_to_commit $tagsmk" + fi fi done + if [ -n "$files_to_commit" ] ; then + command="svn commit -mAdopting-$newname $files_to_commit" + run "Committing selected tags files" $command + fi } #################### @@ -432,7 +443,8 @@ case $0 in *diff-module*) diff_modules $@ ;; *test*) - x=$(figure_module_spec $@) ; echo $x;; +# my_prompt $@ ; echo "result=$?";; + run_test ;; *) echo "Unsupported command $0" ; exit 0 esac -- 2.43.0