Re: [PATCH v4 20/24] introduce GIT_INDEX_VERSION environment variable
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 27, 2013, 22:08 UTC
- Message-ID
- <xmqqk3ftsdk4.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <CAPig+cSHcL62EW5z5n68jQcS4BWW9cZ=GqRwZaoyYM69NE55+w@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 26 quoted lines
> On Wed, Nov 27, 2013 at 7:00 AM, Thomas Gummerer <t.gummerer@gmail.com> wrote:
>> Respect a GIT_INDEX_VERSION environment variable, when a new index is
>> initialized. Setting the environment variable will not cause existing
>> index files to be converted to another format for additional safety.
>>
>> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
>> ---
>> diff --git a/read-cache.c b/read-cache.c
>> index 46551af..04430e5 100644
>> --- a/read-cache.c
>> +++ b/read-cache.c
>> @@ -1233,8 +1233,13 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall
>> void initialize_index(struct index_state *istate, int version)
>> {
>> istate->initialized = 1;
>> - if (!version)
>> - version = INDEX_FORMAT_DEFAULT;
>> + if (!version) {
>> + char *envversion = getenv("GIT_INDEX_VERSION");
>> + if (!envversion)
>> + version = INDEX_FORMAT_DEFAULT;
>> + else
>> + version = atoi(envversion);
>
> Do you want to check that atoi() returned a valid value and emit a
> diagnostic if it did not?Good eyes.
We use strtoul() for this kind of thing instead of atoi() for format checking. The code also needs to make sure that the value obtained thusly are among the versions that are supported.
Thanks.