]> git.wh0rd.org - home.git/blame - .bin/vcs-url
gentoo-sync: use namespaces
[home.git] / .bin / vcs-url
CommitLineData
149dcd4d
MF
1#!/bin/bash
2
3err() { 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}
55cvs_url() {
56 local f
57 for f in "$@" ; do
58 _cvs_url "${f}"
59 done
60}
61
62git_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/*)
50ad3abc 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 ;;
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 ;;
50ad3abc
MF
99 *://sourceware.org/*)
100 repo=$(echo "${remote}" | sed -e 's,.*/,,' -e 's,[.]git$,,')
101 url="https://sourceware.org/git/?p=${repo}.git;a=commit;h="
102 ;;
103 *.googlesource.com/*)
104 url="${remote%.git}/+/"
105 ;;
149dcd4d
MF
106 *)
107 echo "Unknown remote: ${remote}"
108 exit 1
109 ;;
110 esac
111
112 git log -n3 ${1:-HEAD} | sed "s,^commit ,${url},"
113}
114
115svn_url() {
116 if [[ $# -eq 0 ]] ; then
117 svn info | \
118 awk '{
119 if ($1 == "URL:") {
120 URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/,"\\1","");
121 } else if ($1 == "Revision:") {
122 rev = $2
123 URL = URL "?rev=" (rev + 1) "&view=rev"
124 }
125 }
126 END { print URL }'
127 return 0
128 fi
129
130 local f
131 for f in "$@" ; do
132 svn info "${f}" | \
133 awk '{
134 if ($1 == "URL:") {
135 sub(/.*svnroot/,"")
136 URL = "http://sources.gentoo.org" $1 "?"
137 } else if ($1 == "Revision:") {
138 rev = $2
139 URL = URL "r1=" rev "&r2=" (rev + 1)
140 }
141 }
142 END { print URL }'
143 done
144}
145
146usage() {
147 exec cat <<-EOF
148 Usage: $0 [options] [args]
149
150 Options:
151 -c CVS URL
152 -g GIT URL (default)
153 -s SVN URL
154 -x Trace the script
155 -h Help
156 EOF
157}
158
159main() {
160 local vcs="git"
161 while [[ $# -gt 0 ]] ; do
162 case $1 in
163 -c) vcs="cvs";;
164 -s) vcs="svn";;
165 -g) vcs="git";;
166 -x) set -x;;
167 -h) usage;;
168 --) shift; break;;
169 -*) usage;;
170 *) break;;
171 esac
172 shift
173 done
174
175 case ${vcs} in
176 cvs) cvs_url "$@";;
177 git) git_url "$@";;
178 svn) svn_url "$@";;
179 esac
180}
181main "$@"