Re: [PATCH v3 24/25] prune: strategies for linked checkouts
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Feb 19, 2014, 22:53 UTC
- Message-ID
- <CAPig+cQFw+8RE_zPntCkqKyYGK0rXVFQ=OxrBS6MeFEpw5-cEA@mail.gmail.com>
- In-Reply-To
- <CAPig+cQgphSBA6iAYqLJ7RnEwSzBA1dApcLWAydZEXarQRcTKQ@mail.gmail.com>
On Wed, Feb 19, 2014 at 5:08 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 20 quoted lines
> On Tue, Feb 18, 2014 at 8:40 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> +static dev_t get_device_or_die(const char *path)
>> +{
>> + struct stat buf;
>> + if (stat(path, &buf))
>> + die_errno("failed to stat '%s'", path);
>> + /* Ah Windows! Make different drives different "partitions" */
>> + if (buf.st_dev == 0 && has_dos_drive_prefix("c:\\"))
>> + buf.st_dev = toupper(real_path(path)[0]);
>
> This invocation of has_dos_drive_prefix() with hardcoded "c:\\" at
> first looks like an error until the reader realizes that it's an
> #ifdef-less check if the platforms is Windows. Would it make more
> sense to encapsulate this anomaly and abstract it away by fixing
> compat/mingw.c:do_lstat() to instead set 'st_dev' automatically like
> you do here? In particular, this line in mingw.c:
>
> buf->st_dev = buf->st_rdev = 0; /* not used by Git */
>
>> + return buf.st_dev;Or, if doing this in do_lstat() is too expensive for normal stat() operations (which is likely), then a simple #ifdef might be easier to read; or abstract it into a get_device() function which Windows/MinGW can override, doing buf.st_dev = toupper(real_path(...)), thus also making the code easier to understand.