Source

django-environments / scripts / djenv.mercurial

Full commit
Vincent Hillenbr… 16a3a8c 



Vincent Hillenbr… fadef2e 

Vincent Hillenbr… 16a3a8c 
Vincent Hillenbr… e5e8184 
Vincent Hillenbr… 16a3a8c 
Vincent Hillenbr… fadef2e 






Vincent Hillenbr… 16a3a8c 

Vincent Hillenbr… e5e8184 
Vincent Hillenbr… fadef2e 
Vincent Hillenbr… 16a3a8c 


Vincent Hillenbr… e5e8184 
Vincent Hillenbr… 16a3a8c 

Vincent Hillenbr… f9e97f9 
Vincent Hillenbr… 16a3a8c 

Vincent Hillenbr… fadef2e 
Vincent Hillenbr… 5cb6bca 
Vincent Hillenbr… fadef2e 
Vincent Hillenbr… f9e97f9 
Vincent Hillenbr… 5cb6bca 






Vincent Hillenbr… fadef2e 
Vincent Hillenbr… 16a3a8c 






Vincent Hillenbr… 4f00092 

Vincent Hillenbr… fadef2e 

Vincent Hillenbr… 4f00092 


Vincent Hillenbr… fadef2e 
Vincent Hillenbr… f9e97f9 
Vincent Hillenbr… 4f00092 
Vincent Hillenbr… fadef2e 
Vincent Hillenbr… 4f00092 




Vincent Hillenbr… 40146eb 

Vincent Hillenbr… fadef2e 
Vincent Hillenbr… 40146eb 




Vincent Hillenbr… 16a3a8c 

Vincent Hillenbr… fadef2e 
Vincent Hillenbr… 16a3a8c 



Vincent Hillenbr… fadef2e 

Vincent Hillenbr… 16a3a8c 

Vincent Hillenbr… fadef2e 








#
# Mercurial utilities for django-environments
# 

hgbaseport=7100
hgpidfile=$PROJECT_ROOT/tmp/hgserve.pid

# Start hg server in daemon mode and open first argument in browser
function hgserve() {
    [ -z "$PROJECT_ROOT" ] && echo "No \$PROJECT_ROOT" 1>&2 && return 1

    # Determine port number
    local numhash=`echo $PROJECT_ROOT | md5 | sed 's/[^0-9]//g'`
    hgport=`expr $hgbaseport + ${numhash:0:2}`

    # See if the server is alive - start it if not
    kill -0 `cat $hgpidfile 2>&1` > /dev/null 2>&1
    if [ ! $? -eq 0 ]; then
        cwd=`pwd`
        cdroot
        hg serve --port $hgport --daemon \
            --pid-file $PROJECT_ROOT/tmp/hgserve.pid
        sleep 0.5
        cd $cwd
    fi

    [ ! "$1" = "--no-open" ] && open http://localhost:$hgport/$1
}

# Browse files in tip
function hgbrowse() {
    [ -z "$PROJECT_ROOT" ] && echo "No \$PROJECT_ROOT" 1>&2 && return 1
    hgserve --no-open

    path=file/tip`echo \`pwd\` | sed "s#$PROJECT_ROOT##"`
    [ ! -z "$1" ] && path=$path/$1

    open http://localhost:$hgport/$path
}

# Shut down hg server
function hgkill() {
    kill -9 `cat $hgpidfile 2>&1` > /dev/null 2>&1
    if [ ! $? -eq 0 ]; then
        echo Server not running or other error 2>&1
    fi
}

# Runs an hg command on all hg repositories in the externals directory,
# e.g. 'hgexternals pull -u'
function hgexternals() {
    [ -z "$PROJECT_ROOT" ] && echo "No \$PROJECT_ROOT" 1>&2 && return 1
    for external in $PROJECT_ROOT/externals/*; do
        if [ -d $external/.hg ]; then
            echo `basename $external`:
            _IFS=$IFS
            IFS='' # magic
            hg -R $external $*
            IFS=$_IFS
            echo
        fi
    done
}

# Pull and update the project and all Mercurial externals
function hgfetchall() {
    [ -z "$PROJECT_ROOT" ] && echo "No \$PROJECT_ROOT" 1>&2 && return 1
    hg -R $PROJECT_ROOT pull -u
    echo
    hgexternals pull -u
}

# List all .orig files
function hgfindorig() {
    [ -z "$PROJECT_ROOT" ] && echo "No \$PROJECT_ROOT" 1>&2 && return 1
    find $PROJECT_ROOT -name \*.orig -l
}

# List all .orig files
function hgremoveorig() {
    [ -z "$PROJECT_ROOT" ] && echo "No \$PROJECT_ROOT" 1>&2 && return 1
    find $PROJECT_ROOT -name \*.orig -print -delete
}

# Clean up
function _djenv_mercurial_cleanup () {
    # Stop server
    hgkill 2>&1 > /dev/null
    # Clean environment
    unset hgport
}

_djenv_register_cleanup _djenv_mercurial_cleanup