commit - 39fdad0d6c82d335602b30cecb217153e19b19f1
commit + 5c65becf8546894b17cc8d0598cabad6443d38bb
blob - cfc405f04ea5a2285a7a8bad605c11356538d9e0
blob + 1dc1640df39ae68a8e393d3333c470b9d706f7c8
--- gotweb/gotweb.c
+++ gotweb/gotweb.c
gw_gen_commit_header(struct gw_trans *gw_trans, char *str1, char *str2)
{
const struct got_error *error = NULL;
- char *ref_str = NULL;
enum kcgi_err kerr = KCGI_OK;
-
- if (strcmp(str2, "") != 0) {
- if (asprintf(&ref_str, "(%s)", str2) == -1) {
- error = got_error_from_errno("asprintf");
- goto done;
- }
- } else {
- ref_str = strdup("");
- if (ref_str == NULL) {
- error = got_error_from_errno("strdup");
- goto done;
- }
- }
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
KATTR_ID, "header_commit_title", KATTR__MAX);
kerr = khtml_puts(gw_trans->gw_html_req, " ");
if (kerr != KCGI_OK)
goto done;
- kerr = khtml_puts(gw_trans->gw_html_req, ref_str);
- if (kerr != KCGI_OK)
- goto done;
+ if (str2 != NULL) {
+ kerr = khtml_puts(gw_trans->gw_html_req, "(");
+ if (kerr != KCGI_OK)
+ goto done;
+ kerr = khtml_puts(gw_trans->gw_html_req, str2);
+ if (kerr != KCGI_OK)
+ goto done;
+ kerr = khtml_puts(gw_trans->gw_html_req, ")");
+ if (kerr != KCGI_OK)
+ goto done;
+ }
kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
done:
if (error == NULL && kerr != KCGI_OK)
KATTR_ID, "header_diff", KATTR__MAX);
if (kerr != KCGI_OK)
goto done;
- kerr = khtml_puts(gw_trans->gw_html_req, str1);
- if (kerr != KCGI_OK)
- goto done;
+ if (str1 != NULL) {
+ kerr = khtml_puts(gw_trans->gw_html_req, str1);
+ if (kerr != KCGI_OK)
+ goto done;
+ }
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BR, KATTR__MAX);
if (kerr != KCGI_OK)
goto done;
if (error)
goto done;
- if (strncmp(header->parent_id, "/dev/null", 9) != 0) {
+ if (header->parent_id != NULL &&
+ strncmp(header->parent_id, "/dev/null", 9) != 0) {
error = got_repo_match_object_id(&id1, &label1,
header->parent_id, GOT_OBJ_TYPE_ANY, 1, header->repo);
if (error)
header->id = NULL;
header->path = NULL;
SIMPLEQ_INIT(&header->refs);
+
+ header->refs_str = NULL;
+ header->commit_id = NULL;
+ header->parent_id = NULL;
+ header->tree_id = NULL;
+ header->commit_msg = NULL;
return header;
}
goto done;
}
- n_header->refs_str = strdup(header->refs_str);
- if (n_header->refs_str == NULL) {
- error = got_error_from_errno("strdup");
- goto done;
+ if (header->refs_str != NULL) {
+ n_header->refs_str = strdup(header->refs_str);
+ if (n_header->refs_str == NULL) {
+ error = got_error_from_errno("strdup");
+ goto done;
+ }
}
n_header->commit_id = strdup(header->commit_id);
if (n_header->commit_id == NULL) {
error = got_error_from_errno("strdup");
goto done;
}
- n_header->parent_id = strdup(header->parent_id);
- if (n_header->parent_id == NULL) {
- error = got_error_from_errno("strdup");
- goto done;
+ if (header->parent_id != NULL) {
+ n_header->parent_id = strdup(header->parent_id);
+ if (n_header->parent_id == NULL) {
+ error = got_error_from_errno("strdup");
+ goto done;
+ }
}
n_header->tree_id = strdup(header->tree_id);
if (n_header->tree_id == NULL) {
}
}
- if (refs_str == NULL) {
- header->refs_str = strdup("");
- if (header->refs_str == NULL) {
- error = got_error_from_errno("strdup");
- return error;
- }
- }
free(refs_str);
error = got_object_id_str(&header->commit_id, header->id);
error = got_error_from_errno("strdup");
return error;
}
- }
- } else {
- header->parent_id = strdup("");
- if (header->parent_id == NULL) {
- error = got_error_from_errno("strdup");
- return error;
}
}
if (nl)
*nl = '\0';
- if (a->gw_trans->repo_folder == NULL) {
- a->gw_trans->repo_folder = strdup("");
- if (a->gw_trans->repo_folder == NULL) {
- err = got_error_from_errno("strdup");
- goto err;
- }
- }
-
kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
"blame_wrapper", KATTR__MAX);
if (kerr != KCGI_OK)
if (asprintf(&href_diff,
"?path=%s&action=diff&commit=%s&file=%s&folder=%s",
a->gw_trans->repo_name, bline->id_str,
- a->gw_trans->repo_file, a->gw_trans->repo_folder) == -1) {
+ a->gw_trans->repo_file, a->gw_trans->repo_folder ?
+ a->gw_trans->repo_folder : "") == -1) {
err = got_error_from_errno("asprintf");
goto err;
}