]>
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 MF |
85 | ;; |
86 | git@github.com/*|\ | |
87 | *://github.com/*) | |
88 | repo=$(echo "${remote}" | sed -e 's,^git@github.com/,,' -e 's,^https://github.com/,,' -e 's:[.]git$::') | |
89 | url="https://github.com/${repo}/commit/" | |
90 | ;; | |
ed2392be MF |
91 | git://git.sv.gnu.org/*) |
92 | repo=$(echo "${remote}" | sed -e 's,^git://git.sv.gnu.org/,,' -e 's:[.]git$::') | |
93 | url="http://git.savannah.gnu.org/cgit/${repo}.git/commit/?h=" | |
94 | ;; | |
225a775d MF |
95 | git://git.code.sf.net/p/*) |
96 | repo=$(echo "${remote}" | sed -r -e 's,git://git.code.sf.net/p/([^/]*)/.*,\1,') | |
97 | url="http://sourceforge.net/p/${repo}/code/ci/" | |
98 | ;; | |
149dcd4d MF |
99 | *) |
100 | echo "Unknown remote: ${remote}" | |
101 | exit 1 | |
102 | ;; | |
103 | esac | |
104 | ||
105 | git log -n3 ${1:-HEAD} | sed "s,^commit ,${url}," | |
106 | } | |
107 | ||
108 | svn_url() { | |
109 | if [[ $# -eq 0 ]] ; then | |
110 | svn info | \ | |
111 | awk '{ | |
112 | if ($1 == "URL:") { | |
113 | URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/,"\\1",""); | |
114 | } else if ($1 == "Revision:") { | |
115 | rev = $2 | |
116 | URL = URL "?rev=" (rev + 1) "&view=rev" | |
117 | } | |
118 | } | |
119 | END { print URL }' | |
120 | return 0 | |
121 | fi | |
122 | ||
123 | local f | |
124 | for f in "$@" ; do | |
125 | svn info "${f}" | \ | |
126 | awk '{ | |
127 | if ($1 == "URL:") { | |
128 | sub(/.*svnroot/,"") | |
129 | URL = "http://sources.gentoo.org" $1 "?" | |
130 | } else if ($1 == "Revision:") { | |
131 | rev = $2 | |
132 | URL = URL "r1=" rev "&r2=" (rev + 1) | |
133 | } | |
134 | } | |
135 | END { print URL }' | |
136 | done | |
137 | } | |
138 | ||
139 | usage() { | |
140 | exec cat <<-EOF | |
141 | Usage: $0 [options] [args] | |
142 | ||
143 | Options: | |
144 | -c CVS URL | |
145 | -g GIT URL (default) | |
146 | -s SVN URL | |
147 | -x Trace the script | |
148 | -h Help | |
149 | EOF | |
150 | } | |
151 | ||
152 | main() { | |
153 | local vcs="git" | |
154 | while [[ $# -gt 0 ]] ; do | |
155 | case $1 in | |
156 | -c) vcs="cvs";; | |
157 | -s) vcs="svn";; | |
158 | -g) vcs="git";; | |
159 | -x) set -x;; | |
160 | -h) usage;; | |
161 | --) shift; break;; | |
162 | -*) usage;; | |
163 | *) break;; | |
164 | esac | |
165 | shift | |
166 | done | |
167 | ||
168 | case ${vcs} in | |
169 | cvs) cvs_url "$@";; | |
170 | git) git_url "$@";; | |
171 | svn) svn_url "$@";; | |
172 | esac | |
173 | } | |
174 | main "$@" |