diff mbox series

[10/15,GSOC] cat-file: add has_object_file() check

Message ID 18f38075b3c70748894ad6b2e1158f2b17460845.1625155693.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series cat-file: reuse ref-filter logic | expand

Commit Message

ZheNing Hu July 1, 2021, 4:08 p.m. UTC
From: ZheNing Hu <adlternative@gmail.com>

Use `has_object_file()` in `batch_one_object()` to check
whether the input object exists. This can help us reject
the missing oid when we let `cat-file --batch` use ref-filter
logic later.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Hariom Verma <hariom18599@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
 builtin/cat-file.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Ævar Arnfjörð Bjarmason July 2, 2021, 1:34 p.m. UTC | #1
On Thu, Jul 01 2021, ZheNing Hu via GitGitGadget wrote:

> From: ZheNing Hu <adlternative@gmail.com>
>
> Use `has_object_file()` in `batch_one_object()` to check
> whether the input object exists. This can help us reject
> the missing oid when we let `cat-file --batch` use ref-filter
> logic later.
>
> Mentored-by: Christian Couder <christian.couder@gmail.com>
> Mentored-by: Hariom Verma <hariom18599@gmail.com>
> Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> ---
>  builtin/cat-file.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index 243fe6844bc..59a86412fd0 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -428,6 +428,13 @@ static void batch_one_object(const char *obj_name,
>  		return;
>  	}
>  
> +	if (!has_object_file(&data->oid)) {
> +		printf("%s missing\n",
> +		       obj_name ? obj_name : oid_to_hex(&data->oid));
> +		fflush(stdout);
> +		return;
> +	}
> +
>  	batch_object_write(obj_name, scratch, opt, data);
>  }

In 12/15 the old "missing" is removed, so is this strictly redundant to
what's in batch_object_write() for now, does it change anything?
ZheNing Hu July 3, 2021, 5:50 a.m. UTC | #2
Ævar Arnfjörð Bjarmason <avarab@gmail.com> 于2021年7月2日周五 下午9:34写道:
>
>
> On Thu, Jul 01 2021, ZheNing Hu via GitGitGadget wrote:
>
> > From: ZheNing Hu <adlternative@gmail.com>
> >
> > Use `has_object_file()` in `batch_one_object()` to check
> > whether the input object exists. This can help us reject
> > the missing oid when we let `cat-file --batch` use ref-filter
> > logic later.
> >
> > Mentored-by: Christian Couder <christian.couder@gmail.com>
> > Mentored-by: Hariom Verma <hariom18599@gmail.com>
> > Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> > ---
> >  builtin/cat-file.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> > index 243fe6844bc..59a86412fd0 100644
> > --- a/builtin/cat-file.c
> > +++ b/builtin/cat-file.c
> > @@ -428,6 +428,13 @@ static void batch_one_object(const char *obj_name,
> >               return;
> >       }
> >
> > +     if (!has_object_file(&data->oid)) {
> > +             printf("%s missing\n",
> > +                    obj_name ? obj_name : oid_to_hex(&data->oid));
> > +             fflush(stdout);
> > +             return;
> > +     }
> > +
> >       batch_object_write(obj_name, scratch, opt, data);
> >  }
>
> In 12/15 the old "missing" is removed, so is this strictly redundant to
> what's in batch_object_write() for now, does it change anything?

Both of these commits are used to pass some tests for checking missing objects.

If we don't have this commit, "empty --batch-check notices missing
object" in "t/t1006-cat-file.sh"
will fail;
If we don't have the commit "[GSOC] ref-filter: modify the error
message and value in get_object",
"bogus OFS_DELTA in packfile" in "t/t5313-pack-bounds-checks.sh" will fail.

Thanks.
--
ZheNing Hu
diff mbox series

Patch

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 243fe6844bc..59a86412fd0 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -428,6 +428,13 @@  static void batch_one_object(const char *obj_name,
 		return;
 	}
 
+	if (!has_object_file(&data->oid)) {
+		printf("%s missing\n",
+		       obj_name ? obj_name : oid_to_hex(&data->oid));
+		fflush(stdout);
+		return;
+	}
+
 	batch_object_write(obj_name, scratch, opt, data);
 }