Browse code

improve update to check for changes repositories files

Nat! authored on 06-06-2016 23:49:48
Showing 2 changed files
... ...
@@ -876,6 +876,11 @@ install_embedded_repositories()
876 876
 }
877 877
 
878 878
 
879
+# return 0, all cool
880
+# return 1, is symlinked
881
+# return 2, .bootstrap/repositories changed
882
+# return 3, is symlinked and .bootstrap/repositories changed
883
+
879 884
 update()
880 885
 {
881 886
    local name
... ...
@@ -905,14 +910,22 @@ update()
905 910
       svn)
906 911
          operation="svn_update"
907 912
          ;;
908
-
909 913
       *)
910 914
          fail "unknown scm system ${scm}"
911 915
          ;;
912 916
    esac
913 917
 
914 918
    local script
919
+   local before_r
920
+   local before_e
921
+   local after_r
922
+   local after_e
923
+   local rval
915 924
 
925
+   before_r=`modification_timestamp "${dstdir}/${BOOTSTRAP_SUBDIR}/repositories"`
926
+   before_e=`modification_timestamp "${dstdir}/${BOOTSTRAP_SUBDIR}/embedded_repositories"`
927
+
928
+   rval=0
916 929
    if [ ! -L "${dstdir}" ]
917 930
    then
918 931
       run_repo_settings_script "${name}" "${dstdir}" "pre-update" "$@"
... ...
@@ -929,8 +942,18 @@ update()
929 942
    else
930 943
       ensure_clone_branch_is_correct "${dstdir}" "${branch}"
931 944
       log_fluff "Repository \"${name}\" exists, so not updated."
932
-      return 1
945
+
946
+      rval=1
947
+   fi
948
+
949
+   after_r=`modification_timestamp "${dstdir}/${BOOTSTRAP_SUBDIR}/repositories"`
950
+   after_e=`modification_timestamp "${dstdir}/${BOOTSTRAP_SUBDIR}/embedded_repositories"`
951
+
952
+   if [ "${before_r}" = "${after_r}" -a "${before_e}" = "${after_e}" ]
953
+   then
954
+      rval="`expr "$rval" + 2`"
933 955
    fi
956
+   return "$rval"
934 957
 }
935 958
 
936 959
 
... ...
@@ -947,6 +970,8 @@ update_repository()
947 970
    local name
948 971
    local tag
949 972
    local dstdir
973
+   local rval
974
+
950 975
 
951 976
    tag="`read_repo_setting "${name}" "tag"`" #repo (sic)
952 977
 
... ...
@@ -957,27 +982,32 @@ update_repository()
957 982
    log_fetch_action "${url}" "${dstdir}"
958 983
 
959 984
    update "${name}" "${url}" "${dstdir}" "${branch}" "${tag}"
960
-
985
+   rval=$?
961 986
    #update will return 1 if repo is symlinked
962 987
 
963
-   if [ $? -eq 0 -a "${DONT_RECURSE}" = "" ]
988
+   if [ "${DONT_RECURSE}" = "" ]
964 989
    then
965
-      local old_bootstrap
990
+      if [ $rval -eq 0 -o $rval -eq 2 ]
991
+      then
992
+         local old_bootstrap
966 993
 #      local old_fetch
967 994
 
968
-      old_bootstrap="${BOOTSTRAP_SUBDIR}"
995
+         old_bootstrap="${BOOTSTRAP_SUBDIR}"
969 996
 #      old_fetch="${CLONESFETCH_SUBDIR}"
970 997
 
971
-      BOOTSTRAP_SUBDIR="${dstdir}/.bootstrap"
998
+         BOOTSTRAP_SUBDIR="${dstdir}/.bootstrap"
972 999
 #      CLONESFETCH_SUBDIR="${dstdir}/.repos"
973 1000
 
974
-      update_embedded_repositories "${dstdir}/"
1001
+         update_embedded_repositories "${dstdir}/"
975 1002
 
