]>
Commit | Line | Data |
---|---|---|
149dcd4d MF |
1 | #!/bin/bash |
2 | ||
3 | err() { echo "error: $*" >&2; exit 1; } | |
4 | ||
5 | _cvs_url() { | |
6 | [[ $# -gt 1 ]] && err "accepted args: <file>[:rev1[:rev2]]" | |
7 | ||
8 | # spec has the form file:rev1[:rev2] | |
9 | # rev2 defaults to rev1-1 | |
10 | export IFS=: | |
11 | set -- $1 | |
12 | unset IFS | |
13 | ||
14 | local file=$1 | |
15 | if [[ ! -e ${file} ]] ; then | |
16 | echo "file '${file}' does not exist" | |
17 | return 1 | |
18 | fi | |
19 | local dir="." | |
20 | [[ ${file} == */* ]] && dir=${file%/*} | |
21 | file=${file##*/} | |
22 | ||
23 | local rev2=$2 | |
24 | if [[ -z ${rev2} ]] ; then | |
25 | rev2=$( | |
26 | cd ${dir} | |
27 | export IFS=/ | |
28 | set -- $(grep /${file}/ CVS/Entries) | |
29 | unset IFS | |
30 | echo $3 | |
31 | ) | |
32 | if [[ ${rev2} == "0" ]] ; then | |
33 | # new file | |
34 | rev2="1.1" | |
35 | else | |
36 | # existing file, bump rev automatically | |
37 | rev2="1.$((${rev2#1.}+1))" | |
38 | fi | |
39 | fi | |
40 | local rev2r=${rev2#1.} | |
41 | local rev1=${3:-1.$((rev2r - 1))} | |
42 | ||
43 | local cvsroot=$(<${dir}/CVS/Repository) | |
44 | if [[ ${cvsroot} == gentoo-x86* ]] ; then | |
45 | cvsroot=${cvsroot#gentoo-x86} | |
46 | cvsroot=${cvsroot#/} | |
47 | fi | |
48 | ||
49 | local urirev | |
50 | [[ ${rev2} == "1.1" || ${rev1} == "${rev2}" ]] \ | |
51 | && urirev="?rev=${rev2}" \ | |
52 | || urirev="?r1=${rev1}&r2=${rev2}" | |
225a775d | 53 | echo "https://sources.gentoo.org/${cvsroot}/${file}${urirev}" |
149dcd4d MF |
54 | } |
55 | cvs_url() { | |
56 | local f | |
57 | for f in "$@" ; do | |
58 | _cvs_url "${f}" | |
59 | done | |
60 | } | |
61 | ||
62 | git_url() { | |
02b192ca | 63 | [[ $# -gt 1 ]] && err "accepted args: <rev>" |
149dcd4d MF |
64 | |
65 | local repo url | |
66 | local remote=$(git config remote.origin.url) | |
67 | case ${remote} in | |
68 | *://uclibc.org/*|*://git.uclibc.org/*|\ | |
69 | *://busybox.net/*|*://git.busybox.net/*|\ | |
70 | *://buildroot.org/*|*://git.buildroot.org/*|\ | |
71 | *://buildroot.net/*|*://git.buildroot.net/*) | |
72 | repo=$(echo "${remote}" | sed -e 's,^[^:]*://[^/]*/,,' -e 's:[.]git$::') | |
621075aa MF |
73 | url="https://git." |
74 | case ${repo} in | |
75 | uclibc) url+="uclibc.org" ;; | |
76 | buildroot) url+="buildroot.org" ;; | |
77 | *) url+="busybox.net" ;; | |
78 | esac | |
79 | url+="/${repo}/commit/?id=" | |
149dcd4d MF |
80 | ;; |
81 | *://git@git.gentoo.org/*|\ | |
82 | *://anongit.gentoo.org/*) | |
83 | repo=$(echo "${remote}" | sed 's:.*git[.a-z]*.gentoo.org/::') | |
225a775d | 84 | url="https://gitweb.gentoo.org/${repo}/commit/?id=" |
149dcd4d | 85 | ;; |
a23d5466 | 86 | git@github.com[:/]*|\ |
149dcd4d | 87 | *://github.com/*) |
a23d5466 | 88 | repo=$(echo "${remote}" | sed -e 's,^git@github.com[:/],,' -e 's,^https://github.com/,,' -e 's,^git://github.com/,,' -e 's:[.]git$::') |
149dcd4d MF |
89 | url="https://github.com/${repo}/commit/" |
90 | ;; | |
a7e8a010 MF |
91 | git@gitlab.com[:/]*|\ |
92 | *://gitlab.com/*) | |
93 | repo=$(echo "${remote}" | sed -e 's,^git@gitlab.com[:/],,' -e 's,^https://gitlab.com/,,' -e 's,^git://gitlab.com/,,' -e 's:[.]git$::') | |
94 | url="https://gitlab.com/${repo}/commit/" | |
95 | ;; | |
afcb1683 MF |
96 | git://git.sv.gnu.org/*|git://git.savannah.gnu.org/*) |
97 | repo=$(echo "${remote}" | sed -r -e 's,^git://git.(sv|savannah).gnu.org/,,' -e 's:[.]git$::') | |
ed2392be MF |
98 | url="http://git.savannah.gnu.org/cgit/${repo}.git/commit/?h=" |
99 | ;; | |
b5612fc0 MF |
100 | git://git.sv.nongnu.org/*|git://git.savannah.nongnu.org/*) |
101 | repo=$(echo "${remote}" | sed -r -e 's,^git://git.(sv|savannah).nongnu.org/,,' -e 's:[.]git$::') | |
102 | url="http://git.savannah.nongnu.org/cgit/${repo}.git/commit/?h=" | |
103 | ;; | |
97f084d1 MF |
104 | git://git.code.sf.net/p/*|ssh://*@git.code.sf.net/p/*) |
105 | repo=$(echo "${remote}" | sed -r -e 's,(git://|ssh://([^@]*@)?)git.code.sf.net/p/([^/]*)/.*,\3,') | |
106 | url="https://sourceforge.net/p/${repo}/code/ci/" | |
225a775d | 107 | ;; |
50ad3abc MF |
108 | *://sourceware.org/*) |
109 | repo=$(echo "${remote}" | sed -e 's,.*/,,' -e 's,[.]git$,,') | |
110 | url="https://sourceware.org/git/?p=${repo}.git;a=commit;h=" | |
111 | ;; | |
112 | *.googlesource.com/*) | |
113 | url="${remote%.git}/+/" | |
114 | ;; | |
a23d5466 MF |
115 | *://git.enlightenment.org/*) |
116 | repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') | |
117 | url="https://git.enlightenment.org/${repo}.git/commit/?id=" | |
118 | ;; | |
afcb1683 MF |
119 | *://git.qemu.org/*) |
120 | repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') | |
b5612fc0 MF |
121 | url="https://git.qemu.org/?p=${repo}.git;a=commit;h=" |
122 | ;; | |
123 | *://git.kernel.org/*) | |
124 | repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') | |
125 | url="https://git.kernel.org/${repo}.git/commit/?id=" | |
afcb1683 | 126 | ;; |
149dcd4d MF |
127 | *) |
128 | echo "Unknown remote: ${remote}" | |
129 | exit 1 | |
130 | ;; | |
131 | esac | |
132 | ||
133 | git log -n3 ${1:-HEAD} | sed "s,^commit ,${url}," | |
134 | } | |
135 | ||
136 | svn_url() { | |
137 | if [[ $# -eq 0 ]] ; then | |
138 | svn info | \ | |
139 | awk '{ | |
140 | if ($1 == "URL:") { | |
9430565d | 141 | URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/, "\\1", 1); |
149dcd4d MF |
142 | } else if ($1 == "Revision:") { |
143 | rev = $2 | |
144 | URL = URL "?rev=" (rev + 1) "&view=rev" | |
145 | } | |
146 | } | |
147 | END { print URL }' | |
148 | return 0 | |
149 | fi | |
150 | ||
151 | local f | |
152 | for f in "$@" ; do | |
153 | svn info "${f}" | \ | |
154 | awk '{ | |
155 | if ($1 == "URL:") { | |
156 | sub(/.*svnroot/,"") | |
157 | URL = "http://sources.gentoo.org" $1 "?" | |
158 | } else if ($1 == "Revision:") { | |
159 | rev = $2 | |
160 | URL = URL "r1=" rev "&r2=" (rev + 1) | |
161 | } | |
162 | } | |
163 | END { print URL }' | |
164 | done | |
165 | } | |
166 | ||
167 | usage() { | |
168 | exec cat <<-EOF | |
169 | Usage: $0 [options] [args] | |
170 | ||
171 | Options: | |
172 | -c CVS URL | |
173 | -g GIT URL (default) | |
174 | -s SVN URL | |
175 | -x Trace the script | |
176 | -h Help | |
177 | EOF | |
178 | } | |
179 | ||
180 | main() { | |
afcb1683 | 181 | local vcs="auto" |
149dcd4d MF |
182 | while [[ $# -gt 0 ]] ; do |
183 | case $1 in | |
184 | -c) vcs="cvs";; | |
185 | -s) vcs="svn";; | |
186 | -g) vcs="git";; | |
187 | -x) set -x;; | |
188 | -h) usage;; | |
189 | --) shift; break;; | |
190 | -*) usage;; | |
191 | *) break;; | |
192 | esac | |
193 | shift | |
194 | done | |
195 | ||
afcb1683 MF |
196 | if [[ ${vcs} == "auto" ]] ; then |
197 | if [[ -d CVS ]] ; then | |
198 | vcs="cvs" | |
199 | elif svn info >&/dev/null ; then | |
200 | vcs="svn" | |
201 | else | |
202 | vcs="git" | |
203 | fi | |
204 | fi | |
205 | ||
149dcd4d MF |
206 | case ${vcs} in |
207 | cvs) cvs_url "$@";; | |
208 | git) git_url "$@";; | |
209 | svn) svn_url "$@";; | |
210 | esac | |
211 | } | |
212 | main "$@" |