Re: [RFC 4/6] git-check-attr: Normalize paths

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

 



On 08/02/2011 07:24 PM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@xxxxxxxxxxxx> writes:
> 
>> 1. I'm not sure whether it is correct to fix this problem at the level
>>    of git-check-attr, or whether the fix belongs in the API layer.
>>    What is the convention for API functions?  Do they typically take
>>    path names relative to the CWD or relative to the working tree
>>    root, or ...?
> 
> I think passing down "prefix" (i.e. where your $(cwd) was relative to the
> root level of the working tree) and the user-supplied "pathspec" (which
> typically is relative to that original $(cwd)) is the canonical approach.
> The very original git worked only at the root level of the working tree,
> with paths specified relative to the root level of the tree, so many code
> do:
> 
> 	- find out the root of the working tree;
>         - note where the $(cwd) was in "prefix";
>         - chdir to the root of the working tree;
> 	- prepend the "prefix" to user supplied pathspec;
>         - forget all the complexity and work on the whole tree.
> 
> Then the "prefix" gets stripped away from the beginning of the paths when
> reporting.
> 
> Your patch from a cursory look seems to follow that pattern, which is
> good.

Thanks for the explanation.

Yes, my code follows the pattern, except that in this case it is
unnecessary to chdir to the root of the working tree.

All this chdiring is going to be a nightmare for the libification of
git, since the cwd is a program-wide global variable with implicit
side-effects on almost any code that deals with the filesystem.  It is
obviously not permissible for a library to change directories (not even
temporarily, if the library is intended to be used in a multithreaded
application).  But that is a topic for another day.

Michael

-- 
Michael Haggerty
mhagger@xxxxxxxxxxxx
http://softwareswirl.blogspot.com/
--
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]