annotate .shell.d/50.vcs_functions.sh @ 204:9e45ac5350fd

vcs funcs: tools for verifying hg or git repos, packing git repos
author Augie Fackler <durin42@gmail.com>
date Mon, 03 May 2010 00:48:39 -0500
parents a563c21235ad
children 0590f34b92a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 ## vcs_functions
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 # This file contains a handful of functions that relate to using some version
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 # control tool or other.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4
60
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
5 function mq () {
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
6 ( wcroot ;
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
7 hg -R .hg/patches $@
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
8 )
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
9 }
13
c22ca1514f3b Add an alias to ease working with mq repos.
Augie Fackler <durin42@gmail.com>
parents: 10
diff changeset
10
200
a563c21235ad vcs-functions: add mq-snapshot
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
11 function mq-snapshot () {
a563c21235ad vcs-functions: add mq-snapshot
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
12 mq ci -m "Applied on $(hg log -r qparent --template '{node|short}\n')"
a563c21235ad vcs-functions: add mq-snapshot
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
13 }
a563c21235ad vcs-functions: add mq-snapshot
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
14
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
15 function ezsvnsync() {
169
040ac89ffe1e ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents: 167
diff changeset
16 if [ x"$1" = "x" ] ; then
040ac89ffe1e ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents: 167
diff changeset
17 echo 'usage: ez-svn-sync repo url'
040ac89ffe1e ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents: 167
diff changeset
18 return 0
040ac89ffe1e ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents: 167
diff changeset
19 fi
63
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
20 local repo
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
21 repo=$1
169
040ac89ffe1e ez-svn-sync: add usage help
Augie Fackler <durin42@gmail.com>
parents: 167
diff changeset
22 local url
63
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
23 url=$2
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
24 svnadmin create $repo
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
25 echo '#!/bin/sh' >> $repo/hooks/pre-revprop-change
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
26 echo 'exit 0' >> $repo/hooks/pre-revprop-change
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
27 chmod +x $repo/hooks/pre-revprop-change
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
28 svnsync init file://`pwd`/$repo $url
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
29 svnsync sync file://`pwd`/$repo
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
30 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
31 alias ez-svn-sync=ezsvnsync
63
1b4067cc97ca Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents: 62
diff changeset
32
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 # Function to grab the url of an svn wc
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 function svnurlof() {
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 local url
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 if [ x"$url" = "x" ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 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
41 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
42 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
43 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
44 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
45 fi
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 if [ x"$url" = "x" ] ; then
167
f485c32913cd vcs functions: refer to hgsubversion by the real name
Augie Fackler <durin42@gmail.com>
parents: 156
diff changeset
49 echo -n 'No repo found (tried svn, git-svn, hgsubversion)'
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51 echo $url
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
54 function hgsvnmergebranch() {
61
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
55 local targetrev
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
56 local striprev
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
57 targetrev=$(hg id | cut -d ' ' -f 1)
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
58 hg merge $1
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
59 hg ci -m "Merging $1"
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
60 striprev=$(hg id | cut -d ' ' -f 1)
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
61 hg co $targetrev
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
62 hg diff -r$targetrev:$striprev | hg import - -m "Merged branch $1."
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
63 hg strip $striprev
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
64 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
65 alias hg-svn-merge-branch=hgsvnmergebranch
61
79c2c3932362 Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents: 60
diff changeset
66
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
67 function hgsvnrebaseall() {
69
5232fa3d7ad3 Changes required by log being back to the default.
Augie Fackler <durin42@gmail.com>
parents: 67
diff changeset
68 for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq`
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
69 do
67
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
70 echo "rebase $b"
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
71 hg co $b
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
72 if [[ "$?" != "0" ]] ; then
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
73 echo "abort: could not checkout $b"
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
74 return
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
75 fi
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
76 hg parent --svn > /dev/null
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
77 if [[ "$?" == "0" ]] ; then
83
568f9f350844 hg svn rebase is now hg rebase --svn
Augie Fackler <durin42@gmail.com>
parents: 81
diff changeset
78 hg rebase --svn || return
67
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
79 else
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
80 echo "Skip $b since it has a merge."
9f8bd97da0d4 hg-svn-rebase-all: improved rebasing so that merges no longer abort rebasing other branches.
Augie Fackler <durin42@gmail.com>
parents: 63
diff changeset
81 fi
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
82 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
83 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
84 alias hg-svn-rebase-all=hgsvnrebaseall
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
85
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
86 function hgamend() {
62
f9e826bd1f1b Add a function to ammend the latest revision in hg. I don't do this often, but when I need it it is handy.
Augie Fackler <durin42@gmail.com>
parents: 61
diff changeset
87 hg qimport -r . && hg qref && hg qfin qtip
f9e826bd1f1b Add a function to ammend the latest revision in hg. I don't do this often, but when I need it it is handy.
Augie Fackler <durin42@gmail.com>
parents: 61
diff changeset
88 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
89 alias hg-amend=hgamend
62
f9e826bd1f1b Add a function to ammend the latest revision in hg. I don't do this often, but when I need it it is handy.
Augie Fackler <durin42@gmail.com>
parents: 61
diff changeset
90
204
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
91 function hg_verify_all() {
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
92 for x in $(find . -name '.hg') ; do
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
93 y=$(dirname $x)
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
94 echo $y
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
95 hg verify -R $y
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
96 done
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
97 }
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
98
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
99 function hgsvnmkbranch() {
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
100 local upstream
129
1286c27cf0c0 Need to use paths default instead of the outdated svn url now.
Augie Fackler <durin42@gmail.com>
parents: 115
diff changeset
101 upstream=$(hg paths default | sed 's%/*$%%')
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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 } 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
112 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
113 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
114 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
115 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
116 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
117 }
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
118 }
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
119 }'`
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
120
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
121 branchname=$br
47
e80bc65439ac Too clever for my own good in this function.
Augie Fackler <durin42@gmail.com>
parents: 46
diff changeset
122 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
123 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
124 alias hg-svn-mkbranch=hgsvnmkbranch
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
125
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 # Function to clean locks out of svn wcs
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 function clean_svn_source_trees() {
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128 for aa in */ ; do
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129 pushd $aa > /dev/null
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 if [ -e .svn ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
131 echo $aa 'is an svn checkout, cleaning' && svn cleanup
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
133 popd > /dev/null
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
134 done
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
135 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137 # Function to update source trees of known VCS tools in the working dir.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 # "known" means ones I'm forced to use on a regular basis
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139 function update_source_trees() {
184
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
140 if ! ls -l | egrep ^d > /dev/null ; then
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
141 ls -l | egrep ^d
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
142 return
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
143 fi
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
144 local hgpath
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 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
146 pushd $aa > /dev/null || continue
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147 if [ -e .svn ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 echo $aa 'is an svn checkout, updating'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 svn up
115
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
150 elif [ -e README.txt ] \
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
151 && [ -e format ] \
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
152 && grep "This is a Subversion repository; use the 'svnadmin' tool to examine" README.txt > /dev/null \
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
153 && svn pl --revprop -r 0 file://$(pwd) | fgrep svn:sync-from-url > /dev/null\
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
154 ; then
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
155 echo "$aa looks like an svnsync clone, syncing"
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
156 svnsync sync file://$(pwd)
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157 elif [ -e .git/svn ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
158 echo $aa 'is a git-svn checkout, updating'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
159 git svn fetch
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
160 elif [ -e .git ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 echo $aa 'is a git checkout, updating'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 git pull origin master
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163 elif [ -e .hg ] ; then
184
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
164 echo $aa 'is an hg checkout, updating'
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
165 for hgpath in $(HGRCPATH=/dev/null hg paths | sed 's/.* = //g' | sort | uniq ) ; do
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
166 hg pull --update $hgpath
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
167 done
35
7e9269048856 Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents: 31
diff changeset
168 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
169 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
170 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
171 fi
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
172 elif [ -e _MTN ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
173 echo $aa "is an mtn co, updating" && mtn pull && mtn up
184
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
174 else
efa2bfc73d2d update-source-trees: recurse to find all VCS working copies
Augie Fackler <durin42@gmail.com>
parents: 169
diff changeset
175 update_source_trees
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
176 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
177 popd > /dev/null
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178 done
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
179 }
115
5f00625aa1ed Add support for svnsync to update_source_trees, alias update_source_trees to update-source-trees
Augie Fackler <durin42@gmail.com>
parents: 83
diff changeset
180 alias update-source-trees=update_source_trees
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
181
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
182 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
183 git branch 2> /dev/null > /dev/null
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184 if [ $? = 0 ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
185 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
186 return 0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
187 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
188 # when wc-ng comes out, we'll probably do the following
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
189 # svn info 2> /dev/null > /dev/null
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
190 if [ -e .svn ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
191 local d=`svn info | grep URL | sed 's/.*://'`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
192 local br=`echo $d | awk '{
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
193 if ( index($1, "trunk") ) {
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
194 print "trunk"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
195 } else {
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
196 x = index($1, "branches") ;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
197 if ( x != 0 ) {
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
198 sub(".*/branches/", "");
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
199 sub("/.*", "");
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
200 print $0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
201 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
202 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
203 }'`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
204 local rev=`svn info | grep Revision | sed 's/.*: /r/'`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
205 echo $br $rev
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
206 return 0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 fi
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
215 return 1
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
216 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
217
156
59ea03d7029a vcs_functions: add a function to grab the path of the next unmerged file from git
Augie Fackler <durin42@gmail.com>
parents: 133
diff changeset
218 function git_next_unmerged_file() {
195
e1a49db5c6ff git-next-unmerged-file: also include "both modified" files
Augie Fackler <durin42@gmail.com>
parents: 184
diff changeset
219 git status | egrep '(unmerged|both modified)' | head -n 1 | sed 's/.*: //'
156
59ea03d7029a vcs_functions: add a function to grab the path of the next unmerged file from git
Augie Fackler <durin42@gmail.com>
parents: 133
diff changeset
220 }
59ea03d7029a vcs_functions: add a function to grab the path of the next unmerged file from git
Augie Fackler <durin42@gmail.com>
parents: 133
diff changeset
221 alias git-next-unmerged-file=git_next_unmerged_file
59ea03d7029a vcs_functions: add a function to grab the path of the next unmerged file from git
Augie Fackler <durin42@gmail.com>
parents: 133
diff changeset
222
204
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
223 function git_repack_all() {
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
224 for repo in $(find . | \
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
225 grep '/objects/pack/' | \
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
226 sed -e 's%\.git/objects/pack/.*%%' | \
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
227 sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
228 pushd $repo
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
229 git repack -ad --window 100
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
230 git gc --prune="`date`"
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
231 popd
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
232 done
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
233 }
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
234
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
235 function git_fsck_all() {
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
236 for repo in $(find . | \
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
237 grep '/objects/pack/' | \
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
238 sed -e 's%\.git/objects/pack/.*%%' | \
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
239 sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
240 pushd $repo
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
241 git fsck
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
242 popd
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
243 done
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
244 }
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
245
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
246 # change to the root dir of the current wc
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
247 function wcroot() {
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
248 local root=`hg root 2> /dev/null`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
249 if [ x$root != 'x' ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
250 cd $root
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
251 return 0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
252 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
253 git branch 2> /dev/null > /dev/null
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
254 if [ $? = 0 ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
255 while [ ! -e .git ] ; do
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
256 cd ..
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
257 done
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
258 return 0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
259 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
260 if [ -e .svn ] ; then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
261 while [ -e ../.svn ] ; do
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
262 cd ..
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
263 done
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
264 return 0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
265 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
266 echo No working copy found'!'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
267 }