From dcf6766865deb36c6ae06e2696639762751e427a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 6 Oct 2013 22:59:54 +0100 Subject: Refactor code to reduce duplication --- git.liw.fi.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/git.liw.fi.sh b/git.liw.fi.sh index 1c52c2e..9f03ff3 100644 --- a/git.liw.fi.sh +++ b/git.liw.fi.sh @@ -66,14 +66,17 @@ user_add() } -# Remove a user from the server. This is a two-step process. +# A helper function to do a two-step destruction on gitano. With the +# first step, gitano outputs a token, which is the last word on the +# last line of the output. The second step has the same command line +# as the first step, but with the token appended. -user_del() +two_step() { - if run_gitano_as "$1" user del "$2" 2> "$DATADIR/temp" + if "$@" 2> "$DATADIR/temp" then secret=$(awk '{ s = $2 } END { print s }' "$DATADIR/temp") - run_gitano_as "$1" user del "$2" "$secret" + "$@" "$secret" else cat "$DATADIR/temp" 1>&2 return 1 @@ -81,6 +84,14 @@ user_del() } +# Remove a user from the server. This is a two-step process. + +user_del() +{ + two_step run_gitano_as "$1" user del "$2" +} + + # Does a repository exist? repo_exists() @@ -111,12 +122,5 @@ clone_with_ssh() destroy_repo() { - if run_gitano_as "$1" destroy "$2" 2> "$DATADIR/temp" - then - secret=$(awk '{ s = $2 } END { print s }' "$DATADIR/temp") - run_gitano_as "$1" destroy "$2" "$secret" - else - cat "$DATADIR/temp" 1>&2 - return 1 - fi + two_step run_gitano_as "$1" destroy "$2" } -- cgit v1.2.1