rename commit to commit_id in gw_trans and fix setting gw_trans->commit_id from gw_index leave comment explaining this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 20a9cf0..d2f3218 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -64,7 +64,7 @@ struct gw_trans {
const struct got_error *error;
const char *repo_name;
char *repo_path;
- char *commit;
+ char *commit_id;
const char *repo_file;
char *repo_folder;
const char *headref;
@@ -1440,6 +1440,7 @@ gw_tag(struct gw_trans *gw_trans)
if (error)
goto done;
+ khttp_puts(gw_trans->gw_req, header->commit_id);
error = gw_get_header(gw_trans, header, 1);
if (error)
goto done;
@@ -1668,7 +1669,7 @@ gw_parse_querystring(struct gw_trans *gw_trans)
}
if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID])) {
- if (asprintf(&gw_trans->commit, "%s",
+ if (asprintf(&gw_trans->commit_id, "%s",
p->parsed.s) == -1)
return got_error_from_errno("asprintf");
}
@@ -3138,7 +3139,7 @@ gw_get_header(struct gw_trans *gw_trans, struct gw_header *header, int limit)
if (error)
return error;
- if (gw_trans->commit == NULL) {
+ if (gw_trans->commit_id == NULL) {
struct got_reference *head_ref;
error = got_ref_open(&head_ref, gw_trans->repo,
gw_trans->headref, 0);
@@ -3151,7 +3152,8 @@ gw_get_header(struct gw_trans *gw_trans, struct gw_header *header, int limit)
return error;
} else {
struct got_reference *ref;
- error = got_ref_open(&ref, gw_trans->repo, gw_trans->commit, 0);
+ error = got_ref_open(&ref, gw_trans->repo,
+ gw_trans->commit_id, 0);
if (error == NULL) {
int obj_type;
error = got_ref_resolve(&id, gw_trans->repo, ref);
@@ -3189,7 +3191,7 @@ gw_get_header(struct gw_trans *gw_trans, struct gw_header *header, int limit)
}
}
error = got_repo_match_object_id_prefix(&id,
- gw_trans->commit, GOT_OBJ_TYPE_COMMIT,
+ gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT,
gw_trans->repo);
if (error)
goto done;
@@ -3449,7 +3451,7 @@ gw_output_file_blame(struct gw_trans *gw_trans)
if (error)
goto done;
- error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit,
+ error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
if (error)
goto done;
@@ -3554,7 +3556,7 @@ gw_output_blob_buf(struct gw_trans *gw_trans)
if (error)
goto done;
- error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit,
+ error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
if (error)
goto done;
@@ -3648,7 +3650,7 @@ gw_output_repo_tree(struct gw_trans *gw_trans)
path = in_repo_path;
}
- if (gw_trans->commit == NULL) {
+ if (gw_trans->commit_id == NULL) {
struct got_reference *head_ref;
error = got_ref_open(&head_ref, gw_trans->repo,
gw_trans->headref, 0);
@@ -3658,24 +3660,26 @@ gw_output_repo_tree(struct gw_trans *gw_trans)
if (error)
goto done;
got_ref_close(head_ref);
+ /*
+ * gw_trans->commit_id was not parsed from the querystring
+ * we hit this code path from gw_index, where we don't know the
+ * commit values for the tree link yet, so set
+ * gw_trans->commit_id here to continue further into the tree
+ */
+ error = got_object_id_str(&gw_trans->commit_id, commit_id);
+ if (error)
+ goto done;
} else {
error = got_repo_match_object_id(&commit_id, NULL,
- gw_trans->commit, GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
+ gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT, 1,
+ gw_trans->repo);
if (error)
goto done;
}
- /*
- * XXX gw_trans->commit might have already been allocated in
- * gw_parse_querystring(); could we more cleanly seperate values
- * we received as arguments from values we compute ourselves?
- */
- error = got_object_id_str(&gw_trans->commit, commit_id);
- if (error)
- goto done;
-
- error = got_object_id_by_path(&tree_id, gw_trans->repo, commit_id, path);
+ error = got_object_id_by_path(&tree_id, gw_trans->repo, commit_id,
+ path);
if (error)
goto done;
@@ -3723,7 +3727,7 @@ gw_output_repo_tree(struct gw_trans *gw_trans)
if (asprintf(&href_blob,
"?path=%s&action=%s&commit=%s&folder=%s",
gw_trans->repo_name, gw_get_action_name(gw_trans),
- gw_trans->commit, build_folder) == -1) {
+ gw_trans->commit_id, build_folder) == -1) {
error = got_error_from_errno("asprintf");
goto done;
}
@@ -3767,7 +3771,7 @@ gw_output_repo_tree(struct gw_trans *gw_trans)
} else {
if (asprintf(&href_blob,
"?path=%s&action=%s&commit=%s&file=%s&folder=%s",
- gw_trans->repo_name, "blob", gw_trans->commit,
+ gw_trans->repo_name, "blob", gw_trans->commit_id,
got_tree_entry_get_name(te),
gw_trans->repo_folder ?
gw_trans->repo_folder : "") == -1) {
@@ -3776,7 +3780,7 @@ gw_output_repo_tree(struct gw_trans *gw_trans)
}
if (asprintf(&href_blame,
"?path=%s&action=%s&commit=%s&file=%s&folder=%s",
- gw_trans->repo_name, "blame", gw_trans->commit,
+ gw_trans->repo_name, "blame", gw_trans->commit_id,
got_tree_entry_get_name(te),
gw_trans->repo_folder ?
gw_trans->repo_folder : "") == -1) {
@@ -4184,7 +4188,7 @@ main(int argc, char *argv[])
gw_trans->page = 0;
gw_trans->repos_total = 0;
gw_trans->repo_path = NULL;
- gw_trans->commit = NULL;
+ gw_trans->commit_id = NULL;
gw_trans->headref = GOT_REF_HEAD;
gw_trans->mime = KMIME_TEXT_HTML;
gw_trans->gw_tmpl->key = gw_templs;
@@ -4212,7 +4216,7 @@ done:
free(gw_trans->gw_conf->got_logo);
free(gw_trans->gw_conf->got_logo_url);
free(gw_trans->gw_conf);
- free(gw_trans->commit);
+ free(gw_trans->commit_id);
free(gw_trans->repo_path);
if (gw_trans->repo)
got_repo_close(gw_trans->repo);