commit - 3c245a0e1c3f24a9c01bda35f58df21c807ebe19
commit + deac617cc77c38c186932807abd78a8191e72301
blob - 22886a0440325eeb0e1cd9ee59205415e05f20b6
blob + 9e8a8492e829e72113f7b1de73127250fed0aa48
--- gotweb/gotweb.c
+++ gotweb/gotweb.c
struct gw_trans {
TAILQ_HEAD(headers, gw_header) gw_headers;
TAILQ_HEAD(dirs, gw_dir) gw_dirs;
+ struct got_repository *repo;
struct gw_dir *gw_dir;
struct gotweb_conf *gw_conf;
struct ktemplate *gw_tmpl;
struct gw_header {
TAILQ_ENTRY(gw_header) entry;
- struct got_repository *repo;
struct got_reflist_head refs;
char *path;
if (gw_trans->gw_conf->got_show_repo_age == 0)
return NULL;
- error = got_repo_open(&repo, dir, NULL);
- if (error)
- return error;
+ if (gw_trans->repo)
+ repo = gw_trans->repo;
+ else {
+ error = got_repo_open(&repo, dir, NULL);
+ if (error)
+ return error;
+ }
error = got_ref_list(&refs, repo, "refs/heads",
got_ref_cmp_by_name, NULL);
}
done:
got_ref_list_free(&refs);
- got_repo_close(repo);
+ if (gw_trans->repo == NULL)
+ got_repo_close(repo);
return error;
}
if (f == NULL)
return NULL;
- error = got_repo_open(&header->repo, gw_trans->repo_path, NULL);
- if (error)
- goto done;
-
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);
+ header->parent_id, GOT_OBJ_TYPE_ANY, 1, gw_trans->repo);
if (error)
goto done;
}
error = got_repo_match_object_id(&id2, &label2,
- header->commit_id, GOT_OBJ_TYPE_ANY, 1, header->repo);
+ header->commit_id, GOT_OBJ_TYPE_ANY, 1, gw_trans->repo);
if (error)
goto done;
- error = got_object_get_type(&obj_type, header->repo, id2);
+ error = got_object_get_type(&obj_type, gw_trans->repo, id2);
if (error)
goto done;
switch (obj_type) {
case GOT_OBJ_TYPE_BLOB:
error = got_diff_objects_as_blobs(id1, id2, NULL, NULL, 3, 0,
- header->repo, f);
+ gw_trans->repo, f);
break;
case GOT_OBJ_TYPE_TREE:
error = got_diff_objects_as_trees(id1, id2, "", "", 3, 0,
- header->repo, f);
+ gw_trans->repo, f);
break;
case GOT_OBJ_TYPE_COMMIT:
error = got_diff_objects_as_commits(id1, id2, 3, 0,
- header->repo, f);
+ gw_trans->repo, f);
break;
default:
error = got_error(GOT_ERR_OBJ_TYPE);
int limit, int tag_type)
{
const struct got_error *error = NULL;
- struct got_repository *repo = NULL;
struct got_reflist_head refs;
struct got_reflist_entry *re;
char *age = NULL;
SIMPLEQ_INIT(&refs);
- error = got_repo_open(&repo, gw_trans->repo_path, NULL);
+ error = got_ref_list(&refs, gw_trans->repo, "refs/tags",
+ got_ref_cmp_tags, gw_trans->repo);
if (error)
- return error;
-
- error = got_ref_list(&refs, repo, "refs/tags", got_ref_cmp_tags, repo);
- if (error)
goto done;
SIMPLEQ_FOREACH(re, &refs, entry) {
continue;
refname += 10;
- error = got_ref_resolve(&id, repo, re->ref);
+ error = got_ref_resolve(&id, gw_trans->repo, re->ref);
if (error)
goto done;
- error = got_object_open_as_tag(&tag, repo, id);
+ error = got_object_open_as_tag(&tag, gw_trans->repo, id);
if (error) {
if (error->code != GOT_ERR_OBJ_TYPE) {
free(id);
goto done;
}
/* "lightweight" tag */
- error = got_object_open_as_commit(&commit, repo, id);
+ error = got_object_open_as_commit(&commit,
+ gw_trans->repo, id);
if (error) {
free(id);
goto done;
free(href_briefs);
free(href_commits);
got_ref_list_free(&refs);
- if (repo)
- got_repo_close(repo);
if (error == NULL && kerr != KCGI_OK)
error = gw_kcgi_error(kerr);
return error;
gw_free_header(struct gw_header *header)
{
free(header->path);
- if (header->repo)
- got_repo_close(header->repo);
free(header->author);
free(header->committer);
free(header->refs_str);
if (header == NULL)
return NULL;
- header->repo = NULL;
header->path = NULL;
SIMPLEQ_INIT(&header->refs);
if (error)
return error;
- error = got_commit_graph_iter_start(graph, id, header->repo, NULL,
+ error = got_commit_graph_iter_start(graph, id, gw_trans->repo, NULL,
NULL);
if (error)
goto done;
for (;;) {
- error = got_commit_graph_iter_next(&id, graph, header->repo,
+ error = got_commit_graph_iter_next(&id, graph, gw_trans->repo,
NULL, NULL);
if (error) {
if (error->code == GOT_ERR_ITER_COMPLETED)
if (id == NULL)
goto done;
- error = got_object_open_as_commit(&commit, header->repo, id);
+ error = got_object_open_as_commit(&commit, gw_trans->repo, id);
if (error)
goto done;
if (limit == 1) {
if (strncmp(name, "remotes/", 8) == 0)
name += 8;
if (strncmp(name, "tags/", 5) == 0) {
- error = got_object_open_as_tag(&tag, header->repo,
+ error = got_object_open_as_tag(&tag, gw_trans->repo,
re->id);
if (error) {
if (error->code != GOT_ERR_OBJ_TYPE)
char *in_repo_path = NULL;
struct got_object_id *id = NULL;
- error = got_repo_open(&header->repo, gw_trans->repo_path, NULL);
+ error = got_repo_open(&gw_trans->repo, gw_trans->repo_path, NULL);
if (error)
return error;
if (gw_trans->commit == NULL) {
struct got_reference *head_ref;
- error = got_ref_open(&head_ref, header->repo,
+ error = got_ref_open(&head_ref, gw_trans->repo,
gw_trans->headref, 0);
if (error)
return error;
- error = got_ref_resolve(&id, header->repo, head_ref);
+ error = got_ref_resolve(&id, gw_trans->repo, head_ref);
got_ref_close(head_ref);
if (error)
return error;
} else {
struct got_reference *ref;
- error = got_ref_open(&ref, header->repo, gw_trans->commit, 0);
+ error = got_ref_open(&ref, gw_trans->repo, gw_trans->commit, 0);
if (error == NULL) {
int obj_type;
- error = got_ref_resolve(&id, header->repo, ref);
+ error = got_ref_resolve(&id, gw_trans->repo, ref);
got_ref_close(ref);
if (error)
return error;
- error = got_object_get_type(&obj_type, header->repo,
+ error = got_object_get_type(&obj_type, gw_trans->repo,
id);
if (error)
goto done;
if (obj_type == GOT_OBJ_TYPE_TAG) {
struct got_tag_object *tag;
error = got_object_open_as_tag(&tag,
- header->repo, id);
+ gw_trans->repo, id);
if (error)
goto done;
if (got_object_tag_get_object_type(tag) !=
}
error = got_repo_match_object_id_prefix(&id,
gw_trans->commit, GOT_OBJ_TYPE_COMMIT,
- header->repo);
+ gw_trans->repo);
if (error)
goto done;
}
- error = got_repo_map_path(&in_repo_path, header->repo,
+ error = got_repo_map_path(&in_repo_path, gw_trans->repo,
gw_trans->repo_path, 1);
if (error)
goto done;
}
}
- error = got_ref_list(&header->refs, header->repo, NULL,
+ error = got_ref_list(&header->refs, gw_trans->repo, NULL,
got_ref_cmp_by_name, NULL);
if (error)
goto done;
gw_output_file_blame(struct gw_trans *gw_trans)
{
const struct got_error *error = NULL;
- struct got_repository *repo = NULL;
struct got_object_id *obj_id = NULL;
struct got_object_id *commit_id = NULL;
struct got_blob_object *blob = NULL;
int i, obj_type;
size_t filesize;
- error = got_repo_open(&repo, gw_trans->repo_path, NULL);
- if (error)
- return error;
-
/* XXX repo_file could be NULL if not present in querystring */
if (asprintf(&path, "%s%s%s",
gw_trans->repo_folder ? gw_trans->repo_folder : "",
goto done;
}
- error = got_repo_map_path(&in_repo_path, repo, path, 1);
+ error = got_repo_map_path(&in_repo_path, gw_trans->repo, path, 1);
if (error)
goto done;
error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit,
- GOT_OBJ_TYPE_COMMIT, 1, repo);
+ GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
if (error)
goto done;
- error = got_object_id_by_path(&obj_id, repo, commit_id, in_repo_path);
+ error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
+ in_repo_path);
if (error)
goto done;
goto done;
}
- error = got_object_get_type(&obj_type, repo, obj_id);
+ error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
if (error)
goto done;
goto done;
}
- error = got_object_open_as_blob(&blob, repo, obj_id, 8192);
+ error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192);
if (error)
goto done;
i /= 10;
bca.nlines_prec++;
}
- bca.repo = repo;
+ bca.repo = gw_trans->repo;
bca.gw_trans = gw_trans;
- error = got_blame(in_repo_path, commit_id, repo, gw_blame_cb, &bca,
- NULL, NULL);
+ error = got_blame(in_repo_path, commit_id, gw_trans->repo, gw_blame_cb,
+ &bca, NULL, NULL);
done:
free(bca.line_offsets);
free(in_repo_path);
error = got_error_from_errno("fclose");
if (blob)
got_object_blob_close(blob);
- if (repo)
- got_repo_close(repo);
return error;
}
gw_output_blob_buf(struct gw_trans *gw_trans)
{
const struct got_error *error = NULL;
- struct got_repository *repo = NULL;
struct got_object_id *obj_id = NULL;
struct got_object_id *commit_id = NULL;
struct got_blob_object *blob = NULL;
const uint8_t *buf;
enum kcgi_err kerr = KCGI_OK;
- error = got_repo_open(&repo, gw_trans->repo_path, NULL);
- if (error)
- return error;
-
/* XXX repo_file could be NULL if not present in querystring */
if (asprintf(&path, "%s%s%s",
gw_trans->repo_folder ? gw_trans->repo_folder : "",
goto done;
}
- error = got_repo_map_path(&in_repo_path, repo, path, 1);
+ error = got_repo_map_path(&in_repo_path, gw_trans->repo, path, 1);
if (error)
goto done;
error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit,
- GOT_OBJ_TYPE_COMMIT, 1, repo);
+ GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
if (error)
goto done;
- error = got_object_id_by_path(&obj_id, repo, commit_id, in_repo_path);
+ error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
+ in_repo_path);
if (error)
goto done;
goto done;
}
- error = got_object_get_type(&obj_type, repo, obj_id);
+ error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
if (error)
goto done;
goto done;
}
- error = got_object_open_as_blob(&blob, repo, obj_id, 8192);
+ error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192);
if (error)
goto done;
free(path);
if (blob)
got_object_blob_close(blob);
- if (repo)
- got_repo_close(repo);
if (error == NULL && kerr != KCGI_OK)
error = gw_kcgi_error(kerr);
return error;
gw_output_repo_tree(struct gw_trans *gw_trans)
{
const struct got_error *error = NULL;
- struct got_repository *repo = NULL;
struct got_object_id *tree_id = NULL, *commit_id = NULL;
struct got_tree_object *tree = NULL;
char *path = NULL, *in_repo_path = NULL;
int nentries, i, class_flip = 0;
enum kcgi_err kerr = KCGI_OK;
- error = got_repo_open(&repo, gw_trans->repo_path, NULL);
- if (error)
- return error;
-
if (gw_trans->repo_folder != NULL) {
path = strdup(gw_trans->repo_folder);
if (path == NULL) {
goto done;
}
} else {
- error = got_repo_map_path(&in_repo_path, repo,
+ error = got_repo_map_path(&in_repo_path, gw_trans->repo,
gw_trans->repo_path, 1);
if (error)
goto done;
if (gw_trans->commit == NULL) {
struct got_reference *head_ref;
- error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
+ error = got_ref_open(&head_ref, gw_trans->repo,
+ gw_trans->headref, 0);
if (error)
goto done;
- error = got_ref_resolve(&commit_id, repo, head_ref);
+ error = got_ref_resolve(&commit_id, gw_trans->repo, head_ref);
if (error)
goto done;
got_ref_close(head_ref);
} else {
error = got_repo_match_object_id(&commit_id, NULL,
- gw_trans->commit, GOT_OBJ_TYPE_COMMIT, 1, repo);
+ gw_trans->commit, GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
if (error)
goto done;
}
if (error)
goto done;
- error = got_object_id_by_path(&tree_id, repo, commit_id, path);
+ error = got_object_id_by_path(&tree_id, gw_trans->repo, commit_id, path);
if (error)
goto done;
- error = got_object_open_as_tree(&tree, repo, tree_id);
+ error = got_object_open_as_tree(&tree, gw_trans->repo, tree_id);
if (error)
goto done;
done:
if (tree)
got_object_tree_close(tree);
- if (repo)
- got_repo_close(repo);
free(id_str);
free(href_blob);
free(href_blame);
gw_output_repo_heads(struct gw_trans *gw_trans)
{
const struct got_error *error = NULL;
- struct got_repository *repo = NULL;
struct got_reflist_head refs;
struct got_reflist_entry *re;
char *age = NULL, *href_summary = NULL, *href_briefs = NULL;
SIMPLEQ_INIT(&refs);
- error = got_repo_open(&repo, gw_trans->repo_path, NULL);
- if (error)
- goto done;
-
- error = got_ref_list(&refs, repo, "refs/heads", got_ref_cmp_by_name,
- NULL);
+ error = got_ref_list(&refs, gw_trans->repo, "refs/heads",
+ got_ref_cmp_by_name, NULL);
if (error)
goto done;
free(href_summary);
free(href_briefs);
free(href_commits);
- if (repo)
- got_repo_close(repo);
return error;
}
free(gw_trans->gw_conf);
free(gw_trans->commit);
free(gw_trans->repo_path);
+ if (gw_trans->repo)
+ got_repo_close(gw_trans->repo);
TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
free(dir->name);