changeset 210:0590f34b92a0

shell.d: split hg and git functions out of vcs functions
author Augie Fackler <durin42@gmail.com>
date Sun, 16 May 2010 20:43:00 -0500
parents c28a1e2c746a
children 8980dc2deda0
files .shell.d/50.git_functions.sh .shell.d/50.hg_functions.sh .shell.d/50.vcs_functions.sh
diffstat 3 files changed, 3 insertions(+), 534 deletions(-) [+]
line wrap: on
line diff
copy from .shell.d/50.vcs_functions.sh
copy to .shell.d/50.git_functions.sh
--- a/.shell.d/50.vcs_functions.sh
+++ b/.shell.d/50.git_functions.sh
@@ -1,219 +1,4 @@
-## vcs_functions
-# This file contains a handful of functions that relate to using some version
-# control tool or other.
-
-function mq () {
-    ( wcroot ;
-       hg -R .hg/patches $@
-     )
-}
-
-function mq-snapshot () {
-    mq ci -m "Applied on $(hg log -r qparent --template '{node|short}\n')"
-}
-
-function ezsvnsync() {
-    if [ x"$1" = "x" ] ; then
-        echo 'usage: ez-svn-sync repo url'
-        return 0
-    fi
-    local repo
-    repo=$1
-    local url
-    url=$2
-    svnadmin create $repo
-    echo '#!/bin/sh' >> $repo/hooks/pre-revprop-change
-    echo 'exit 0' >> $repo/hooks/pre-revprop-change
-    chmod +x $repo/hooks/pre-revprop-change
-    svnsync init file://`pwd`/$repo $url
-    svnsync sync file://`pwd`/$repo
-}
-alias ez-svn-sync=ezsvnsync
-
-# Function to grab the url of an svn wc
-function svnurlof() {
-    local url
-    url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
-    if [ x"$url" = "x" ] ; then
-        url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
-    fi
-    if [ x"$url" = "x" ] ; then
-        local dir
-        dir=$1
-        if [ x"$dir" = "x" ] ; then
-                dir="."
-        fi
-        url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
-    fi
-    if [ x"$url" = "x" ] ; then
-        echo -n 'No repo found (tried svn, git-svn, hgsubversion)'
-    fi
-    echo $url
-}
-
-function hgsvnmergebranch() {
-    local targetrev
-    local striprev
-    targetrev=$(hg id | cut -d ' ' -f 1)
-    hg merge $1
-    hg ci -m "Merging $1"
-    striprev=$(hg id | cut -d ' ' -f 1)
-    hg co $targetrev
-    hg diff -r$targetrev:$striprev | hg import - -m "Merged branch $1."
-    hg strip $striprev
-}
-alias hg-svn-merge-branch=hgsvnmergebranch
-
-function hgsvnrebaseall() {
-    for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq`
-    do
-        echo "rebase $b"
-        hg co $b
-        if [[ "$?" != "0" ]] ; then
-            echo "abort: could not checkout $b"
-            return
-        fi
-        hg parent --svn > /dev/null
-        if [[ "$?" == "0" ]] ; then
-            hg rebase --svn || return
-        else
-            echo "Skip $b since it has a merge."
-        fi
-    done
-}
-alias hg-svn-rebase-all=hgsvnrebaseall
-
-function hgamend() {
-    hg qimport -r . && hg qref && hg qfin qtip
-}
-alias hg-amend=hgamend
-
-function hg_verify_all() {
-  for x in $(find . -name '.hg') ; do
-    y=$(dirname $x)
-    echo $y
-    hg verify -R $y
-  done
-}
-
-function hgsvnmkbranch() {
-    local upstream
-    upstream=$(hg paths default | sed 's%/*$%%')
-    local branchname
-    if [ "x$1" = "x" ] ; then
-        echo 'Must provide new branch name.'
-        return 1
-    fi
-    local d=`hg svn info | grep URL | sed 's/.*://'`
-    local br=`echo $d | awk '{
-            if ( index($1, "trunk") ) {
-                    print  "trunk"
-                } else {
-                    x = index($1, "branches") ;
-                    if ( x != 0 ) {
-                            sub(".*/branches/", "");
-                            sub("/.*", "");
-                            print $0
-                        }
-                }
-                }'`
-
-    branchname=$br
-    echo svn cp $upstream/$branchname $upstream/branches/$1
-}
-alias hg-svn-mkbranch=hgsvnmkbranch
-
-# Function to clean locks out of svn wcs
-function clean_svn_source_trees() {
-    for aa in */ ; do
-        pushd $aa > /dev/null
-        if [ -e .svn ] ; then
-            echo $aa 'is an svn checkout, cleaning' && svn cleanup
-        fi
-        popd  > /dev/null
-    done
-}
-
-# Function to update source trees of known VCS tools in the working dir.
-# "known" means ones I'm forced to use on a regular basis
-function update_source_trees() {
-    if ! ls -l | egrep ^d > /dev/null ; then
-        ls -l | egrep ^d
-        return
-    fi
-    local hgpath
-    for aa in */ ; do
-        pushd $aa > /dev/null || continue
-        if [ -e .svn ] ; then
-            echo $aa 'is an svn checkout, updating'
-            svn up
-        elif [ -e README.txt ] \
-            && [ -e format ] \
-            && grep "This is a Subversion repository; use the 'svnadmin' tool to examine" README.txt > /dev/null \
-            && svn pl --revprop -r 0 file://$(pwd) | fgrep svn:sync-from-url  > /dev/null\
-            ; then
-            echo "$aa looks like an svnsync clone, syncing"
-            svnsync sync file://$(pwd)
-        elif [ -e .git/svn ] ; then
-            echo $aa 'is a git-svn checkout, updating'
-            git svn fetch
-        elif [ -e .git ] ; then
-            echo $aa 'is a git checkout, updating'
-            git pull origin master
-        elif [ -e .hg ] ; then
-            echo $aa 'is an hg checkout, updating'
-            for hgpath in $(HGRCPATH=/dev/null hg paths | sed 's/.* = //g' | sort | uniq ) ; do
-                hg pull --update $hgpath
-            done
-            if [ -e .hg/patches/.hg ] ; then
-               echo $aa 'has an mq, updating that too...'
-               hg -R .hg/patches pull -u
-            fi
-        elif [ -e _MTN ] ; then
-            echo $aa "is an mtn co, updating" && mtn pull && mtn up
-        else
-            update_source_trees
-        fi
-        popd > /dev/null
-    done
-}
-alias update-source-trees=update_source_trees
-
-function vcs_current_branch() {
-   git branch 2> /dev/null > /dev/null
-    if [ $? = 0 ] ; then
-        git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /'
-        return 0
-    fi
-    # when wc-ng comes out, we'll probably do the following
-    # svn info 2> /dev/null > /dev/null
-    if [ -e .svn ] ; then
-        local d=`svn info | grep URL | sed 's/.*://'`
-        local br=`echo $d | awk '{
-                        if ( index($1, "trunk") ) {
-                            print  "trunk"
-                        } else {
-                            x = index($1, "branches") ;
-                            if ( x != 0 ) {
-                                sub(".*/branches/", "");
-                                sub("/.*", "");
-                                print $0
-                            }
-                        }
-                    }'`
-        local rev=`svn info | grep Revision | sed 's/.*: /r/'`
-        echo $br $rev
-        return 0
-    fi
-    hg branch 2> /dev/null > /dev/null
-    if [ $? = 0 ] ; then
-        local br=`hg branch | head -c 10`
-        local rid=`hg parents | head -n 1 | awk '{print $2}' | head -c 7`
-        echo "$br $rid"
-        return 0
-    fi
-    return 1
-}
+# git utility functions
 
 function git_next_unmerged_file() {
   git status | egrep '(unmerged|both modified)' | head -n 1 | sed 's/.*:   //'
@@ -242,26 +27,3 @@ function git_fsck_all() {
     popd
   done
 }
-
-# change to the root dir of the current wc
-function wcroot() {
-    local root=`hg root 2> /dev/null`
-    if [ x$root != 'x' ] ; then
-        cd $root
-        return 0
-    fi
-    git branch 2> /dev/null > /dev/null
-    if [ $? = 0 ] ; then
-        while [ ! -e .git ] ; do
-            cd ..
-        done
-        return 0
-    fi
-    if [ -e .svn ] ; then
-        while [ -e ../.svn ] ; do
-            cd ..
-        done
-        return 0
-    fi
-    echo No working copy found'!'
-}
copy from .shell.d/50.vcs_functions.sh
copy to .shell.d/50.hg_functions.sh
--- a/.shell.d/50.vcs_functions.sh
+++ b/.shell.d/50.hg_functions.sh
@@ -1,6 +1,5 @@
-## vcs_functions
-# This file contains a handful of functions that relate to using some version
-# control tool or other.
+## hg_functions
+# various hg utility functions
 
 function mq () {
     ( wcroot ;
@@ -12,45 +11,6 @@ function mq-snapshot () {
     mq ci -m "Applied on $(hg log -r qparent --template '{node|short}\n')"
 }
 
-function ezsvnsync() {
-    if [ x"$1" = "x" ] ; then
-        echo 'usage: ez-svn-sync repo url'
-        return 0
-    fi
-    local repo
-    repo=$1
-    local url
-    url=$2
-    svnadmin create $repo
-    echo '#!/bin/sh' >> $repo/hooks/pre-revprop-change
-    echo 'exit 0' >> $repo/hooks/pre-revprop-change
-    chmod +x $repo/hooks/pre-revprop-change
-    svnsync init file://`pwd`/$repo $url
-    svnsync sync file://`pwd`/$repo
-}
-alias ez-svn-sync=ezsvnsync
-
-# Function to grab the url of an svn wc
-function svnurlof() {
-    local url
-    url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
-    if [ x"$url" = "x" ] ; then
-        url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
-    fi
-    if [ x"$url" = "x" ] ; then
-        local dir
-        dir=$1
-        if [ x"$dir" = "x" ] ; then
-                dir="."
-        fi
-        url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
-    fi
-    if [ x"$url" = "x" ] ; then
-        echo -n 'No repo found (tried svn, git-svn, hgsubversion)'
-    fi
-    echo $url
-}
-
 function hgsvnmergebranch() {
     local targetrev
     local striprev
@@ -122,146 +82,3 @@ function hgsvnmkbranch() {
     echo svn cp $upstream/$branchname $upstream/branches/$1
 }
 alias hg-svn-mkbranch=hgsvnmkbranch
-
-# Function to clean locks out of svn wcs
-function clean_svn_source_trees() {
-    for aa in */ ; do
-        pushd $aa > /dev/null
-        if [ -e .svn ] ; then
-            echo $aa 'is an svn checkout, cleaning' && svn cleanup
-        fi
-        popd  > /dev/null
-    done
-}
-
-# Function to update source trees of known VCS tools in the working dir.
-# "known" means ones I'm forced to use on a regular basis
-function update_source_trees() {
-    if ! ls -l | egrep ^d > /dev/null ; then
-        ls -l | egrep ^d
-        return
-    fi
-    local hgpath
-    for aa in */ ; do
-        pushd $aa > /dev/null || continue
-        if [ -e .svn ] ; then
-            echo $aa 'is an svn checkout, updating'
-            svn up
-        elif [ -e README.txt ] \
-            && [ -e format ] \
-            && grep "This is a Subversion repository; use the 'svnadmin' tool to examine" README.txt > /dev/null \
-            && svn pl --revprop -r 0 file://$(pwd) | fgrep svn:sync-from-url  > /dev/null\
-            ; then
-            echo "$aa looks like an svnsync clone, syncing"
-            svnsync sync file://$(pwd)
-        elif [ -e .git/svn ] ; then
-            echo $aa 'is a git-svn checkout, updating'
-            git svn fetch
-        elif [ -e .git ] ; then
-            echo $aa 'is a git checkout, updating'
-            git pull origin master
-        elif [ -e .hg ] ; then
-            echo $aa 'is an hg checkout, updating'
-            for hgpath in $(HGRCPATH=/dev/null hg paths | sed 's/.* = //g' | sort | uniq ) ; do
-                hg pull --update $hgpath
-            done
-            if [ -e .hg/patches/.hg ] ; then
-               echo $aa 'has an mq, updating that too...'
-               hg -R .hg/patches pull -u
-            fi
-        elif [ -e _MTN ] ; then
-            echo $aa "is an mtn co, updating" && mtn pull && mtn up
-        else
-            update_source_trees
-        fi
-        popd > /dev/null
-    done
-}
-alias update-source-trees=update_source_trees
-
-function vcs_current_branch() {
-   git branch 2> /dev/null > /dev/null
-    if [ $? = 0 ] ; then
-        git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /'
-        return 0
-    fi
-    # when wc-ng comes out, we'll probably do the following
-    # svn info 2> /dev/null > /dev/null
-    if [ -e .svn ] ; then
-        local d=`svn info | grep URL | sed 's/.*://'`
-        local br=`echo $d | awk '{
-                        if ( index($1, "trunk") ) {
-                            print  "trunk"
-                        } else {
-                            x = index($1, "branches") ;
-                            if ( x != 0 ) {
-                                sub(".*/branches/", "");
-                                sub("/.*", "");
-                                print $0
-                            }
-                        }
-                    }'`
-        local rev=`svn info | grep Revision | sed 's/.*: /r/'`
-        echo $br $rev
-        return 0
-    fi
-    hg branch 2> /dev/null > /dev/null
-    if [ $? = 0 ] ; then
-        local br=`hg branch | head -c 10`
-        local rid=`hg parents | head -n 1 | awk '{print $2}' | head -c 7`
-        echo "$br $rid"
-        return 0
-    fi
-    return 1
-}
-
-function git_next_unmerged_file() {
-  git status | egrep '(unmerged|both modified)' | head -n 1 | sed 's/.*:   //'
-}
-alias git-next-unmerged-file=git_next_unmerged_file
-
-function git_repack_all() {
-  for repo in $(find . | \
-      grep '/objects/pack/' | \
-      sed -e 's%\.git/objects/pack/.*%%' | \
-      sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
-    pushd $repo
-    git repack -ad --window 100
-    git gc --prune="`date`"
-    popd
-  done
-}
-
-function git_fsck_all() {
-  for repo in $(find . | \
-      grep '/objects/pack/' | \
-      sed -e 's%\.git/objects/pack/.*%%' | \
-      sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
-    pushd $repo
-    git fsck
-    popd
-  done
-}
-
-# change to the root dir of the current wc
-function wcroot() {
-    local root=`hg root 2> /dev/null`
-    if [ x$root != 'x' ] ; then
-        cd $root
-        return 0
-    fi
-    git branch 2> /dev/null > /dev/null
-    if [ $? = 0 ] ; then
-        while [ ! -e .git ] ; do
-            cd ..
-        done
-        return 0
-    fi
-    if [ -e .svn ] ; then
-        while [ -e ../.svn ] ; do
-            cd ..
-        done
-        return 0
-    fi
-    echo No working copy found'!'
-}
--- a/.shell.d/50.vcs_functions.sh
+++ b/.shell.d/50.vcs_functions.sh
@@ -2,16 +2,6 @@
 # This file contains a handful of functions that relate to using some version
 # control tool or other.
 
-function mq () {
-    ( wcroot ;
-       hg -R .hg/patches $@
-     )
-}
-
-function mq-snapshot () {
-    mq ci -m "Applied on $(hg log -r qparent --template '{node|short}\n')"
-}
-
 function ezsvnsync() {
     if [ x"$1" = "x" ] ; then
         echo 'usage: ez-svn-sync repo url'
@@ -51,78 +41,6 @@ function svnurlof() {
     echo $url
 }
 
-function hgsvnmergebranch() {
-    local targetrev
-    local striprev
-    targetrev=$(hg id | cut -d ' ' -f 1)
-    hg merge $1
-    hg ci -m "Merging $1"
-    striprev=$(hg id | cut -d ' ' -f 1)
-    hg co $targetrev
-    hg diff -r$targetrev:$striprev | hg import - -m "Merged branch $1."
-    hg strip $striprev
-}
-alias hg-svn-merge-branch=hgsvnmergebranch
-
-function hgsvnrebaseall() {
-    for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq`
-    do
-        echo "rebase $b"
-        hg co $b
-        if [[ "$?" != "0" ]] ; then
-            echo "abort: could not checkout $b"
-            return
-        fi
-        hg parent --svn > /dev/null
-        if [[ "$?" == "0" ]] ; then
-            hg rebase --svn || return
-        else
-            echo "Skip $b since it has a merge."
-        fi
-    done
-}
-alias hg-svn-rebase-all=hgsvnrebaseall
-
-function hgamend() {
-    hg qimport -r . && hg qref && hg qfin qtip
-}
-alias hg-amend=hgamend
-
-function hg_verify_all() {
-  for x in $(find . -name '.hg') ; do
-    y=$(dirname $x)
-    echo $y
-    hg verify -R $y
-  done
-}
-
-function hgsvnmkbranch() {
-    local upstream
-    upstream=$(hg paths default | sed 's%/*$%%')
-    local branchname
-    if [ "x$1" = "x" ] ; then
-        echo 'Must provide new branch name.'
-        return 1
-    fi
-    local d=`hg svn info | grep URL | sed 's/.*://'`
-    local br=`echo $d | awk '{
-            if ( index($1, "trunk") ) {
-                    print  "trunk"
-                } else {
-                    x = index($1, "branches") ;
-                    if ( x != 0 ) {
-                            sub(".*/branches/", "");
-                            sub("/.*", "");
-                            print $0
-                        }
-                }
-                }'`
-
-    branchname=$br
-    echo svn cp $upstream/$branchname $upstream/branches/$1
-}
-alias hg-svn-mkbranch=hgsvnmkbranch
-
 # Function to clean locks out of svn wcs
 function clean_svn_source_trees() {
     for aa in */ ; do
@@ -215,34 +133,6 @@ function vcs_current_branch() {
     return 1
 }
 
-function git_next_unmerged_file() {
-  git status | egrep '(unmerged|both modified)' | head -n 1 | sed 's/.*:   //'
-}
-alias git-next-unmerged-file=git_next_unmerged_file
-
-function git_repack_all() {
-  for repo in $(find . | \
-      grep '/objects/pack/' | \
-      sed -e 's%\.git/objects/pack/.*%%' | \
-      sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
-    pushd $repo
-    git repack -ad --window 100
-    git gc --prune="`date`"
-    popd
-  done
-}
-
-function git_fsck_all() {
-  for repo in $(find . | \
-      grep '/objects/pack/' | \
-      sed -e 's%\.git/objects/pack/.*%%' | \
-      sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
-    pushd $repo
-    git fsck
-    popd
-  done
-}
-
 # change to the root dir of the current wc
 function wcroot() {
     local root=`hg root 2> /dev/null`