Re: [PATCH v1 3/3] convert: ce_compare_data() checks for a sha1 of a path

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

 



On Sun, May 15, 2016 at 2:38 AM,  <tboegi@xxxxxx> wrote:
> To compare a file in working tree with the index, convert_to_git() is used,
> the the result is hashed and the hash value compared with ce->sha1.
>
> Deep down would_convert_crlf_at_commit() is invoked, to check if CRLF
> are converted or not: When a CRLF had been in the index before, CRLF in
> the working tree are not converted.
>
> While in a merge, a file name in the working tree has different blobs
> in the index with different hash values.
> Forwarding ce->sha1 from ce_compare_data() into crlf_to_git() makes sure
> the would_convert_crlf_at_commit() looks at the appropriate blob.
>
> Signed-off-by: Torsten Bögershausen <tboegi@xxxxxx>
> ---
> diff --git a/convert.c b/convert.c
> @@ -217,21 +217,29 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
> -static int has_cr_in_index(const char *path)
> +static int has_cr_in_index(const char *path, const unsigned char *sha1)
>  {
>         unsigned long sz;
>         void *data;
>         int has_cr;
> -
> -       data = read_blob_data_from_cache(path, &sz);
> -       if (!data)
> +       enum object_type type;
> +       if (!sha1)
> +               sha1 = get_sha1_from_cache(path);
> +       if (!sha1)
> +               return 0;
> +       data = read_sha1_file(sha1, &type, &sz);
> +       if (!data || type != OBJ_BLOB) {
> +               free(data);
>                 return 0;
> +       }
> +
>         has_cr = memchr(data, '\r', sz) != NULL;
>         free(data);
>         return has_cr;
>  }

Possible rewrite which would make it harder to forget to free 'data':

    int has_cr = 0;
    ...
    data = read_sha1_file(...);
    if (data && type == OBJ_BLOB)
        has_cr = memchr(...);
    free(data);
    return has_cr;
--
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]