ref: add object check for regular ref
cover ref: add object check for regular ref
Hi All:
When I implement the code for packed ref content checks, I somehow notice that I ignore checks for the object. In the first glance, I think I could make this patch in the first of my packed ref content check series. However, this is not a good idea which may cause the reviewers more overhead.
And this patch aims at checking whether the object exists and whether the type of the object is correct.
Thanks,
Jialuo
shejialuo (1):
ref: add object check for regular ref
refs/files-backend.c | 50 ++++++++++++++++++++++++++++-------- t/t0602-reffiles-fsck.sh | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 10 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/1 ref: add object check for regular ref
Although we use "parse_loose_ref_content" to check whether the object id is correct, we never parse it into the "struct object" structure thus we ignore checking whether there is a real object existing in the repo and whether the object type is correct.
Use "parse_object" to parse the oid for the regular ref content. If the object does not exist, report the error to the user by reusing the fsck message "BAD_REF_CONTENT".
Then, we need to check the type of the object. Unlike "git-fsck(1)" which only report "not a commit" error when the ref is a branch. We will check whether tags point to either annotated tag object or commit object. For other refs, we check that they could only point to commit object.
Last, update the test to exercise the code.
--- refs/files-backend.c | 50 ++++++++++++++++++++++++++++-------- t/t0602-reffiles-fsck.sh | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 10 deletions(-)
refs/files-backend.c +40 -10
@@ -21,6 +21,7 @@#include "../lockfile.h" #include "../object.h" #include "../object-file.h" +#include "../packfile.h" #include "../path.h" #include "../dir.h" #include "../chdir-notify.h"
@@ -3703,18 +3704,47 @@ static int files_fsck_refs_content(struct ref_store *ref_store, }if (!(type &REF_ISSYMREF )) { -if (!*trailing) { - ret =fsck_report_ref (o, &report, -FSCK_MSG_REF_MISSING_NEWLINE , -"misses LF at the end" ); - goto cleanup; +struct object *obj =parse_object (the_repository, &oid); + +if (!obj) { +if (!is_promisor_object (the_repository, &oid)) { + ret |=fsck_report_ref (o, &report, +FSCK_MSG_BAD_REF_CONTENT , +"points to non-existing object %s" , +oid_to_hex (&oid)); + } + }else if (obj->type !=OBJ_COMMIT ) { +const char *err_fmt =NULL ; + +/* +* Only tag can point to annotated tag object. All other refs +* should point to commit object. +*/ +if (starts_with (target_name,"refs/tags/" )) { +if (obj->type !=OBJ_TAG ) + err_fmt ="points to neither commit nor tag object %s" ; + }else { + err_fmt ="points to non-commit object %s" ; + } + +if (err_fmt) { + ret |=fsck_report_ref (o, &report, +FSCK_MSG_BAD_REF_CONTENT , + err_fmt,oid_to_hex (&oid)); + } } -if (*trailing !='\n' || *(trailing +1 )) { - ret =fsck_report_ref (o, &report, -FSCK_MSG_TRAILING_REF_CONTENT , -"has trailing garbage: '%s'" , trailing); - goto cleanup; + +if (!*trailing) { + ret |=fsck_report_ref (o, &report, +FSCK_MSG_REF_MISSING_NEWLINE , +"misses LF at the end" ); + }else if (*trailing !='\n' || *(trailing +1 )) { + ret |=fsck_report_ref (o, &report, +FSCK_MSG_TRAILING_REF_CONTENT , +"has trailing garbage: '%s'" , trailing); } + + goto cleanup; }else { ret =files_fsck_symref_target (o, &report, &referent,0 ); goto cleanup;
t/t0602-reffiles-fsck.sh +55 -0
91 lines not on this page · raw message
Signature · 1 line
2.47.1
Quoted 14 lines · shejialuo
Hi All:
When I implement the code for packed ref content checks, I somehow notice that I ignore checks for the object. In the first glance, I think I could make this patch in the first of my packed ref content check series. However, this is not a good idea which may cause the reviewers more overhead.
And this patch aims at checking whether the object exists and whether the type of the object is correct.
Thanks,
Jialuo
Quoted 10 lines
shejialuo (1):
ref: add object check for regular refrefs/files-backend.c | 50 ++++++++++++++++++++++++++++-------- t/t0602-reffiles-fsck.sh | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 10 deletions(-)Signature · 1 line
2.47.1
Forget to tell Junio, this patch is based on the latest master branch. I don't use the "sj/refs-content-check" due to there are some conflicts when using "is_promisor_object" in the latest master branch.
Quoted 14 lines · shejialuo
Hi All:
When I implement the code for packed ref content checks, I somehow notice that I ignore checks for the object. In the first glance, I think I could make this patch in the first of my packed ref content check series. However, this is not a good idea which may cause the reviewers more overhead.
And this patch aims at checking whether the object exists and whether the type of the object is correct.
Thanks,
Jialuo
Quoted 10 lines
shejialuo (1):
ref: add object check for regular refrefs/files-backend.c | 50 ++++++++++++++++++++++++++++-------- t/t0602-reffiles-fsck.sh | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 10 deletions(-)Signature · 1 line
2.47.1
Please ignore this patch, I will send it together within the packed-ref consistency implementation.
Thanks,