From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17093 invoked by alias); 5 Dec 2009 17:46:13 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27464 Received: (qmail 24798 invoked from network); 5 Dec 2009 17:46:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Received-SPF: none (ns1.primenet.com.au: domain at altlinux.org does not designate permitted sender hosts) Date: Sat, 5 Dec 2009 20:45:51 +0300 From: "Alexey I. Froloff" To: zsh-workers@zsh.org Subject: Re: [PATCH] _git: offer changed files relative to current directory Message-ID: <20091205174551.GF3344@altlinux.org> References: <1259973163-20919-1-git-send-email-raorn@altlinux.org> <20091205120753.GA21684@headley> <20091205124258.GC3344@altlinux.org> <20091205151202.GE3344@altlinux.org> <20091205170053.GB21684@headley> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sClP8c1IaQxyux9v" Content-Disposition: inline In-Reply-To: <20091205170053.GB21684@headley> User-Agent: Mutt/1.5.20 (2009-06-23) --sClP8c1IaQxyux9v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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=3D( ${(s:/:)"${${${${1//\/\///}//\/.\///}%%/.}%%/}"} ) to=3D( ${(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] =3D=3D $to[1] ]= ]; do what[1]=3D() to[1]=3D() done This loop strips common prefix from $what and $to, we wont need it in relative path. while (( $#to > 0 )); do res+=3D.. to[1]=3D() done For each path component left in $to ascend one level up. res=3D( "$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. --=20 Regards, Sir Raorn. --sClP8c1IaQxyux9v Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAksanEoACgkQVqT7+fkT8wrM9ACePnyjdL8Fsh/J9uxzLw5Hd0OO iBAAn1VWafnm1Euh3rlHwioOW4CzH/k7 =5KBQ -----END PGP SIGNATURE----- --sClP8c1IaQxyux9v--