Fixes #5361 - Simplify repo-merge.sh by using function instead of duplicated code

Fixes #5361 - Simplify repo-merge.sh by using function instead of duplicated code

cf http://www.rudder-project.org/redmine/issues/5361
> The indentation here looks pretty messed up... Can you align everything using (I guess tabs)?

Err... yes, there is a strange mix of tab/spaces. I'll fix it