comparison .shell.d/50.vcs_functions.sh @ 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 9e45ac5350fd
children da06f9fd5016
comparison
equal deleted inserted replaced
209:c28a1e2c746a 210:0590f34b92a0
1 ## vcs_functions 1 ## vcs_functions
2 # This file contains a handful of functions that relate to using some version 2 # This file contains a handful of functions that relate to using some version
3 # control tool or other. 3 # control tool or other.
4
5 function mq () {
6 ( wcroot ;
7 hg -R .hg/patches $@
8 )
9 }
10
11 function mq-snapshot () {
12 mq ci -m "Applied on $(hg log -r qparent --template '{node|short}\n')"
13 }
14 4
15 function ezsvnsync() { 5 function ezsvnsync() {
16 if [ x"$1" = "x" ] ; then 6 if [ x"$1" = "x" ] ; then
17 echo 'usage: ez-svn-sync repo url' 7 echo 'usage: ez-svn-sync repo url'
18 return 0 8 return 0
48 if [ x"$url" = "x" ] ; then 38 if [ x"$url" = "x" ] ; then
49 echo -n 'No repo found (tried svn, git-svn, hgsubversion)' 39 echo -n 'No repo found (tried svn, git-svn, hgsubversion)'
50 fi 40 fi
51 echo $url 41 echo $url
52 } 42 }
53
54 function hgsvnmergebranch() {
55 local targetrev
56 local striprev
57 targetrev=$(hg id | cut -d ' ' -f 1)
58 hg merge $1
59 hg ci -m "Merging $1"
60 striprev=$(hg id | cut -d ' ' -f 1)
61 hg co $targetrev
62 hg diff -r$targetrev:$striprev | hg import - -m "Merged branch $1."
63 hg strip $striprev
64 }
65 alias hg-svn-merge-branch=hgsvnmergebranch
66
67 function hgsvnrebaseall() {
68 for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq`
69 do
70 echo "rebase $b"
71 hg co $b
72 if [[ "$?" != "0" ]] ; then
73 echo "abort: could not checkout $b"
74 return
75 fi
76 hg parent --svn > /dev/null
77 if [[ "$?" == "0" ]] ; then
78 hg rebase --svn || return
79 else
80 echo "Skip $b since it has a merge."
81 fi
82 done
83 }
84 alias hg-svn-rebase-all=hgsvnrebaseall
85
86 function hgamend() {
87 hg qimport -r . && hg qref && hg qfin qtip
88 }
89 alias hg-amend=hgamend
90
91 function hg_verify_all() {
92 for x in $(find . -name '.hg') ; do
93 y=$(dirname $x)
94 echo $y
95 hg verify -R $y
96 done
97 }
98
99 function hgsvnmkbranch() {
100 local upstream
101 upstream=$(hg paths default | sed 's%/*$%%')
102 local branchname
103 if [ "x$1" = "x" ] ; then
104 echo 'Must provide new branch name.'
105 return 1
106 fi
107 local d=`hg svn info | grep URL | sed 's/.*://'`
108 local br=`echo $d | awk '{
109 if ( index($1, "trunk") ) {
110 print "trunk"
111 } else {
112 x = index($1, "branches") ;
113 if ( x != 0 ) {
114 sub(".*/branches/", "");
115 sub("/.*", "");
116 print $0
117 }
118 }
119 }'`
120
121 branchname=$br
122 echo svn cp $upstream/$branchname $upstream/branches/$1
123 }
124 alias hg-svn-mkbranch=hgsvnmkbranch
125 43
126 # Function to clean locks out of svn wcs 44 # Function to clean locks out of svn wcs
127 function clean_svn_source_trees() { 45 function clean_svn_source_trees() {
128 for aa in */ ; do 46 for aa in */ ; do
129 pushd $aa > /dev/null 47 pushd $aa > /dev/null
213 return 0 131 return 0
214 fi 132 fi
215 return 1 133 return 1
216 } 134 }
217 135
218 function git_next_unmerged_file() {
219 git status | egrep '(unmerged|both modified)' | head -n 1 | sed 's/.*: //'
220 }
221 alias git-next-unmerged-file=git_next_unmerged_file
222
223 function git_repack_all() {
224 for repo in $(find . | \
225 grep '/objects/pack/' | \
226 sed -e 's%\.git/objects/pack/.*%%' | \
227 sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
228 pushd $repo
229 git repack -ad --window 100
230 git gc --prune="`date`"
231 popd
232 done
233 }
234
235 function git_fsck_all() {
236 for repo in $(find . | \
237 grep '/objects/pack/' | \
238 sed -e 's%\.git/objects/pack/.*%%' | \
239 sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
240 pushd $repo
241 git fsck
242 popd
243 done
244 }
245
246 # change to the root dir of the current wc 136 # change to the root dir of the current wc
247 function wcroot() { 137 function wcroot() {
248 local root=`hg root 2> /dev/null` 138 local root=`hg root 2> /dev/null`
249 if [ x$root != 'x' ] ; then 139 if [ x$root != 'x' ] ; then
250 cd $root 140 cd $root