improved the import function - takes only module in argument, ties to figure the...
authorthierry <thierry@41d37cc5-eb28-0410-a9bf-d37491348ade>
Thu, 19 Jul 2007 12:51:56 +0000 (12:51 +0000)
committerthierry <thierry@41d37cc5-eb28-0410-a9bf-d37491348ade>
Thu, 19 Jul 2007 12:51:56 +0000 (12:51 +0000)
scripts/import-module.sh

index 298eb76..6fd099b 100755 (executable)
@@ -6,15 +6,11 @@
 date=$(date +%Y-%m-%d)
 
 #### REVIEW this carefully
-module=new_plc_api
 cvstag=planetlab-4_0-rc3
-previous=002-rc3-2007-05-02
-next=003-${cvstag}-${date}
 
 ####
 svn="svn+ssh://thierry@svn.one-lab.org/svn"
 cvs=":pserver:anon@cvs.planet-lab.org:/cvs"
-import=$HOME/import-$module-$date
 
 function message () {
   echo -n '-------------------- '
@@ -170,17 +166,17 @@ function print_warning () {
 
  so again : USE WITH CARE
 
+========== Your input :
 module=$module
-previous=$previous
-next=$next
+========== Hard-wired :
 cvstag=$cvstag
 svn=$svn
 cvs=$cvs
+========== Computed :
+previous=$previous
+next=$next
 date=$date
 import=$import
-tagwork=$tagwork
-tagtrunk=$tagtrunk
 ####### WARNING
 
 EOF
@@ -200,33 +196,58 @@ function run_test () {
   exit 0
 }
 
+function figure_last_import () {
+    module=$1; shift
+    last_import=$(svn list $svn/$module/imports | grep '^import-' | sort | tail -1 | sed -e s,import-,, -e s,/,,g )
+    echo $last_import
+}
+
+function figure_next_import () {
+    last_import=$1; shift
+    current_index=$(echo $last_import | sed -e 's,-.*,,')
+    # remove leading 0 that confuse printf (takes it as octal)
+    decimal_index=$(echo  $current_index | sed 's,^0*,,' )
+    next_index=$(printf "%03d" $(($decimal_index+1)))
+    echo ${next_index}-${cvstag}-${date}
+}
+
 function import_usage () {
-   echo "Usage: $0"
-   echo "All parameters to be entered in the source file for now - sorry"
+   echo "Usage: $0 module"
+   echo "All other parameters to be entered in the source file for now - sorry"
    exit 1
 }
 
 function import_module () {
 
+    [[ -z "$@" ]] && import_usage
+    module=$1; shift
+    import=$HOME/import-$module-$date
     [[ -n "$@" ]] && import_usage
 
+    echo -n 'Figuring previous import ..'
+    previous=$(figure_last_import $module)
+    next=$(figure_next_import $previous)
+    echo " found $previous - next=$next"
+
     print_warning
 
     # checks current status
-    echo "------------------------------ Checking $module/imports/import-$previous"
-    [ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] && echo WARNING : import-$previous not found
-
-    echo ''
+    echo -n "-------------------- Checking $module/imports/import-$previous "
+    if [ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] ; then
+       echo FATAL : import-$previous not found
+       exit 1
+    fi
+    echo 'OK'
 
     # snapshot current status
     prompt=$(svn_url_needs_creation $svn/$module/imports/before-$next)
     run_prompt $prompt "Creating snapshot of current status" \
-        svn copy $svn/$module/trunk $svn/$module/imports/before-$next
+        svn copy -mBefore-${next} $svn/$module/trunk $svn/$module/imports/before-$next
 
     # init import dir from previous import
     prompt=$(svn_url_needs_creation $svn/$module/imports/import-$next)
     run_prompt $prompt "Preparing import-$next from import-$previous" \
-        svn copy $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
+        svn copy -mCreation-from-import-${previous} $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
 
     ####
     run_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
@@ -251,8 +272,8 @@ function import_module () {
     run_loop "Check the changes in import-$next -- no conflict expected" \
         svn status $import/$module/imports/import-$next
 
-    run_prompt n "CHECKING IN changes in import-$next" \
-        svn ci -m "Changes since $previous"
+    run_prompt n "CHECKING IN imported changes in import-$next" \
+        svn ci -mApplied-changes-since-$previous
 
     ###
     run "Going to $import/$module" \
@@ -264,7 +285,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 the changes in trunk -- conflicts should get resolved" \
+    run_loop "CHECK CHANGES in $import/$module/trunk -- conflicts should get resolved" \
         svn status trunk
 
     run_prompt n "CHECKING IN changes in trunk" \
@@ -280,6 +301,8 @@ function import_module () {
     echo 'Done'
 }
 
+##############################
+
 function tag_usage () {
    echo "Usage: $0 module"
    exit 1