Skip to content

Commit 79cbceb

Browse files
committed
添加 chef_verify_contributor() 以及 重写 chef_set_chef()
1 parent 404807e commit 79cbceb

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/framework/chef.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,33 @@ chef_set_authors (Target_t *target, size_t count, ...)
231231
}
232232

233233

234+
/**
235+
* @brief 验证该 `id` 所指的贡献者确有其人
236+
*/
237+
Contributor_t *
238+
chef_verify_contributor (const char *id)
239+
{
240+
xy_cant_be_null (id);
241+
242+
Contributor_t *c = xy_map_get (ProgStatus.contributors, id);
243+
if (!c)
244+
{
245+
char error[256];
246+
snprintf (error, sizeof (error), "贡献者不存在: %s", id);
247+
chsrc_panic (error);
248+
}
249+
return c;
250+
}
251+
252+
234253
void
235-
chef_set_chef (Target_t *target, char *name, char *email)
254+
chef_set_chef (Target_t *target, const char *id)
236255
{
237-
if (!target || !name || !email)
238-
return;
256+
xy_cant_be_null (target);
257+
258+
Contributor_t *c = chef_verify_contributor (id);
239259

240-
target->chef = xy_malloc0 (sizeof(Contributor_t));
241-
target->chef->name = xy_strdup (name);
242-
target->chef->email = xy_strdup (email);
260+
target->chef = c;
243261
}
244262

245263

0 commit comments

Comments
 (0)