X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=.bin%2Fvcs-url;h=8b05986768b33db107af0abf1bdf8d106d588e74;hb=a1826e38803eb7a2fca38210dabc2a3051ede96e;hp=0bbbcf50e945323328fc1ae8e6e7d45346b95dd1;hpb=02b192cab6ff11126a487e9751cb569016b05c13;p=home.git diff --git a/.bin/vcs-url b/.bin/vcs-url index 0bbbcf5..8b05986 100755 --- a/.bin/vcs-url +++ b/.bin/vcs-url @@ -50,7 +50,7 @@ _cvs_url() { [[ ${rev2} == "1.1" || ${rev1} == "${rev2}" ]] \ && urirev="?rev=${rev2}" \ || urirev="?r1=${rev1}&r2=${rev2}" - echo "http://sources.gentoo.org/${cvsroot}/${file}${urirev}" + echo "https://sources.gentoo.org/${cvsroot}/${file}${urirev}" } cvs_url() { local f @@ -64,24 +64,76 @@ git_url() { local repo url local remote=$(git config remote.origin.url) + + if [[ -z ${remote} ]] ; then + # Maybe the repo doesn't use "origin". Try harder. + local branch=$(git rev-parse --abbrev-ref HEAD) + remote=$(git config "branch.${branch}.remote") + if [[ -n ${remote} ]] ; then + remote=$(git config "remote.${remote}.url") + fi + fi + case ${remote} in *://uclibc.org/*|*://git.uclibc.org/*|\ *://busybox.net/*|*://git.busybox.net/*|\ *://buildroot.org/*|*://git.buildroot.org/*|\ *://buildroot.net/*|*://git.buildroot.net/*) repo=$(echo "${remote}" | sed -e 's,^[^:]*://[^/]*/,,' -e 's:[.]git$::') - url="https://git.${repo,,}.org/${repo}/commit/?id=" + url="https://git." + case ${repo} in + uclibc) url+="uclibc.org" ;; + buildroot) url+="buildroot.org" ;; + *) url+="busybox.net" ;; + esac + url+="/${repo}/commit/?id=" ;; *://git@git.gentoo.org/*|\ *://anongit.gentoo.org/*) repo=$(echo "${remote}" | sed 's:.*git[.a-z]*.gentoo.org/::') - url="http://gitweb.gentoo.org/${repo}/commit/?id=" + url="https://gitweb.gentoo.org/${repo}/commit/?id=" ;; - git@github.com/*|\ + git@github.com[:/]*|\ *://github.com/*) - repo=$(echo "${remote}" | sed -e 's,^git@github.com/,,' -e 's,^https://github.com/,,' -e 's:[.]git$::') + repo=$(echo "${remote}" | sed -e 's,^git@github.com[:/],,' -e 's,^https://github.com/,,' -e 's,^git://github.com/,,' -e 's:[.]git$::') url="https://github.com/${repo}/commit/" ;; + git@gitlab.com[:/]*|\ + *://gitlab.com/*) + repo=$(echo "${remote}" | sed -e 's,^git@gitlab.com[:/],,' -e 's,^https://gitlab.com/,,' -e 's,^git://gitlab.com/,,' -e 's:[.]git$::') + url="https://gitlab.com/${repo}/commit/" + ;; + git://git.sv.gnu.org/*|git://git.savannah.gnu.org/*) + repo=$(echo "${remote}" | sed -r -e 's,^git://git.(sv|savannah).gnu.org/,,' -e 's:[.]git$::') + url="http://git.savannah.gnu.org/cgit/${repo}.git/commit/?h=" + ;; + git://git.sv.nongnu.org/*|git://git.savannah.nongnu.org/*) + repo=$(echo "${remote}" | sed -r -e 's,^git://git.(sv|savannah).nongnu.org/,,' -e 's:[.]git$::') + url="http://git.savannah.nongnu.org/cgit/${repo}.git/commit/?h=" + ;; + git://git.code.sf.net/p/*|ssh://*@git.code.sf.net/p/*) + repo=$(echo "${remote}" | sed -r -e 's,(git://|ssh://([^@]*@)?)git.code.sf.net/p/([^/]*)/.*,\3,') + url="https://sourceforge.net/p/${repo}/code/ci/" + ;; + *://sourceware.org/*) + repo=$(echo "${remote}" | sed -e 's,.*/,,' -e 's,[.]git$,,') + url="https://sourceware.org/git/?p=${repo}.git;a=commit;h=" + ;; + *.googlesource.com/*) + url="${remote%.git}/+/" + ;; + *://git.enlightenment.org/*) + repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') + url="https://git.enlightenment.org/${repo}.git/commit/?id=" + ;; + *://git.qemu.org/*) + repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') + url="https://git.qemu.org/?p=${repo}.git;a=commit;h=" + ;; + *://git.kernel.org/*) + repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,') + url="https://git.kernel.org/${repo}.git/commit/?id=" + ;; *) echo "Unknown remote: ${remote}" exit 1 @@ -96,7 +148,7 @@ svn_url() { svn info | \ awk '{ if ($1 == "URL:") { - URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/,"\\1",""); + URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/, "\\1", 1); } else if ($1 == "Revision:") { rev = $2 URL = URL "?rev=" (rev + 1) "&view=rev" @@ -136,7 +188,7 @@ usage() { } main() { - local vcs="git" + local vcs="auto" while [[ $# -gt 0 ]] ; do case $1 in -c) vcs="cvs";; @@ -151,6 +203,16 @@ main() { shift done + if [[ ${vcs} == "auto" ]] ; then + if [[ -d CVS ]] ; then + vcs="cvs" + elif svn info >&/dev/null ; then + vcs="svn" + else + vcs="git" + fi + fi + case ${vcs} in cvs) cvs_url "$@";; git) git_url "$@";;