Mercurial > dotfiles
annotate .zsh/50.vcs_functions.zsh @ 12:d4d720c4c416
Add mercurial support to emacs. Improve setting of PYTHONPATH in there.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 03 Dec 2008 22:34:01 -0600 |
parents | b4bfce76123f |
children | c22ca1514f3b |
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 | |
5 # Function to grab the url of an svn wc | |
6 function svnurlof() { | |
7 local url | |
8 url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
9 if [ x"$url" = "x" ] ; then | |
10 url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
11 fi | |
12 if [ x"$url" = "x" ] ; then | |
13 local dir | |
14 dir=$1 | |
15 if [ x"$dir" = "x" ] ; then | |
16 dir="." | |
17 fi | |
18 url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
19 fi | |
20 if [ x"$url" = "x" ] ; then | |
21 echo -n 'No repo found (tried svn, git-svn, hgsvnclient)' | |
22 fi | |
23 echo $url | |
24 } | |
25 | |
26 # Function to clean locks out of svn wcs | |
27 function clean_svn_source_trees() { | |
28 for aa in */ ; do | |
29 pushd $aa > /dev/null | |
30 if [ -e .svn ] ; then | |
31 echo $aa 'is an svn checkout, cleaning' && svn cleanup | |
32 fi | |
33 popd > /dev/null | |
34 done | |
35 } | |
36 | |
37 # Function to update source trees of known VCS tools in the working dir. | |
38 # "known" means ones I'm forced to use on a regular basis | |
39 function update_source_trees() { | |
40 for aa in */ ; do | |
41 pushd $aa > /dev/null | |
42 if [ -e .svn ] ; then | |
43 echo $aa 'is an svn checkout, updating' | |
44 svn up | |
45 elif [ -e .hg/svn ] ; then | |
46 echo $aa 'is an hg-svn checkout, updating' | |
47 hg svn pull | |
48 hg svn gentags | |
49 hg up | |
50 elif [ -e .git/svn ] ; then | |
51 echo $aa 'is a git-svn checkout, updating' | |
52 git svn fetch | |
53 git repack | |
54 git gc | |
55 elif [ -e .git ] ; then | |
56 echo $aa 'is a git checkout, updating' | |
57 git pull origin master | |
58 git repack | |
59 git gc | |
60 elif [ -e .hg ] ; then | |
61 echo $aa 'is an hg checkout, updating' && hg pull && hg up | |
62 elif [ -e _MTN ] ; then | |
63 echo $aa "is an mtn co, updating" && mtn pull && mtn up | |
64 fi | |
65 popd > /dev/null | |
66 done | |
67 } | |
68 | |
69 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
|
70 git branch 2> /dev/null > /dev/null |
0 | 71 if [ $? = 0 ] ; then |
72 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /' | |
73 return 0 | |
74 fi | |
75 # when wc-ng comes out, we'll probably do the following | |
76 # svn info 2> /dev/null > /dev/null | |
77 if [ -e .svn ] ; then | |
78 local d=`svn info | grep URL | sed 's/.*://'` | |
79 local br=`echo $d | awk '{ | |
80 if ( index($1, "trunk") ) { | |
81 print "trunk" | |
82 } else { | |
83 x = index($1, "branches") ; | |
84 if ( x != 0 ) { | |
85 sub(".*/branches/", ""); | |
86 sub("/.*", ""); | |
87 print $0 | |
88 } | |
89 } | |
90 }'` | |
91 local rev=`svn info | grep Revision | sed 's/.*: /r/'` | |
92 echo $br $rev | |
93 return 0 | |
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 fi |
0 | 102 return 1 |
103 } | |
104 | |
105 # change to the root dir of the current wc | |
106 function wcroot() { | |
107 local root=`hg root 2> /dev/null` | |
108 if [ x$root != 'x' ] ; then | |
109 cd $root | |
110 return 0 | |
111 fi | |
112 git branch 2> /dev/null > /dev/null | |
113 if [ $? = 0 ] ; then | |
114 while [ ! -e .git ] ; do | |
115 cd .. | |
116 done | |
117 return 0 | |
118 fi | |
119 if [ -e .svn ] ; then | |
120 while [ -e ../.svn ] ; do | |
121 cd .. | |
122 done | |
123 return 0 | |
124 fi | |
125 echo No working copy found'!' | |
126 } |