1- #! /bin/sh -ex
1+ #! /bin/bash -ex
22
33verbose=0
44git_verbose=0
5+ max_jobs=16
6+
7+ lockfile=" $( pwd) /version_check.lock"
8+ resultfile=" $( pwd) /version_check_results.txt"
59
610if [ " $1 " = " -v" ]; then
711 verbose=1
@@ -10,9 +14,13 @@ elif [ "$1" = "-vv" ]; then
1014 git_verbose=1
1115fi
1216
13- max_dir_length=0
14- result_dirs=()
15- result_msgs=()
17+ # Limit concurrent jobs
18+ job_control ()
19+ {
20+ while [ " $( jobs | wc -l) " -ge " $max_jobs " ]; do
21+ sleep 0.1
22+ done
23+ }
1624
1725git_call ()
1826{
@@ -27,29 +35,29 @@ git_call()
2735
2836check_tags ()
2937{
30- path=$( echo " $1 " | sed ' s:/*$::' )
38+ local path=$( echo " $1 " | sed ' s:/*$::' )
3139
3240 echo " Checking $path "
3341
34- git_call fetch --prune --all
42+ # git_call fetch --prune --all
3543
3644 # Get the latest tag (by commit date, not tag name)
37- tag_list=$( git_call rev-list --tags --max-count=1)
38- latest_tag=$( git_call describe --tags " $tag_list " )
45+ local tag_list=$( git_call rev-list --tags --max-count=1)
46+ local latest_tag=$( git_call describe --tags " $tag_list " )
3947
4048 if [ -n " $latest_tag " ]; then
4149
4250 # Get the current tag
43- current_tag=$( git_call describe --tags --abbrev=0)
51+ local current_tag=$( git_call describe --tags --abbrev=0)
4452
4553 if [ -n " $current_tag " ]; then
4654
4755 if [ " $verbose " -eq 1 ]; then
4856 echo " $path -> latest: $latest_tag , current: $current_tag "
4957 fi
5058
51- ts1=$( git_call log -1 --format=%ct $latest_tag )
52- ts2=$( git_call log -1 --format=%ct $current_tag )
59+ local ts1=$( git_call log -1 --format=%ct $latest_tag )
60+ local ts2=$( git_call log -1 --format=%ct $current_tag )
5361
5462 if (( ts1 > ts2 )) ; then
5563 if [ " $verbose " -eq 1 ]; then
@@ -58,12 +66,11 @@ check_tags()
5866 echo " $path -> latest: $latest_tag , current: $current_tag "
5967 fi
6068
61- path_length=${# path}
62- if (( $path_length > $max_dir_length )) ; then
63- max_dir_length=$path_length
64- fi
65- result_dirs+=(" $path " )
66- result_msgs+=(" latest: $latest_tag , current: $current_tag " )
69+ # Critical section guarded by flock
70+ (
71+ flock 200
72+ echo " $path -> latest: $latest_tag , current: $current_tag " >> " $resultfile "
73+ ) 200> " $lockfile "
6774 fi
6875
6976 elif [ " $verbose " -eq 1 ]; then
@@ -79,19 +86,21 @@ check_tags()
7986 fi
8087}
8188
89+ # Fetch and check repositories multi threaded
8290for submoduledir in * / ;
8391do
8492 cd " $submoduledir " || continue
8593
8694 if [ -e " .git" ]; then
87- check_tags " $submoduledir "
95+ job_control
96+ check_tags " $submoduledir " &
8897 else
89- # find */ -mindepth 1 -maxdepth 1 -type d | while read -r sub;
9098 for sub in * / ;
9199 do
92100 if [ -e " $sub /.git" ]; then
93101 cd " $sub " || continue
94- check_tags " $submoduledir$sub "
102+ job_control
103+ check_tags " $submoduledir$sub " &
95104 cd .. || exit
96105 fi
97106 done
100109 cd .. || exit
101110done
102111
112+ # Wait for all background jobs to finish
113+ wait
114+
115+ # Print results
103116echo -e " \n\nResult:\n"
104- i=0
105- for result_dir in " ${result_dirs[@]} " ; do
106- msg=" "
107- diff=$(( $max_dir_length - ${# result_dir} ))
108- if (( $diff > 0 )) ; then
109- msg+=$( printf " %${diff} s" " " )
117+
118+ # Find the max length of the paths (before '->')
119+ max_len=0
120+ while IFS=' ->' read -r left _; do
121+ len=$( echo -n " $left " | wc -c)
122+ if (( len > max_len )) ; then
123+ max_len=$len
110124 fi
111- msg+=" $result_dir "
112- echo " $msg -> ${result_msgs[$i]} "
113- (( i++ ))
114- done
115- echo " "
125+ done < " $resultfile "
126+
127+ # Print with padding so '->' lines up
128+ while IFS=' ->' read -r left right; do
129+ right=$( echo " $right " | sed ' s/^[[:space:]]*>*[[:space:]]*//' )
130+ printf " %-${max_len} s -> %s\n" " $left " " $right "
131+ done < " $resultfile "
132+
133+ # Remove tmp files
134+ rm -f " $resultfile "
135+ rm -f " $lockfile "
0 commit comments