From: "Alexey I. Froloff" <raorn@altlinux.org>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] _git: offer changed files relative to current directory
Date: Sat, 5 Dec 2009 20:45:51 +0300 [thread overview]
Message-ID: <20091205174551.GF3344@altlinux.org> (raw)
In-Reply-To: <20091205170053.GB21684@headley>
[-- Attachment #1: Type: text/plain, Size: 2044 bytes --]
On Sat, Dec 05, 2009 at 06:00:53PM +0100, ??t??p??n N??mec wrote:
> I'm not sure about the exact purpose of this function, but it doesn't
> seem correct to me:
Yes, my code requires some explanations.
$what is the file we got from "git tree-index" or "git ls-files
--full-name -- $(git rev-parse --show-cdup)", we can assume it's
a full path from the root of repository.
$to is the path we got from "git rev-parse --show-prefix".
what=( ${(s:/:)"${${${${1//\/\///}//\/.\///}%%/.}%%/}"} )
to=( ${(s:/:)"${${${${2//\/\///}//\/.\///}%%/.}%%/}"} )
Some paranoid code that strips "/./", converts multiple slashes
to one and strips "/." and "/" from right. Then path is split to
components for easier processing.
BTW, if prefix is empty string, $to will be equal to ( "" ) which
will add unneeded "../" later (my bug).
while (( $#what > 0 )) && (( $#to > 0 )) && [[ $what[1] == $to[1] ]]; do
what[1]=()
to[1]=()
done
This loop strips common prefix from $what and $to, we wont need
it in relative path.
while (( $#to > 0 )); do
res+=..
to[1]=()
done
For each path component left in $to ascend one level up.
res=( "$res[@]" "$what[@]" )
Add path components left in $what.
> It is not unlikely to have more same-named directories in different
> parts of directory tree. IIUC, the code above won't always work
> correctly in such situation (i.e. it will remove the directory from the
> path, wrongly assuming it is the same directory for both paths).
No, first loop will only remove prefix common for both paths.
> I believe the only correct way to solve the path relativization problem
> for arbitrary input is to use the *absolute* paths.
These paths _are_ absolute since it is impossible to ascend
outside of git repository. Hope we can assume so ;-)
> In any case, it would be more useful/comprehensible (to me at least) if
> you included the solution with the former patch to solve the actual
> problem.
A bit later.
--
Regards,
Sir Raorn.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2009-12-05 17:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-05 0:32 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 [this message]
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
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=20091205174551.GF3344@altlinux.org \
--to=raorn@altlinux.org \
--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).