]> git.draconx.ca Git - scripts.git/blob - gitcvs.zsh
Add script to convert "JWK"-format RSA keys to normal.
[scripts.git] / gitcvs.zsh
1 #!/usr/bin/env zsh
2 #
3 # Copyright © 2008-2011 Nick Bowler
4 #
5 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 # This is free software: you are free to do what the fuck you want to.
7 # There is NO WARRANTY, to the extent permitted by law.
8
9 # List all commits that have not yet been committed to CVS.  (run this command
10 # from the root of the CVS repository)
11 git-cvs-commitlist() {
12         if [[ -z "$1" ]]; then
13                 echo "usage: git-cvs-commitlist <git_dir> [origin]" 1>&2
14                 return 1
15         fi
16
17         [[ -z "$2" ]] && 2="remotes/CVS/master"
18         [[ -d "$1/.git" ]] && 1="$1/.git"
19
20         GIT_DIR="$1" git cherry -v "$2"
21 }
22
23 # Commit a specified commit to CVS (run this command from the root of the CVS
24 # repository).
25 git-cvs-commit() {
26         if [[ -z "$1" || -z "$2" ]]; then
27                 echo "usage: git-cvs-commit <git_dir> <commit>" 1>&2
28                 return 1
29         fi
30
31         [[ -d "$1/.git" ]] && 1="$1/.git"
32
33         GIT_DIR="$1" git cvsexportcommit -cvp "$2"
34 }
35
36 # Commit all commits that are not yet in CVS to CVS.
37 # (run this command from the root of the CVS repository).
38 git-cvs-commit-all() {
39         if [[ -z "$1" ]]; then
40                 echo "usage: git-cvs-commit-all <git_dir>" 1>&2
41                 return 1
42         fi
43
44         git-cvs-commitlist $1 | while read i; do
45                 local commit=$(echo $i | cut -d ' ' -f 2)
46                 git-cvs-commit $1 $commit || return $?
47         done
48 }
49
50 # Import the latest and greatest changes into a git repository (will create
51 # a new repository if run outside of any git repo).
52 #
53 # The details used to fetch from CVS are recorded so that running
54 # git-cvs-fetch with no arguments will repeat the same fetch as last time.
55 # Currently, some arguments which don't make sense to record are recorded
56 # anyway, so you may need to manually edit .git/config afterwards...
57 git-cvs-fetch() {
58         local tmp cvsroot cvsmod cvsopts
59
60         cvsroot=${$(git config cvs.root):-$CVSROOT}
61         cvsopts=${$(git config cvs.opts):-'$@'}
62         eval "cvsopts=($cvsopts)"
63
64         # Extract a CVS root from opts, if any.
65         while [[ $((tmp=${cvsopts[(i)-d*]})) -le $#cvsopts ]]; do
66                 cvsroot=${cvsopts[$tmp]#-d}
67                 cvsopts=($cvsopts[1,$tmp-1] $cvsopts[$tmp+1,-1])
68                 if [[ -z $cvsroot ]]; then
69                         cvsroot=${cvsopts[$tmp]}
70                         cvsopts=($cvsopts[1,$tmp-1] $cvsopts[$tmp+1,-1])
71                 fi
72         done
73
74         if ! cvsmod=$(git config cvs.module); then
75                 cvsmod=$cvsopts[-1]
76                 cvsopts=($cvsopts[1,-2])
77         fi
78
79         # By this point, we must have a CVS root and module.
80         if [[ -z $cvsroot ]]; then
81                 printf '%s: no CVS root set.\n' $0 1>&2
82                 return 1
83         fi
84
85         if [[ -z $cvsmod ]]; then
86                 printf '%s: no CVS module set.\n' $0 1>&2
87                 return 1
88         fi
89
90         GIT_DIR=`git rev-parse --git-dir 2>/dev/null` git cvsimport \
91                 -air CVS -d $cvsroot $cvsopts $cvsmod || return 1
92
93         # Store the settings for this run.
94         git config cvs.root   $cvsroot
95         git config cvs.module $cvsmod
96         [[ $#cvsopts -gt 0 ]] && git config cvs.opts ${(j: :)${(qq)cvsopts}}
97         :
98 }
99
100 # Generate an excludes file, suitable for writing to .git/info/exclude, based
101 # on .cvsignore files found in the repository.  Run this command from the git
102 # repository.
103 git-cvs-genexclude() {
104         local dir i j cvsdefaults work
105
106         work=`git rev-parse --show-toplevel` || return 1
107         if test -z $work; then
108                 printf '%s: must be run from the work tree\n' $0 1>&2
109                 return 1
110         fi
111
112         printf '#\n# Automatically generated by %s\n#\n' "$0 $*"
113
114         # CVS ignores a number of patterns by default.
115         cvsdefaults=(
116                 'RCS'   'SCCS'  'CVS'   'CVS.adm' 'RCSLOG' 'cvslog.*'
117                 'tags'  'TAGS'  '.make.state'     '.nse_depinfo'
118                 '*~'    '#*'    '.#*'   ',*'      '_$*'    '*$'
119                 '*.old' '*.bak' '*.BAK' '*.orig'  '*.rej'  '.del-*'
120                 '*.a'   '*.olb' '*.o'   '*.obj'   '*.so'   '*.exe'
121                 '*.Z'   '*.elc' '*.ln'  'core'
122         )
123         printf '%s\n' $cvsdefaults
124
125         find $work -name .cvsignore | while read i; do
126                 dir=${$(dirname $i)#$work}
127
128                 < $i while read j; do
129                         printf '%s/%s\n' $dir $j
130                 done
131         done
132 }
133
134 # For executable-like invocation...
135
136 # It would be nice if we could detect whether we are invoked as an executable
137 # and print a usage message if not given any arguments.  I have yet to find
138 # a clean way to do this, however.
139
140 if [ $# -gt 0 ]; then
141         func="git-cvs-${1#git-cvs-}"
142         shift
143         "$func" $@
144 fi