Mercurial > dotfiles
annotate .shell.d/50.vcs_functions.sh @ 59:2eb8cbc08070
Add a script that builds serf and subversion assuming all other deps are installed so that I can wipe and rebuild a little easier.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Mon, 02 Mar 2009 15:01:30 -0600 |
| parents | 20834b97b814 |
| children | 87b2ccf6ec44 |
| rev | line source |
|---|---|
| 0 | 1 ## vcs_functions |
| 2 # This file contains a handful of functions that relate to using some version | |
| 3 # control tool or other. | |
| 4 | |
|
13
c22ca1514f3b
Add an alias to ease working with mq repos.
Augie Fackler <durin42@gmail.com>
parents:
10
diff
changeset
|
5 alias mq='hg -R .hg/patches' |
|
c22ca1514f3b
Add an alias to ease working with mq repos.
Augie Fackler <durin42@gmail.com>
parents:
10
diff
changeset
|
6 |
| 0 | 7 # Function to grab the url of an svn wc |
| 8 function svnurlof() { | |
| 9 local url | |
| 10 url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
| 11 if [ x"$url" = "x" ] ; then | |
| 12 url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
| 13 fi | |
| 14 if [ x"$url" = "x" ] ; then | |
|
46
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
15 local dir |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
16 dir=$1 |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
17 if [ x"$dir" = "x" ] ; then |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
18 dir="." |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
19 fi |
| 0 | 20 url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` |
| 21 fi | |
| 22 if [ x"$url" = "x" ] ; then | |
| 23 echo -n 'No repo found (tried svn, git-svn, hgsvnclient)' | |
| 24 fi | |
| 25 echo $url | |
| 26 } | |
| 27 | |
|
58
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
28 function hg-svn-rebase-all() { |
|
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
29 for b in `hg llog -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq` |
|
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
30 do |
|
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
31 hg co $b && hg svn rebase || return |
|
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
32 done |
|
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
33 } |
|
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
34 |
|
46
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
35 function hg-svn-mkbranch() { |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
36 local upstream |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
37 upstream=$(hg svn url) |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
38 local branchname |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
39 if [ "x$1" = "x" ] ; then |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
40 echo 'Must provide new branch name.' |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
41 return 1 |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
42 fi |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
43 local d=`hg svn info | grep URL | sed 's/.*://'` |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
44 local br=`echo $d | awk '{ |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
45 if ( index($1, "trunk") ) { |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
46 print "trunk" |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
47 } else { |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
48 x = index($1, "branches") ; |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
49 if ( x != 0 ) { |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
50 sub(".*/branches/", ""); |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
51 sub("/.*", ""); |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
52 print $0 |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
53 } |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
54 } |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
55 }'` |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
56 |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
57 branchname=$br |
|
47
e80bc65439ac
Too clever for my own good in this function.
Augie Fackler <durin42@gmail.com>
parents:
46
diff
changeset
|
58 echo svn cp $upstream/$branchname $upstream/branches/$1 |
|
46
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
59 } |
|
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
60 |
| 0 | 61 # Function to clean locks out of svn wcs |
| 62 function clean_svn_source_trees() { | |
| 63 for aa in */ ; do | |
| 64 pushd $aa > /dev/null | |
| 65 if [ -e .svn ] ; then | |
| 66 echo $aa 'is an svn checkout, cleaning' && svn cleanup | |
| 67 fi | |
| 68 popd > /dev/null | |
| 69 done | |
| 70 } | |
| 71 | |
| 72 # Function to update source trees of known VCS tools in the working dir. | |
| 73 # "known" means ones I'm forced to use on a regular basis | |
| 74 function update_source_trees() { | |
| 75 for aa in */ ; do | |
|
31
a5691a22c92b
Fix a bug in update_source_trees where it could eat any existing dirstack
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
76 pushd $aa > /dev/null || continue |
| 0 | 77 if [ -e .svn ] ; then |
| 78 echo $aa 'is an svn checkout, updating' | |
| 79 svn up | |
| 80 elif [ -e .hg/svn ] ; then | |
| 81 echo $aa 'is an hg-svn checkout, updating' | |
| 82 hg svn pull | |
| 83 hg up | |
| 84 elif [ -e .git/svn ] ; then | |
| 85 echo $aa 'is a git-svn checkout, updating' | |
| 86 git svn fetch | |
| 87 git repack | |
| 88 git gc | |
| 89 elif [ -e .git ] ; then | |
| 90 echo $aa 'is a git checkout, updating' | |
| 91 git pull origin master | |
| 92 git repack | |
| 93 git gc | |
| 94 elif [ -e .hg ] ; then | |
| 95 echo $aa 'is an hg checkout, updating' && hg pull && hg up | |
|
35
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
96 if [ -e .hg/patches/.hg ] ; then |
|
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
97 echo $aa 'has an mq, updating that too...' |
|
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
98 hg -R .hg/patches pull -u |
|
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
99 fi |
| 0 | 100 elif [ -e _MTN ] ; then |
| 101 echo $aa "is an mtn co, updating" && mtn pull && mtn up | |
| 102 fi | |
| 103 popd > /dev/null | |
| 104 done | |
| 105 } | |
| 106 | |
| 107 function vcs_current_branch() { | |
|
10
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
108 git branch 2> /dev/null > /dev/null |
| 0 | 109 if [ $? = 0 ] ; then |
| 110 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /' | |
| 111 return 0 | |
| 112 fi | |
| 113 # when wc-ng comes out, we'll probably do the following | |
| 114 # svn info 2> /dev/null > /dev/null | |
| 115 if [ -e .svn ] ; then | |
| 116 local d=`svn info | grep URL | sed 's/.*://'` | |
| 117 local br=`echo $d | awk '{ | |
| 118 if ( index($1, "trunk") ) { | |
| 119 print "trunk" | |
| 120 } else { | |
| 121 x = index($1, "branches") ; | |
| 122 if ( x != 0 ) { | |
| 123 sub(".*/branches/", ""); | |
| 124 sub("/.*", ""); | |
| 125 print $0 | |
| 126 } | |
| 127 } | |
| 128 }'` | |
| 129 local rev=`svn info | grep Revision | sed 's/.*: /r/'` | |
| 130 echo $br $rev | |
| 131 return 0 | |
| 132 fi | |
|
10
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
133 hg branch 2> /dev/null > /dev/null |
|
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
134 if [ $? = 0 ] ; then |
|
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
135 local br=`hg branch | head -c 10` |
|
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
136 local rid=`hg parents | head -n 1 | awk '{print $2}' | head -c 7` |
|
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
137 echo "$br $rid" |
|
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
138 return 0 |
|
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
139 fi |
| 0 | 140 return 1 |
| 141 } | |
| 142 | |
| 143 # change to the root dir of the current wc | |
| 144 function wcroot() { | |
| 145 local root=`hg root 2> /dev/null` | |
| 146 if [ x$root != 'x' ] ; then | |
| 147 cd $root | |
| 148 return 0 | |
| 149 fi | |
| 150 git branch 2> /dev/null > /dev/null | |
| 151 if [ $? = 0 ] ; then | |
| 152 while [ ! -e .git ] ; do | |
| 153 cd .. | |
| 154 done | |
| 155 return 0 | |
| 156 fi | |
| 157 if [ -e .svn ] ; then | |
| 158 while [ -e ../.svn ] ; do | |
| 159 cd .. | |
| 160 done | |
| 161 return 0 | |
| 162 fi | |
| 163 echo No working copy found'!' | |
| 164 } |
