commit - dd669d1824c1e2077bc147b91460ca4209621ced
commit + d2e4f1e938dd709aa0969b8f334c91dd2f1d24ef
blob - cdc23983f6af5f4cf642e738040bcb424ce25a4b
blob + f4b5063722029cc5a154459dd9e915a680617558
--- gotd/libexec/got-notify-email/got-notify-email.c
+++ gotd/libexec/got-notify-email/got-notify-email.c
int with_diff)
{
const struct got_error *err;
- char *line = NULL, *space = NULL;
+ char *line = NULL, *space = NULL, *refname = NULL;
size_t linesize = 0;
ssize_t linelen;
struct got_object_id *id = NULL;
- struct got_reference *ref = NULL;
- const char *refname;
- int have_line = 0;
+ struct got_object_id_queue ids;
+ struct got_object_qid *qid = NULL;
- while ((linelen = getline(&line, &linesize, stdin)) != -1) {
- have_line = 1;
+ STAILQ_INIT(&ids);
+ while ((linelen = getline(&line, &linesize, stdin)) != -1) {
while (linelen > 0 && line[linelen - 1] == '\n') {
line[linelen - 1] = '\0';
linelen--;
*space = '\0';
- refname = space + 1;
- err = got_ref_open(&ref, repo, refname, 0);
- if (err)
+ refname = strdup(space + 1);
+ if (refname == NULL) {
+ err = got_error_from_errno("strdup");
goto done;
+ }
+ if (!got_ref_name_is_valid(refname)) {
+ err = got_error_fmt(GOT_ERR_BAD_REF_NAME, "%s",
+ refname);
+ goto done;
+ }
err = got_object_resolve_id_str(&id, repo, line);
if (err)
goto done;
+ err = got_object_qid_alloc(&qid, id);
+ if (err)
+ goto done;
+
+ qid->data = refname;
+ refname = NULL;
+
+ STAILQ_INSERT_TAIL(&ids, qid, entry);
+
free(id);
id = NULL;
- got_ref_close(ref);
- ref = NULL;
}
- if (!have_line)
+ if (STAILQ_EMPTY(&ids)) {
err = got_error_fmt(GOT_ERR_EOF,
"reading 'commit reference-name' pairs from stdin");
+ goto done;
+ }
+
+ STAILQ_FOREACH(qid, &ids, entry) {
+ char *idstr;
+ got_object_id_str(&idstr, &qid->id);
+ refname = qid->data;
+ printf("%s: commit=%s refname=%s\n", __func__, idstr, refname);
+ }
done:
free(line);
free(id);
- if (ref)
- got_ref_close(ref);
+ free(refname);
+ if (qid)
+ got_object_qid_free(qid);
return err;
}