Re: [PATCH v4 08/10] dir: simplify untracked cache "ident" field
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Dec 30, 2015, 22:01 UTC
- Message-ID
- <CAP8UFD1KcMOQ2M7=OnC3i2OKrzBigDphdOAgwjVWqMSU9VRo7g@mail.gmail.com>
- In-Reply-To
- <xmqqsi2kga1x.fsf@gitster.mtv.corp.google.com>
On Tue, Dec 29, 2015 at 11:32 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 35 quoted lines
> Christian Couder <christian.couder@gmail.com> writes:
>
>> -static int ident_in_untracked(const struct untracked_cache *uc)
>> +static int ident_current_location_in_untracked(const struct untracked_cache *uc)
>> {
>> - const char *end = uc->ident.buf + uc->ident.len;
>> - const char *p = uc->ident.buf;
>> + struct strbuf cur_loc = STRBUF_INIT;
>> + int res = 0;
>>
>> - for (p = uc->ident.buf; p < end; p += strlen(p) + 1)
>> - if (!strcmp(p, get_ident_string()))
>> - return 1;
>> - return 0;
>> + /*
>> + * Previous git versions may have saved many strings in the
>> + * "ident" field, but it is insane to manage many locations,
>> + * so just take care of the first one.
>> + */
>> +
>> + strbuf_addf(&cur_loc, "Location %s, system ", get_git_work_tree());
>> +
>> + if (starts_with(uc->ident.buf, cur_loc.buf))
>> + res = 1;
>> +
>> + strbuf_release(&cur_loc);
>> +
>> + return res;
>> }
>
> The ", system " part looks funny. I think I know what you are
> trying to do, though.
>
> If the path to the working tree has ", system " as a substring,
> I wonder if funny things may happen with this starts_with()?Yeah, I think in the next iteration I will do what Torsten suggests. It looks like the only sane solution, other than just not using the "ident" field anymore and relying only on config variables like the example I give in my reply to Torsten.