Skip to content

Commit 311d0b8

Browse files
adlternativegitster
authored andcommitted
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. So it's needed to pass a `struct expand_data *data` instread of only `void *buf` to both `grab_sub_body_contents()` and `grab_values()` to be able to check the object type. 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. Reviewed-by: Jacob Keller <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Hariom Verma <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: ZheNing Hu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bff9703 commit 311d0b8

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

ref-filter.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,11 +1356,12 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size
13561356
}
13571357

13581358
/* See grab_values */
1359-
static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
1359+
static void grab_sub_body_contents(struct atom_value *val, int deref, struct expand_data *data)
13601360
{
13611361
int i;
13621362
const char *subpos = NULL, *bodypos = NULL, *sigpos = NULL;
13631363
size_t sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0;
1364+
void *buf = data->content;
13641365

13651366
for (i = 0; i < used_atom_cnt; i++) {
13661367
struct used_atom *atom = &used_atom[i];
@@ -1371,10 +1372,13 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
13711372
continue;
13721373
if (deref)
13731374
name++;
1374-
if (strcmp(name, "body") &&
1375-
!starts_with(name, "subject") &&
1376-
!starts_with(name, "trailers") &&
1377-
!starts_with(name, "contents"))
1375+
1376+
if ((data->type != OBJ_TAG &&
1377+
data->type != OBJ_COMMIT) ||
1378+
(strcmp(name, "body") &&
1379+
!starts_with(name, "subject") &&
1380+
!starts_with(name, "trailers") &&
1381+
!starts_with(name, "contents")))
13781382
continue;
13791383
if (!subpos)
13801384
find_subpos(buf,
@@ -1438,17 +1442,19 @@ static void fill_missing_values(struct atom_value *val)
14381442
* pointed at by the ref itself; otherwise it is the object the
14391443
* ref (which is a tag) refers to.
14401444
*/
1441-
static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf)
1445+
static void grab_values(struct atom_value *val, int deref, struct object *obj, struct expand_data *data)
14421446
{
1447+
void *buf = data->content;
1448+
14431449
switch (obj->type) {
14441450
case OBJ_TAG:
14451451
grab_tag_values(val, deref, obj);
1446-
grab_sub_body_contents(val, deref, buf);
1452+
grab_sub_body_contents(val, deref, data);
14471453
grab_person("tagger", val, deref, buf);
14481454
break;
14491455
case OBJ_COMMIT:
14501456
grab_commit_values(val, deref, obj);
1451-
grab_sub_body_contents(val, deref, buf);
1457+
grab_sub_body_contents(val, deref, data);
14521458
grab_person("author", val, deref, buf);
14531459
grab_person("committer", val, deref, buf);
14541460
break;
@@ -1678,7 +1684,7 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
16781684
return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
16791685
oid_to_hex(&oi->oid), ref->refname);
16801686
}
1681-
grab_values(ref->value, deref, *obj, oi->content);
1687+
grab_values(ref->value, deref, *obj, oi);
16821688
}
16831689

16841690
grab_common_values(ref->value, deref, oi);

0 commit comments

Comments
 (0)