]> git.wh0rd.org - home.git/blobdiff - .bin/vcs-url
cros-board: update
[home.git] / .bin / vcs-url
index bab6e78c9ca5ce4b7e48c453806956f67abb70cb..6612a33c34a89cd8bf93319bf51648fbf9ab6d66 100755 (executable)
@@ -64,6 +64,22 @@ 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")
+               else
+                       # Still try harder.
+                       local remotes=$(git config --get-regexp 'remote\..*\.url')
+                       if [[ -n ${remotes} ]]; then
+                               remote=$(echo "${remotes}" | awk '{print $2; exit}')
+                       fi
+               fi
+       fi
+
        case ${remote} in
        *://uclibc.org/*|*://git.uclibc.org/*|\
        *://busybox.net/*|*://git.busybox.net/*|\
@@ -88,18 +104,35 @@ git_url() {
                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://git.sv.gnu.org/*)
-               repo=$(echo "${remote}" | sed -e 's,^git://git.sv.gnu.org/,,' -e 's:[.]git$::')
-               url="http://git.savannah.gnu.org/cgit/${repo}.git/commit/?h="
+       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.code.sf.net/p/*)
-               repo=$(echo "${remote}" | sed -r -e 's,git://git.code.sf.net/p/([^/]*)/.*,\1,')
-               url="http://sourceforge.net/p/${repo}/code/ci/"
+       git://git.sv.gnu.org/*|git://git.savannah.gnu.org/*|https://git.savannah.gnu.org/*)
+               repo=$(echo "${remote}" | sed -E -e 's,^(git|https)://git.(sv|savannah).gnu.org/(git/)?,,' -e 's:[.]git$::')
+               url="https://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="https://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="
                ;;
+       *://gcc.gnu.org/*)
+               repo=$(echo "${remote}" | sed -e 's,.*/,,' -e 's,[.]git$,,')
+               url="https://gcc.gnu.org/git/?p=${repo}.git;a=commit;h="
+               ;;
+       rpc://*)
+               url="${remote#rpc://}"
+               url="https://${url/\//.googlesource.com/}/+/"
+               ;;
        *.googlesource.com/*)
                url="${remote%.git}/+/"
                ;;
@@ -107,13 +140,21 @@ git_url() {
                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}"
+               echo "Unknown remote: '${remote}'"
                exit 1
                ;;
        esac
 
-       git log -n3 ${1:-HEAD} | sed "s,^commit ,${url},"
+       git log -n${num} ${1:-HEAD} | sed "s,^commit ,${url},"
 }
 
 svn_url() {
@@ -121,7 +162,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"
@@ -152,6 +193,8 @@ usage() {
        Usage: $0 [options] [args]
 
        Options:
+         -#       Number of commits to show (default: 3)
+         -n#      Number of commits to show
          -c       CVS URL
          -g       GIT URL (default)
          -s       SVN URL
@@ -161,9 +204,11 @@ usage() {
 }
 
 main() {
-       local vcs="git"
+       local vcs="auto" num="3" args=()
        while [[ $# -gt 0 ]] ; do
                case $1 in
+               -n[0-9]*) num="${1:2}";;
+               -[0-9]*) num="${1:1}";;
                -c) vcs="cvs";;
                -s) vcs="svn";;
                -g) vcs="git";;
@@ -171,10 +216,21 @@ main() {
                -h) usage;;
                --) shift; break;;
                -*) usage;;
-               *)  break;;
+               *)  args+=( "$1" );;
                esac
                shift
        done
+       set -- "${args}"
+
+       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 "$@";;