Message ID | e6c26d19a3f3b4791c435867550da538cfe6e287.1622379718.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ref-filter: add %(raw) atom | expand |
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: ZheNing Hu <adlternative@gmail.com> > > Only tag and commit will use `grab_sub_body_contents()` > to grab object contents in origin implement. If we want > to make blob, tree can also use `grab_sub_body_contents()` > to get objects' raw data, a blob look like commit or tag > will be wrongly regarded as commit, tag by `find_subpos()`. > > So we must add a test before `find_subpos()` to reject > blob, tree objects. This will help us add %(raw) atom > which can grab raw data of four type objects. > > Helped-by: Junio C Hamano <gitster@pobox.com> > Signed-off-by: ZheNing Hu <adlternative@gmail.com> > --- > ref-filter.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) Thanks. I'll rephrase the log message while queuing, but the change as a separate preliminary step does make sense. ref-filter: add obj-type check in grab contents Only tag and commit objects use `grab_sub_body_contents()` to grab object contents in the current codebase. We want to teach the function to also handle blobs and trees to get their raw data, without parsing a blob (whose contents looks like a commit or a tag) incorrectly as a commit or a tag. Skip the block of code that is specific to handling commits and tags early when the given object is of a wrong type to help later addition to handle other types of objects in this function.
diff --git a/ref-filter.c b/ref-filter.c index 97116e12d7c4..f6a7b5290d54 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1292,7 +1292,8 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size } /* See grab_values */ -static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) +static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf, + struct object *obj) { int i; const char *subpos = NULL, *bodypos = NULL, *sigpos = NULL; @@ -1307,10 +1308,13 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) continue; if (deref) name++; - if (strcmp(name, "body") && - !starts_with(name, "subject") && - !starts_with(name, "trailers") && - !starts_with(name, "contents")) + + if ((obj->type != OBJ_TAG && + obj->type != OBJ_COMMIT) || + (strcmp(name, "body") && + !starts_with(name, "subject") && + !starts_with(name, "trailers") && + !starts_with(name, "contents"))) continue; if (!subpos) find_subpos(buf, @@ -1379,12 +1383,12 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, v switch (obj->type) { case OBJ_TAG: grab_tag_values(val, deref, obj); - grab_sub_body_contents(val, deref, buf); + grab_sub_body_contents(val, deref, buf, obj); grab_person("tagger", val, deref, buf); break; case OBJ_COMMIT: grab_commit_values(val, deref, obj); - grab_sub_body_contents(val, deref, buf); + grab_sub_body_contents(val, deref, buf, obj); grab_person("author", val, deref, buf); grab_person("committer", val, deref, buf); break;