From: "Jörg Sommer" <joerg@alea.gnuu.de>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] _git: offer files relative to current directory
Date: Mon, 14 Dec 2009 13:20:19 +0000 (UTC) [thread overview]
Message-ID: <slrnhicesh.2pm.joerg@alea.gnuu.de> (raw)
In-Reply-To: <20091213213334.28bbeb66@pws-pc>
Hi Peter,
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Sun, 13 Dec 2009 03:08:20 +0300
> "Alexey I. Froloff" <raorn@altlinux.org> wrote:
>> On Mon, Dec 07, 2009 at 12:52:33AM +0300, Alexey I. Froloff wrote:
>> > When offering repository files (cached, deleted, changed, etc), make
>> > sure that paths are relative to current directory, as git expects.
>> So, what about this patch? Will it be accepted or rejected?
>
> Please can someone who uses git decide.
I've did some tests and this functions seems correct. But I would
refuse it for these reasons:
• The function can be written more self‐contained and generic if the
prefix would be passed as argument and not determined internally.
• The intention of the function is the make paths relative to a given
prefix. It should not beautify paths or something. Otherwise name it
__git_files_relative_and_beatify.
• The function should not take and return a nul‐separated string but an
array. The code looks as follows:
call git
call __git_files_relative
split output of git
…
join output
split output of __git_files_relative
Here's my test:
#v+
#!/bin/zsh
emulate -R zsh
_call_program () {
local tmp
if zstyle -s ":completion:${curcontext}:${1}" command tmp
then
if [[ "$tmp" = -* ]]
then
eval "$tmp[2,-1]" "$argv[2,-1]"
else
eval "$tmp"
fi
else
eval "$argv[2,-1]"
fi
}
__git_command_successful() { true; }
__git_files_relative () {
local rawfiles files file f_parts prefix p_parts tmp
prefix=$(_call_program gitprefix git rev-parse --show-prefix 2>/dev/null)
__git_command_successful || return
# Empty prefix, no modifications
if (( $#prefix == 0 )); then
print $1
return
fi
rawfiles=(${(ps:\0:)1})
files=()
# Now we assume that we've given "absolute" paths list with "root"
# being repository top directory. $prefix is also "absolute" path.
for file in $rawfiles; do
# Collapse "/./" and "//", strip "/." and "/" from tail (I know,
# this is a bit paranoid).
f_parts=(${(s:/:)"${${${${file//\/\///}//\/.\///}%%/.}%%/}"})
p_parts=(${(s:/:)"${${${${prefix//\/\///}//\/.\///}%%/.}%%/}"})
tmp=()
# Strip common path prefix.
while (( $#f_parts > 0 )) && (( $#p_parts > 0 )) && [[ $f_parts[1] == $p_parts[1] ]]; do
f_parts[1]=()
p_parts[1]=()
done
# If prefix still not empty, ascend up.
while (( $#p_parts > 0 )); do
tmp+=..
p_parts[1]=()
done
# Add remaining path.
tmp=("$tmp[@]" "$f_parts[@]")
files+=${(j:/:)tmp}
done
print ${(pj:\0:)files}
}
do_test()
{
local no prefix arg expect
no=$1
prefix=$2
arg=${3//$'\n'/$'\0'}
expect=${4//$'\n'/$'\0'}
zstyle ':completion:*:git:gitprefix' command "echo $prefix"
outp=$(curcontext='git-test:git' __git_files_relative $arg)
if [[ $outp != $expect ]]
then
print "test $no failed"
print "output:"
print ${outp//$'\0'/$'\n'}
print "expected:"
print ${expect//$'\0'/$'\n'}
print '===================='
fi
}
do_test 1 '' "$(print -l 'a/x' 'b')" "$(print -l 'a/x' 'b')"
do_test 2 'a' "$(print -l 'a/x' 'b')" "$(print -l 'x' '../b')"
do_test 3 'b' "$(print -l 'a/x' 'b/y')" "$(print -l '../a/x' 'y')"
do_test 4 'c' "$(print -l a/{1..3} b c/{m/{1..2},n/1,o})" \
"$(print -l ../a/{1..3} ../b {m/{1..2},n/1,o})"
do_test 5 'c/n' "$(print -l a/{1..3} b c/{m/{1..2},n/1,o})" \
"$(print -l ../../a/{1..3} ../../b {../m/{1..2},1,../o})"
do_test 6 'a' "$(print -l a/1 b/t/u/../v)" \
"$(print -l 1 ../b/t/u/../v)"
do_test 7 'a' "$(print -l a/1 b/t/./v)" \
"$(print -l 1 ../b/t/./v)"
do_test 8 'a' "$(print -l a/1 b/t/.///)" \
"$(print -l 1 ../b/t/.///)"
#v-
Bye, Jörg.
--
Eine Blume geht über eine Wiese, sieht einen schönen Menschen und reißt
ihm den Kopf ab.
next prev parent reply other threads:[~2009-12-14 13:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-05 0:32 [PATCH] _git: offer changed " Alexey I. Froloff
2009-12-05 12:07 ` Štěpán Němec
2009-12-05 12:42 ` Alexey I. Froloff
2009-12-05 15:12 ` Alexey I. Froloff
2009-12-05 17:00 ` Štěpán Němec
2009-12-05 17:45 ` Alexey I. Froloff
2009-12-06 21:52 ` [PATCH] _git: offer " Alexey I. Froloff
2009-12-07 22:40 ` Alexey I. Froloff
2009-12-08 10:48 ` Štěpán Němec
2009-12-08 10:50 ` Nikolai Weibull
2009-12-08 11:37 ` Štěpán Němec
2009-12-08 11:45 ` Mikael Magnusson
2009-12-08 11:22 ` Alexey I. Froloff
2009-12-08 11:39 ` Štěpán Němec
2009-12-08 12:07 ` Alexey I. Froloff
2009-12-13 0:08 ` Alexey I. Froloff
2009-12-13 21:33 ` Peter Stephenson
2009-12-13 22:16 ` Nikolai Weibull
2009-12-13 22:22 ` Štěpán Němec
2009-12-14 13:20 ` Jörg Sommer [this message]
2009-12-08 12:08 ` [PATCH] _git: offer changed " Alexey I. Froloff
2009-12-08 13:20 ` Štěpán Němec
2009-12-08 13:30 ` Alexey I. Froloff
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=slrnhicesh.2pm.joerg@alea.gnuu.de \
--to=joerg@alea.gnuu.de \
--cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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).