From: Yves Blusseau <blusseau@zetam.org>
To: git@vger.kernel.org
Subject: [PATCH] completion: resolve svn remote upstream refs
Date: Fri, 03 Aug 2012 11:54:25 +0200 [thread overview]
Message-ID: <501B9FD1.8090204@zetam.org> (raw)
Updated version of my previous patch
This fix is used to return the svn reference of the remote svn upstream
branch when the git repository is a clone of a svn repository that was
created with the --stdlayout and --prefix options of git svn command.
* completion/git-prompt.sh: add function to resolve svn branches into
git remote refs using paths declared in svn-remote.*.fetch and
svn-remote.*.branches configurations
Signed-off-by: Yves Blusseau <blusseau@zetam.org>
---
contrib/completion/git-prompt.sh | 56
+++++++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-prompt.sh
b/contrib/completion/git-prompt.sh
index 29b1ec9..f9a3421 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -73,17 +73,65 @@ __gitdir ()
fi
}
+# resolve svn refs
+# The function accepts 2 arguments:
+# 1: An array containing the translation ref(s) (ie
branches/*:refs/remotes/svn/*)
+# 2: the ref to be translated (ie. branches/prod)
+# returns the remote refs or original ref if it could not be translated
+__git_resolve_svn_refs ()
+{
+ local idx ref_globs left_part_ref_glob right_part_ref_glob left right
value
+
+ local all_ref_globs=("${!1}")
+ local ref="$2"
+
+ for (( idx=0 ; idx < ${#all_ref_globs[@]}; idx++ ));do
+ ref_globs="${all_ref_globs[$idx]}"
+ # get the left part ref glob (before the :refs/)
+ left_part_ref_glob="${ref_globs%%:refs/*}"
+
+ # If the ref match the left part we can resolve the ref directly
+ if [[ "$ref" == "$left_part_ref_glob" ]];then
+ # resolve the ref into the right part (after the :)
+ ref="${ref_globs/${left_part_ref_glob}:/}"
+ break
+ else
+ case $ref in
+ # check if the ref match the glob
+ $left_part_ref_glob)
+ # extract the value that match the pattern
+ left=${left_part_ref_glob%%\**}
+ right=${left_part_ref_glob##*\*}
+ value=${ref#$left}
+ value=${value%$right}
+ # get the right part ref glob (after the :)
+ right_part_ref_glob="${ref_globs/${left_part_ref_glob}:/}"
+ # replace the pattern with the value found above
+ left=${right_part_ref_glob%%\**}
+ right=${right_part_ref_glob##*\*}
+ ref=${left}${value}${right}
+ break
+ ;;
+ esac
+ fi
+ done
+ # remove leading refs/remotes/
+ ref=${ref/refs\/remotes\//}
+ echo "$ref"
+}
+
# stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM
__git_ps1_show_upstream ()
{
local key value
local svn_remote svn_url_pattern count n
+ local svn_refs_globs=()
local upstream=git legacy="" verbose=""
svn_remote=()
# get some config options from git-config
- local output="$(git config -z --get-regexp
'^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
+ local output="$(git config -z --get-regexp
'^(svn-remote\..*\.(fetch|branches|url)|bash\.showupstream)$'
2>/dev/null | tr '\0\n' '\n ')"
while read -r key value; do
case "$key" in
bash.showupstream)
@@ -93,6 +141,9 @@ __git_ps1_show_upstream ()
return
fi
;;
+ svn-remote.*.fetch|svn-remote.*.branches)
+ svn_refs_globs[${#svn_refs_globs[*]}]="$value"
+ ;;
svn-remote.*.url)
svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
svn_url_pattern+="\\|$value"
@@ -132,6 +183,9 @@ __git_ps1_show_upstream ()
else
upstream=${svn_upstream#/}
fi
+ if [[ ${#svn_refs_globs[@]} -gt 0 ]]; then
+ upstream=$(__git_resolve_svn_refs svn_refs_globs[@] "$upstream")
+ fi
elif [[ "svn+git" = "$upstream" ]]; then
upstream="@{upstream}"
fi
--
1.7.12.rc1.17.g6cf3663
next reply other threads:[~2012-08-03 9:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-03 9:54 Yves Blusseau [this message]
2012-08-03 20:40 ` [PATCH] completion: resolve svn remote upstream refs Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2012-08-02 8:20 Yves Blusseau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=501B9FD1.8090204@zetam.org \
--to=blusseau@zetam.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).