From e229b36aae86b3867e1f6165dfe8dcddf93777d6 Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 13 Oct 2015 17:50:50 +0300 Subject: [PATCH 1/6] Check if git branch exists before trying to create one --- peg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/peg b/peg index 60ed268..9f138c9 100755 --- a/peg +++ b/peg @@ -293,7 +293,9 @@ function setup_repo { function checkout_repo_git { link_project_git cd $PGSRC/$PGPROJECT - # TODO This will fail if this branch already exists. + + # Create new branch only if the branch doesn't already + git rev-parse --verify $PGPROJECT 2>&1 > /dev/null || \ git checkout -b $PGPROJECT $GITMASTERBRANCH } From e30d1fe4a4710722f6fed024b3d83ab6461021c7 Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 13 Oct 2015 17:50:50 +0300 Subject: [PATCH 2/6] if branch exists we still need to run checkout --- peg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/peg b/peg index 9f138c9..07ee947 100755 --- a/peg +++ b/peg @@ -297,6 +297,9 @@ function checkout_repo_git { # Create new branch only if the branch doesn't already git rev-parse --verify $PGPROJECT 2>&1 > /dev/null || \ git checkout -b $PGPROJECT $GITMASTERBRANCH + + # But always checkout the branch + git checkout $PGPROJECT } function checkout_repo_cvs { From 5fa53c32017f71164045598da1422a79351a59e5 Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 13 Oct 2015 17:50:50 +0300 Subject: [PATCH 3/6] Check if database exists before trying to create it --- peg | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/peg b/peg index 07ee947..a80b734 100755 --- a/peg +++ b/peg @@ -523,9 +523,12 @@ function add_user_db { # psql by default wants to connect to a database with the same user # as is running the program. createdb will default to creating a user # with the same name. Might as well take advantage of that synergy. - - # TODO Only execute this if the database doesn't already exist - $PGENGINE/createdb + + if [ -x /usr/bin/whoami ] ; then + $PGENGINE/psql $(whoami) -c ';' 2>/dev/null >/dev/null || $PGENGINE/createdb + else + $PGENGINE/createdb + fi; } function report_env { From 983d6f1e51102f03125854499f80f1e51e4908aa Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 13 Oct 2015 17:50:50 +0300 Subject: [PATCH 4/6] Check if configure ran before trying to 'make maintainer-clean' --- peg | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/peg b/peg index a80b734..7f036d2 100755 --- a/peg +++ b/peg @@ -337,7 +337,11 @@ function clean_project { if [ -d "$PGSRC/$PGPROJECT" ] ; then echo Cleaning out source code tree at $PGSRC/$PGPROJECT pushd $PGSRC/$PGPROJECT - make maintainer-clean + # The PG Makefile itself uses this check to ensure + # configure has been run prior to a 'make clean' + if [ -f GNUmakefile ] ; then + make maintainer-clean + fi; popd echo maintainer-clean of source directory $PGSRC/$PRPROJECT finished else @@ -353,7 +357,11 @@ function remove_project { GITBASE="$GITROOT/$GITPGROOTDIR" echo Cleaning out all build artifacts from the git repo at $GITBASE pushd $GITBASE - make maintainer-clean + # The PG Makefile itself uses this check to ensure + # configure has been run prior to a 'make clean' + if [ -f GNUmakefile ] ; then + make maintainer-clean + fi; popd echo maintainer-clean of repo directory $GITBASE finished fi From c4795d0a7337324cf44632d496245d6ae3b2e4fd Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 13 Oct 2015 17:50:50 +0300 Subject: [PATCH 5/6] Remove lastproject on remove_project --- peg | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/peg b/peg index 7f036d2..fe8cd6b 100755 --- a/peg +++ b/peg @@ -326,13 +326,22 @@ function create_project { function rm_if_exists { if [ -d "$1" ] ; then - echo Erasing directory $1 + echo Erasing directory $1 rm -rf "$1" else echo Not removing directory $1 because it does not exist fi } +function rm_file_if_exists { + if [ -f "$1" ] ; then + echo Erasing file $1 + rm -rf "$1" + else + echo Not removing file $1 because it does not exist + fi +} + function clean_project { if [ -d "$PGSRC/$PGPROJECT" ] ; then echo Cleaning out source code tree at $PGSRC/$PGPROJECT @@ -374,6 +383,8 @@ function remove_project { rm_if_exists "$PGWORK/$DATADIR/$PGPROJECT" rm_if_exists "$PGINST/$PGPROJECT" rm_if_exists "$PGSRC/$PGPROJECT" + rm_file_if_exists "$PGWORK/lastproject" + } function optional_project { From 7ad25804a247c37130b225fcfcf4b7aa97a7d0cb Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 13 Oct 2015 17:50:50 +0300 Subject: [PATCH 6/6] Always distclean before building. ccache can speed things up for us --- peg | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/peg b/peg index fe8cd6b..5b35a6b 100755 --- a/peg +++ b/peg @@ -452,18 +452,18 @@ function detect_cpus { if [ -z "$CPUS" ]; then # If there's no more accurate guess, running make with 4 processes works - # well enough on typical hardware circa 2012. + # well enough on typical hardware circa 2012. CPUS=4 fi } function build { cd $PGSRC/$PGPROJECT - if [ -f GNUmakefile ] ; then - echo WARNING: Build found an existing GNUmakefile, not running configure again - else - ./configure --prefix=$PGINST/$PGPROJECT --enable-depend --enable-thread-safety $PGDEBUG - fi + + $PGMAKE distclean # always clean first, files in working dir may belong to + # may belong to the branch we just checked out of + + ./configure --prefix=$PGINST/$PGPROJECT --enable-depend --enable-thread-safety $PGDEBUG detect_cpus if [ -z "$CPUS" ] ; then