]> git.wh0rd.org - home.git/commitdiff
vcs-url: improve piper support
authorMike Frysinger <vapier@google.com>
Tue, 6 Oct 2026 17:37:41 +0000 (13:37 -0400)
committerMike Frysinger <vapier@google.com>
Tue, 6 Oct 2026 17:37:41 +0000 (13:37 -0400)
.bin/vcs-url

index 6612a33c34a89cd8bf93319bf51648fbf9ab6d66..edff294a56300473dee0c97d27d03613d2a3b98c 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
-err() { echo "error: $*" >&2; exit 1; }
+PROG=${0##*/}
+
+err() { echo "${PROG}: error: $*" >&2; exit 1; }
 
 _cvs_url() {
        [[ $# -gt 1 ]] && err "accepted args: <file>[:rev1[:rev2]]"
@@ -59,6 +61,9 @@ cvs_url() {
        done
 }
 
+git_root() {
+       git rev-parse --show-toplevel 2>/dev/null
+}
 git_url() {
        [[ $# -gt 1 ]] && err "accepted args: <rev>"
 
@@ -129,8 +134,9 @@ git_url() {
                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://}"
+       sso://*|rpc://*)
+               url="${remote#sso://}"
+               url="${url#rpc://}"
                url="https://${url/\//.googlesource.com/}/+/"
                ;;
        *.googlesource.com/*)
@@ -188,9 +194,17 @@ svn_url() {
        done
 }
 
+piper_root() {
+       g4 info 2>/dev/null | sed -n "/^Client root: / { s|^[^:]*:\s*|| ; p }"
+}
+piper_url() {
+       : "${root:=$(piper_root)}"
+       echo "http://depot/${PWD#${root}/}"
+}
+
 usage() {
        exec cat <<-EOF
-       Usage: $0 [options] [args]
+       Usage: ${PROG} [options] [args]
 
        Options:
          -#       Number of commits to show (default: 3)
@@ -222,20 +236,26 @@ main() {
        done
        set -- "${args}"
 
+       local root
        if [[ ${vcs} == "auto" ]] ; then
-               if [[ -d CVS ]] ; then
+               # Order by which VCS actually matter nowadays.
+               if [[ -n ${root:=$(git_root)} ]] ; then
+                       vcs="git"
+               elif [[ -d CVS ]] ; then
                        vcs="cvs"
                elif svn info >&/dev/null ; then
                        vcs="svn"
-               else
-                       vcs="git"
+               elif [[ -n ${root:=$(piper_root)} ]] ; then
+                       vcs="piper"
                fi
        fi
 
        case ${vcs} in
-       cvs) cvs_url "$@";;
        git) git_url "$@";;
+       cvs) cvs_url "$@";;
        svn) svn_url "$@";;
+       piper) piper_url "$@";;
+       *) err "unknown VCS for ${PWD}";;
        esac
 }
 main "$@"