Re: [PATCH 01/19] dir.c: optionally compute sha-1 of a .gitignore file
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Oct 28, 2014, 00:12 UTC
- Message-ID
- <CACsJy8CgiQhAs2ydKLei9QUZLUXCfCHMCAaZcOdKgMVBGNB=FA@mail.gmail.com>
- In-Reply-To
- <xmqq7fzl5dxw.fsf@gitster.dls.corp.google.com>
On Tue, Oct 28, 2014 at 5:46 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 58 quoted lines
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>
>> This is not used anywhere yet. But the goal is to compare quickly if a
>> .gitignore file has changed when we have the SHA-1 of both old (cached
>> somewhere) and new (from index or a tree) versions.
>>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>> dir.c | 50 +++++++++++++++++++++++++++++++++++++++++++-------
>> dir.h | 5 +++++
>> 2 files changed, 48 insertions(+), 7 deletions(-)
>>
>> diff --git a/dir.c b/dir.c
>> index bd274a7..33a35c1 100644
>> --- a/dir.c
>> +++ b/dir.c
>> @@ -466,7 +466,8 @@ void add_exclude(const char *string, const char *base,
>> x->el = el;
>> }
>>
>> -static void *read_skip_worktree_file_from_index(const char *path, size_t *size)
>> +static void *read_skip_worktree_file_from_index(const char *path, size_t *size,
>> + struct sha1_stat *ss)
>> {
>> int pos, len;
>> unsigned long sz;
>> @@ -485,6 +486,10 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size)
>> return NULL;
>> }
>> *size = xsize_t(sz);
>> + if (ss) {
>> + memset(&ss->stat, 0, sizeof(ss->stat));
>> + hashcpy(ss->sha1, active_cache[pos]->sha1);
>> + }
>> return data;
>> }
>>
>> @@ -529,11 +534,18 @@ static void trim_trailing_spaces(char *buf)
>> *last_space = '\0';
>> }
>>
>> -int add_excludes_from_file_to_list(const char *fname,
>> - const char *base,
>> - int baselen,
>> - struct exclude_list *el,
>> - int check_index)
>> +/*
>> + * Given a file with name "fname", read it (either from disk, or from
>> + * the index if "check_index" is non-zero), parse it and store the
>> + * exclude rules in "el".
>> + *
>> + * If "ss" is not NULL, compute SHA-1 of the exclude file and fill
>> + * stat data from disk (only valid if add_excludes returns zero). If
>> + * ss_valid is non-zero, "ss" must contain good value as input.
>> + */
>
> Hmm, do we want a separate parameter for that? Wouldn't it be
> sufficient and cleaner to pass is_null_sha1(ss->sha1[]),Hm.. no. If both ss->sha1 and ss->stat are valid, then we could try to match stat on disk and reuse ss->sha1, so we can't use a special value of ss->sha1[] to mark the validity.
> or alternatively have an element ss->valid that is initialized to false?
Yeah..
-- Duy