Download raw body.
stop using got_repo_map_path() in gotwebd
got_repo_map_path() is supposed to figure out whether an input path
corresponds to an on-disk file in a non-bare git repository, and map
such paths to in-repository paths. In other cases it will just return
the input path as-is.
Since gotwebd only deals with repository-relative input paths in the
first place, it can just use input paths from query strings as-is.
Avoids realpath errors seen in my gotwebd server logs, such as:
gotweb_render_blame: got_output_file_blame: realpath: template/tmpl.c: \
Permission denied
With the blame page showing a header but no file content.
ok?
M gotwebd/got_operations.c | 11+ 44-
1 file changed, 11 insertions(+), 44 deletions(-)
commit - eaef053d0e02ef1c9fc0f3b86e402e87ba085efa
commit + 4dac45af0751f575663d09d961ea68e0026064cd
blob - f60b86ed8bb810bc93dbee821cc7991a64152284
blob + 0910b7745841a7f283764674dfa9ff44f77044a2
--- gotwebd/got_operations.c
+++ gotwebd/got_operations.c
@@ -339,7 +339,7 @@ got_get_repo_commits(struct request *c, size_t limit)
struct got_repository *repo = t->repo;
struct querystring *qs = t->qs;
struct repo_dir *repo_dir = t->repo_dir;
- char *in_repo_path = NULL, *repo_path = NULL, *file_path = NULL;
+ char *repo_path = NULL, *file_path = NULL;
int chk_next = 0;
if (limit == 0)
@@ -382,10 +382,6 @@ got_get_repo_commits(struct request *c, size_t limit)
goto done;
}
- error = got_repo_map_path(&in_repo_path, repo, repo_path);
- if (error)
- goto done;
-
error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
if (error)
goto done;
@@ -395,7 +391,7 @@ got_get_repo_commits(struct request *c, size_t limit)
if (error)
goto done;
} else {
- error = got_commit_graph_open(&graph, in_repo_path, 0);
+ error = got_commit_graph_open(&graph, "/", 0);
if (error)
goto done;
}
@@ -456,7 +452,6 @@ got_get_repo_commits(struct request *c, size_t limit)
if (graph)
got_commit_graph_close(graph);
got_ref_list_free(&refs);
- free(in_repo_path);
free(file_path);
free(repo_path);
free(id);
@@ -478,7 +473,7 @@ got_get_repo_tags(struct request *c, size_t limit)
struct querystring *qs = t->qs;
struct repo_dir *repo_dir = t->repo_dir;
struct got_tag_object *tag = NULL;
- char *in_repo_path = NULL, *repo_path = NULL, *id_str = NULL;
+ char *repo_path = NULL, *id_str = NULL;
char *tag_commit = NULL, *tag_commit0 = NULL;
char *commit_msg = NULL, *commit_msg0 = NULL;
int chk_next = 0, chk_multi = 1, commit_found = 0;
@@ -523,10 +518,6 @@ got_get_repo_tags(struct request *c, size_t limit)
}
}
- error = got_repo_map_path(&in_repo_path, repo, repo_path);
- if (error)
- goto done;
-
error = got_ref_list(&refs, repo, "refs/tags", got_ref_cmp_tags,
repo);
if (error)
@@ -683,7 +674,6 @@ got_get_repo_tags(struct request *c, size_t limit)
got_object_tag_close(tag);
got_ref_list_free(&refs);
free(commit_msg0);
- free(in_repo_path);
free(repo_path);
free(id);
free(id_str);
@@ -704,10 +694,9 @@ got_output_repo_tree(struct request *c, char **readme,
struct got_reflist_head refs;
struct got_tree_object *tree = NULL;
struct got_tree_entry *te;
- struct repo_dir *repo_dir = t->repo_dir;
const char *name;
mode_t mode;
- char *escaped_name = NULL, *path = NULL;
+ char *escaped_name = NULL;
int nentries, i;
TAILQ_INIT(&refs);
@@ -715,18 +704,6 @@ got_output_repo_tree(struct request *c, char **readme,
rc = TAILQ_FIRST(&t->repo_commits);
- if (qs->folder != NULL) {
- path = strdup(qs->folder);
- if (path == NULL) {
- error = got_error_from_errno("strdup");
- goto done;
- }
- } else {
- error = got_repo_map_path(&path, repo, repo_dir->path);
- if (error)
- goto done;
- }
-
error = got_repo_match_object_id(&commit_id, NULL, rc->commit_id,
GOT_OBJ_TYPE_COMMIT, &refs, repo);
if (error)
@@ -736,7 +713,8 @@ got_output_repo_tree(struct request *c, char **readme,
if (error)
goto done;
- error = got_object_id_by_path(&tree_id, repo, commit, path);
+ error = got_object_id_by_path(&tree_id, repo, commit,
+ qs->folder ? qs->folder : "/");
if (error)
goto done;
@@ -765,7 +743,6 @@ got_output_repo_tree(struct request *c, char **readme,
}
done:
free(escaped_name);
- free(path);
got_ref_list_free(&refs);
if (commit)
got_object_commit_close(commit);
@@ -794,7 +771,7 @@ got_open_blob_for_output(struct got_blob_object **blob
struct got_object_id *commit_id = NULL;
struct got_object_id *blob_id = NULL;
struct got_reflist_head refs;
- char *path = NULL, *in_repo_path = NULL;
+ char *path = NULL;
int obj_type;
TAILQ_INIT(&refs);
@@ -814,10 +791,6 @@ got_open_blob_for_output(struct got_blob_object **blob
goto done;
}
- error = got_repo_map_path(&in_repo_path, repo, path);
- if (error)
- goto done;
-
if (commitstr == NULL)
commitstr = GOT_REF_HEAD;
@@ -830,7 +803,7 @@ got_open_blob_for_output(struct got_blob_object **blob
if (error)
goto done;
- error = got_object_id_by_path(&blob_id, repo, commit, in_repo_path);
+ error = got_object_id_by_path(&blob_id, repo, commit, path);
if (error)
goto done;
@@ -874,7 +847,6 @@ got_open_blob_for_output(struct got_blob_object **blob
}
got_ref_list_free(&refs);
- free(in_repo_path);
free(commit_id);
free(blob_id);
free(path);
@@ -1013,7 +985,7 @@ got_output_file_blame(struct request *c, got_render_bl
struct got_commit_object *commit = NULL;
struct got_reflist_head refs;
struct got_blob_object *blob = NULL;
- char *path = NULL, *in_repo_path = NULL;
+ char *path = NULL;
struct blame_cb_args bca;
int i, obj_type, blobfd = -1, fd1 = -1, fd2 = -1;
off_t filesize;
@@ -1029,10 +1001,6 @@ got_output_file_blame(struct request *c, got_render_bl
goto done;
}
- error = got_repo_map_path(&in_repo_path, repo, path);
- if (error)
- goto done;
-
error = got_repo_match_object_id(&commit_id, NULL, qs->commit,
GOT_OBJ_TYPE_COMMIT, &refs, repo);
if (error)
@@ -1042,7 +1010,7 @@ got_output_file_blame(struct request *c, got_render_bl
if (error)
goto done;
- error = got_object_id_by_path(&obj_id, repo, commit, in_repo_path);
+ error = got_object_id_by_path(&obj_id, repo, commit, path);
if (error)
goto done;
@@ -1107,7 +1075,7 @@ got_output_file_blame(struct request *c, got_render_bl
if (error)
goto done;
- error = got_blame(in_repo_path, commit_id, repo,
+ error = got_blame(path, commit_id, repo,
GOT_DIFF_ALGORITHM_PATIENCE, got_gotweb_blame_cb, &bca, NULL, NULL,
fd1, fd2, f1, f2);
@@ -1146,7 +1114,6 @@ got_output_file_blame(struct request *c, got_render_bl
got_object_commit_close(commit);
if (blob)
got_object_blob_close(blob);
- free(in_repo_path);
free(commit_id);
free(obj_id);
free(path);
stop using got_repo_map_path() in gotwebd