Re: [PATCHv2 4/4] git submodule: Fix handling of // and /.. in paths for added submodules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Johannes Sixt venit, vidit, dixit 25.02.2009 15:06:
> Michael J Gruber schrieb:
>> @@ -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.

Hmmpf. Is it that new, or gnu specific? I'm always afraid of portability
issues with bash but wasn't aware of sed being an issue as well.

In any case, would 's|\\*|/|g' be better (more portable) then?

>> +
>> +	# 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

Now you got me ;)
It seems I misunderstood the meaning of 'g'. It's really multiple
matches in one step, not recursively matching multiple times.

> (and make this /\.\./ instead of /../).

Oh yes, you're right, my oversight. Thanks!

I guess this is why test writing and coding should not be done by the
same person...

>> +
>>  	# 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.

Yes! I just checked, and git ls-files get's this right, so g-sm-add
should as well.

> 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

Well, how is

echo a/b/c/../../d | sed -e ':start;s|\([^/]*\)/\.\./||g;tstart'
a/d

I meant: how portable is...

Cheers,
Michael
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux