Tuesday 2010-09-28

Using git for homedir versioning works well. However, bouncing between machines, it's annoying and slow to 'git pull' each remote. So I added a parallelized git pull for all my repos to my bashrc's section for interactive commands:

Monday 2010-10-04

The sleep exit'ing will trigger a SIGCHLD as it's not a bash internal. So we need to increment the pool count (now child count) for each sleep we run.

git_all_child_count_inc() {
	export GIT_ALL_CHILD_COUNT=$(( $GIT_ALL_CHILD_COUNT + 1))
}
git_all_child_count_dec() {
	export GIT_ALL_CHILD_COUNT=$(( $GIT_ALL_CHILD_COUNT - 1))
}
git_all() {
	local max=10
	export GIT_ALL_CHILD_COUNT=0
	trap git_all_child_count_dec SIGCHLD

	for dir in $HOME/* $HOME/projects/* ; do 
		[[ ! -d ${dir}/.git ]] && continue
		echo -n "$dir "
		( builtin cd $dir 
			command git branch | grep -q '^* master' && command git pull -q
		) &  
		disown $!
		git_all_child_count_inc
		while [[ $GIT_ALL_CHILD_COUNT -gt $max ]]; do git_all_child_count_inc; sleep 1; done
	done
	wait
	trap "" SIGCHLD
}

This parallelizes the git pulls (10 in the above case).

I'm assuming atomicity/exclusion for the signal handler. If it's not and this locks, we just export the child count lower.


You might want to try out Joey Hess' mr tool: http://joey.kitenet.net/code/mr/

^ -Doug

mr looks slick. Good deal on making the RPMs available for it, Doug.