]>
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) | |
a1826e38 MF |
67 | |
68 | if [[ -z ${remote} ]] ; then | |
69 | # Maybe the repo doesn't use "origin". Try harder. | |
70 | local branch=$(git rev-parse --abbrev-ref HEAD) | |
71 | remote=$(git config "branch.${branch}.remote") | |
72 | if [[ -n ${remote} ]] ; then | |
73 | remote=$(git config "remote.${remote}.url") | |
b6a56800 MF |
74 | else |
75 | # Still try harder. | |
76 | local remotes=$(git config --get-regexp 'remote\..*\.url') | |
77 | if [[ -n ${remotes} ]]; then | |
78 | remote=$(echo "${remotes}" | awk '{print $2; exit}') | |
79 | fi | |
a1826e38 MF |
80 | fi |
81 | fi | |
82 | ||
149dcd4d MF |
83 | case ${remote} in |
84 | *://uclibc.org/*|*://git.uclibc.org/*|\ | |
85 | *://busybox.net/*|*://git.busybox.net/*|\ | |
86 | *://buildroot.org/*|*://git.buildroot.org/*|\ | |
87 | *://buildroot.net/*|*://git.buildroot.net/*) | |
88 | repo=$(echo "${remote}" | sed -e 's,^[^:]*://[^/]*/,,' -e 's:[.]git$::') | |
621075aa MF |
89 | url="https://git." |
90 | case ${repo} in | |
91 | uclibc) url+="uclibc.org" ;; | |
92 | buildroot) url+="buildroot.org" ;; | |
93 | *) url+="busybox.net" ;; | |
94 | esac | |
95 | url+="/${repo}/commit/?id=" | |
149dcd4d MF |
96 | ;; |
97 | *://git@git.gentoo.org/*|\ | |
98 | *://anongit.gentoo.org/*) | |
99 | repo=$(echo "${remote}" | sed 's:.*git[.a-z]*.gentoo.org/::') | |
225a775d | 100 | url="https://gitweb.gentoo.org/${repo}/commit/?id=" |
149dcd4d | 101 | ;; |
a23d5466 | 102 | git@github.com[:/]*|\ |
149dcd4d | 103 | *://github.com/*) |
a23d5466 | 104 | repo=$(echo "${remote}" | sed -e 's,^git@github.com[:/],,' -e 's,^https://github.com/,,' -e 's,^git://github.com/,,' -e 's:[.]git$::') |
149dcd4d MF |
105 | url="https://github.com/${repo}/commit/" |
106 | ;; | |
a7e8a010 MF |
107 | git@gitlab.com[:/]*|\ |
108 | *://gitlab.com/*) | |
109 | repo=$(echo "${remote}" | sed -e 's,^git@gitlab.com[:/],,' -e 's,^https://gitlab.com/,,' -e 's,^git://gitlab.com/,,' -e 's:[.]git$::') | |
110 | url="https://gitlab.com/${repo}/commit/" | |
111 | ;; | |
e8c564b6 MF |
112 | git://git.sv.gnu.org/*|git://git.savannah.gnu.org/*|https://git.savannah.gnu.org/*) |
113 | repo=$(echo "${remote}" | sed -E -e 's,^(git|https)://git.(sv|savannah).gnu.org/(git/)?,,' -e 's:[.]git$::') | |
114 | url="https://git.savannah.gnu.org/cgit/${repo}.git/commit/?h=" | |
ed2392be | 115 | ;; |
b5612fc0 MF |
116 | git://git.sv.nongnu.org/*|git://git.savannah.nongnu.org/*) |
117 | repo=$(echo "${remote}" | sed -r -e 's,^git://git.(sv|savannah).nongnu.org/,,' -e 's:[.]git$::') | |
e8c564b6 | 118 | url="https://git.savannah.nongnu.org/cgit/${repo}.git/commit/?h=" |
b5612fc0 | 119 | ;; |
97f084d1 MF |
120 | git://git.code.sf.net/p/*|ssh://*@git.code.sf.net/p/*) |
121 | repo=$(echo "${remote}" | sed -r -e 's,(git://|ssh://([^@]*@)?)git.code.sf.net/p/([^/]*)/.*,\3,') | |
122 | url="https://sourceforge.net/p/${repo}/code/ci/" | |
225a775d | 123 | ;; |
50ad3abc MF |
124 | *://sourceware.org/*) |
125 | repo=$(echo "${remote}" | sed -e 's,.*/,,' -e 's,[.]git$,,') | |
126 | url="https://sourceware.org/git/?p=${repo}.git;a=commit;h=" | |
127 | ;; | |
dd6b7ff9 MF |
128 | *://gcc.gnu.org/*) |
129 | repo=$(echo "${remote}" | sed -e 's,.*/,,' -e 's,[.]git$,,') | |
130 | url="https://gcc.gnu.org/git/?p=${repo}.git;a=commit;h=" | |
131 | ;; | |
108c3e81 MF |
132 | rpc://*) |
133 | url="${remote#rpc://}" | |
134 | url="https://${url/\//.googlesource.com/}/+/" | |
135 | ;; | |
50ad3abc MF |
136 | *.googlesource.com/*) |
137 | url="${remote%.git}/+/" | |
138 | ;; | |
a23d5466 MF |
139 | *://git.enlightenment.org/*) |
140 | repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') | |
141 | url="https://git.enlightenment.org/${repo}.git/commit/?id=" | |
142 | ;; | |
afcb1683 MF |
143 | *://git.qemu.org/*) |
144 | repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') | |
b5612fc0 MF |
145 | url="https://git.qemu.org/?p=${repo}.git;a=commit;h=" |
146 | ;; | |
147 | *://git.kernel.org/*) | |
148 | repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') | |
149 | url="https://git.kernel.org/${repo}.git/commit/?id=" | |
afcb1683 | 150 | ;; |
149dcd4d | 151 | *) |
b6a56800 | 152 | echo "Unknown remote: '${remote}'" |
149dcd4d MF |
153 | exit 1 |
154 | ;; | |
155 | esac | |
156 | ||
a8d76436 | 157 | git log -n${num} ${1:-HEAD} | sed "s,^commit ,${url}," |
149dcd4d MF |
158 | } |
159 | ||
160 | svn_url() { | |
161 | if [[ $# -eq 0 ]] ; then | |
162 | svn info | \ | |
163 | awk '{ | |
164 | if ($1 == "URL:") { | |
9430565d | 165 | URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/, "\\1", 1); |
149dcd4d MF |
166 | } else if ($1 == "Revision:") { |
167 | rev = $2 | |
168 | URL = URL "?rev=" (rev + 1) "&view=rev" | |
169 | } | |
170 | } | |
171 | END { print URL }' | |
172 | return 0 | |
173 | fi | |
174 | ||
175 | local f | |
176 | for f in "$@" ; do | |
177 | svn info "${f}" | \ | |
178 | awk '{ | |
179 | if ($1 == "URL:") { | |
180 | sub(/.*svnroot/,"") | |
181 | URL = "http://sources.gentoo.org" $1 "?" | |
182 | } else if ($1 == "Revision:") { | |
183 | rev = $2 | |
184 | URL = URL "r1=" rev "&r2=" (rev + 1) | |
185 | } | |
186 | } | |
187 | END { print URL }' | |
188 | done | |
189 | } | |
190 | ||
191 | usage() { | |
192 | exec cat <<-EOF | |
193 | Usage: $0 [options] [args] | |
194 | ||
195 | Options: | |
a8d76436 MF |
196 | -# Number of commits to show (default: 3) |
197 | -n# Number of commits to show | |
149dcd4d MF |
198 | -c CVS URL |
199 | -g GIT URL (default) | |
200 | -s SVN URL | |
201 | -x Trace the script | |
202 | -h Help | |
203 | EOF | |
204 | } | |
205 | ||
206 | main() { | |
a8d76436 | 207 | local vcs="auto" num="3" args=() |
149dcd4d MF |
208 | while [[ $# -gt 0 ]] ; do |
209 | case $1 in | |
a8d76436 MF |
210 | -n[0-9]*) num="${1:2}";; |
211 | -[0-9]*) num="${1:1}";; | |
149dcd4d MF |
212 | -c) vcs="cvs";; |
213 | -s) vcs="svn";; | |
214 | -g) vcs="git";; | |
215 | -x) set -x;; | |
216 | -h) usage;; | |
217 | --) shift; break;; | |
218 | -*) usage;; | |
a8d76436 | 219 | *) args+=( "$1" );; |
149dcd4d MF |
220 | esac |
221 | shift | |
222 | done | |
a8d76436 | 223 | set -- "${args}" |
149dcd4d | 224 | |
afcb1683 MF |
225 | if [[ ${vcs} == "auto" ]] ; then |
226 | if [[ -d CVS ]] ; then | |
227 | vcs="cvs" | |
228 | elif svn info >&/dev/null ; then | |
229 | vcs="svn" | |
230 | else | |
231 | vcs="git" | |
232 | fi | |
233 | fi | |
234 | ||
149dcd4d MF |
235 | case ${vcs} in |
236 | cvs) cvs_url "$@";; | |
237 | git) git_url "$@";; | |
238 | svn) svn_url "$@";; | |
239 | esac | |
240 | } | |
241 | main "$@" |