From da06304fc60e1c57cee5dfadeb37b8819fc6ac72 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 6 Oct 2026 13:37:41 -0400 Subject: [PATCH] vcs-url: improve piper support --- .bin/vcs-url | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/.bin/vcs-url b/.bin/vcs-url index 6612a33..edff294 100755 --- a/.bin/vcs-url +++ b/.bin/vcs-url @@ -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: [: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: " @@ -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 "$@" -- 2.47.3