976
-      BOOTSTRAP_SUBDIR="${old_bootstrap}"
1003
+         BOOTSTRAP_SUBDIR="${old_bootstrap}"
977 1004
 #      CLONESFETCH_SUBDIR="${old_fetch}"
1005
+      fi
978 1006
    fi
979 1007
 
980 1008
    ensure_clone_branch_is_correct "${dstdir}" "${branch}"
1009
+   [ $rval -eq 0 -o $rval -eq 2 ]
1010
+   return $?
981 1011
 }
982 1012
 
983 1013
 
... ...
@@ -1032,7 +1062,24 @@ update_repositories()
1032 1062
          IFS="${old}"
1033 1063
          did_update_repository "${name}" "${CLONESFETCH_SUBDIR}/${name}"
1034 1064
       done
1035
-   else
1065
+      IFS="${old}"
1066
+      return
1067
+   fi
1068
+
1069
+   local stop
1070
+   local url
1071
+   local updated
1072
+   local match
1073
+   local branch
1074
+   local scm
1075
+
1076
+   updated=""
1077
+
1078
+   stop=0
1079
+   while [ $stop -eq 0 ]
1080
+   do
1081
+      stop=1
1082
+
1036 1083
       clones="`read_fetch_setting "repositories"`"
1037 1084
       clones="`echo "${clones}" | sed '1!G;h;$!d'`"  # reverse lines
1038 1085
 
... ...
@@ -1043,30 +1090,30 @@ update_repositories()
1043 1090
          for clone in ${clones}
1044 1091
          do
1045 1092
             IFS="${old}"
1046
-            name="`canonical_name_from_clone "${clone}"`"
1047
-            url="`url_from_clone "${clone}"`"
1048
-            branch="`branch_from_clone "${clone}"`"
1049 1093
 
1050
-            update_repository "${name}" "${url}" "${branch}"
1051
-         done
1094
+            # avoid superflous updates
1095
+            match="`echo "${updated}" | grep -x "${clone}"`"
1052 1096
 
1053
-         # reread because of auto
1054
-         IFS="
1055
-"
1056
-         clones="`read_fetch_setting "repositories"`"
1057
-         clones="`echo "${clones}" | sed '1!G;h;$!d'`"  # reverse lines
1097
+            if [ "${match}" != "${clone}" ]
1098
+            then
1099
+               fetched="${updated}
1100
+${clone}"
1058 1101
 
1059
-         for clone in ${clones}
1060
-         do
1061
-            IFS="${old}"
1062
-            name="`canonical_name_from_clone "${clone}"`"
1063
-            url="`url_from_clone "${clone}"`"
1064
-            branch="`branch_from_clone "${clone}"`"
1102
+               name="`canonical_name_from_clone "${clone}"`"
1103
+               url="`url_from_clone "${clone}"`"
1104
+               branch="`branch_from_clone "${clone}"`"
1065 1105
 
1066
-            did_update_repository "${name}" "${url}" "${branch}"
1106
+               update_repository "${name}" "${url}" "${branch}"
1107
+
1108
+               if [ $? -eq 1 ]
1109
+               then
1110
+                  stop=0
1111
+                  break
1112
+               fi
1113
+            fi
1067 1114
          done
1068 1115
       fi
1069
-   fi
1116
+   done
1070 1117
 
1071 1118
    IFS="${old}"
1072 1119
 }
... ...
@@ -440,6 +440,18 @@ remove_file_if_present()
440 440
 }
441 441
 
442 442
 
443
+modification_timestamp()
444
+{
445
+   case "`uname`" in
446
+      Linux )
447
+         stat --printf "%Y\n" "$1"
448
+         ;;
449
+      * )
450
+         stat -f "%m" "$1"
451
+         ;;
452
+   esac
453
+}
454
+
443 455
 
444 456
 simplify_path()
445 457
 {