Re: [PATCHv2 4/4] git submodule: Fix handling of // and /.. in paths for added submodules
- From
Johannes Sixt <j.sixt@viscovery.net>
- Date
- Feb 25, 2009, 14:06 UTC
- Message-ID
- <49A55056.8020504@viscovery.net>
- In-Reply-To
- <1235568392-19705-5-git-send-email-git@drmicha.warpmail.net>
Michael J Gruber schrieb:
Show 6 quoted lines
> @@ -167,6 +167,12 @@ cmd_add() > ;; > esac > > + # simplify multiple / > + path=$(echo "$path" | sed -e 's|/\+|/|g')
I think we have so far avoided \+ in sed expressions for portability reasons.
> + > + # resolve /.. (add trailing / for matching /..$) > + path=$(echo "$path/" | sed -e 's|\([^/]*\)/../||g')
This does not work if there are more than two ../ in a row:
$ echo a/b/c/../../d | sed -e 's|\([^/]*\)/\.\./||g' a/b/../d
(and make this /\.\./ instead of /../).
> + > # strip superfluous ./ from path > path=$(echo "$path" | sed -e 's|^\(\./\)*||' -e's|/\./|/|g')
The latter two transformations should be swapped; otherwise you would transform foo/./../bar into foo/bar.
Perhaps it's now time to write this as:
# normalize path path=$(printf '%s\n' "$path" | sed -e ' # simplify multiple / s|//*|/|g # strip superfluous ./ s|^\(\./\)*|| s|/\./|/|g # resolve /.. s|\([^/]*\)/\.\./||g # strip trailing slashes s|/*$|| ')
But unless you know how to solve the ../../ case with a sed program, I suggest that you keep things simple and take care only of the common cases.
-- Hannes