Re: [PATCH v2 4/5] diff.c: initialize hash algo when running in --no-index mode
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Feb 24, 2018, 08:15 UTC
- Message-ID
- <CAPig+cQq32eyArKME4_H0njjn2mbPkNVKo=ULbh-16d55tVYOQ@mail.gmail.com>
- In-Reply-To
- <20180224033429.9656-5-pclouds@gmail.com>
On Fri, Feb 23, 2018 at 10:34 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 12 quoted lines
> Our "git diff" command supports running as a standalone tool. In this > code path, we try to hash the file content but after > 18e2588e11 (sha1_file: switch uses of SHA-1 to the_hash_algo - > 2018-02-01), there is a chance that the_hash_algo (required by > index_path) may still be uninitialized if no repository is found. > > Executing index_path() when the_hash_algo is NULL (or points to unknown > algo) either crashes or dies. Let's make it a bit safer by explicitly > falling back to SHA-1 (so that the diff output remains the same as > before, compared to the alternative that we simply do not hash). > > dòng được
Accidental paste?
Show 7 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> > --- > diff --git a/diff.c b/diff.c > @@ -3995,6 +3995,18 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o) > + /* > + * NEEDSWORK: When running in no-index mode (and no repo is > + * found, thus no hash algo conifugred), fall back to SHA-1
s/conifugred/configured/
Show 11 quoted lines
> + * hashing (which is used by diff_fill_oid_info below) to > + * avoid regression in diff output. > + * > + * In future, perhaps we can allow the user to specify their > + * hash algorithm from command line in this mode. > + */ > + if (o->flags.no_index && !the_hash_algo) > + the_hash_algo = &hash_algos[GIT_HASH_SHA1]; > + > diff_fill_oid_info(one); > diff_fill_oid_info(two);