History

Add a wrapper for get_sha1 called cgit_get_sha1

This will later be changed to include namespace resolution, but the call sites are changed now to keep the changes small.

Richard Maw committed 10 years ago

Commit b2ac8911 parent 52a0eca13 files · +29 −22Browse files

Unified · Split

13 files
  1. cgit.c +1 −1
  2. cgit.h +2 −0
  3. shared.c +5 −0
  4. ui-blob.c +3 −3
  5. ui-commit.c +1 −1
  6. ui-diff.c +2 −2
  7. ui-log.c +1 −1
  8. ui-patch.c +2 −2
  9. ui-plain.c +1 −1
  10. ui-shared.c +4 −4
  11. ui-snapshot.c +5 −5
  12. ui-tag.c +1 −1
  13. ui-tree.c +1 −1
cgit.c+1−1
@@ -615,7 +615,7 @@ static int prepare_repo_cmd(void) · 614 unmodified lines
615615 return 1;
616616 }
617617
618− if (get_sha1(ctx.qry.head, sha1)) {
618+ if (cgit_get_sha1(ctx.qry.head, sha1)) {
619619 char *old_head = ctx.qry.head;
620620 ctx.qry.head = xstrdup(ctx.repo->defbranch);
621621 cgit_print_error_page(404, "Not found",
cgit.h+2−0
@@ -391,4 +391,6 @@ extern char *expand_macros(const char *txt); · 390 unmodified lines
391391
392392 extern char *get_mimetype_for_filename(const char *filename);
393393
394+extern int cgit_get_sha1(const char *name, unsigned char *sha1);
395+
394396 #endif /* CGIT_H */
shared.c+5−0
@@ -601,3 +601,8 @@ char *get_mimetype_for_filename(const char *filename) · 600 unmodified lines
601601 fclose(file);
602602 return NULL;
603603 }
604+
605+int cgit_get_sha1(const char *name, unsigned char *sha1)
606+{
607+ return get_sha1(name, sha1);
608+}
ui-blob.c+3−3
@@ -52,7 +52,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) · 51 unmodified lines
5252 .file_only = file_only
5353 };
5454
55− if (get_sha1(ref, sha1))
55+ if (cgit_get_sha1(ref, sha1))
5656 return 0;
5757 if (sha1_object_info(sha1, &size) != OBJ_COMMIT)
5858 return 0;
@@ -82,7 +82,7 @@ int cgit_print_file(char *path, const char *head, int file_only) · 23 unmodified lines
8282 .file_only = file_only
8383 };
8484
85− if (get_sha1(head, sha1))
85+ if (cgit_get_sha1(head, sha1))
8686 return -1;
8787 type = sha1_object_info(sha1, &size);
8888 if (type == OBJ_COMMIT) {
@@ -132,7 +132,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl · 43 unmodified lines
132132 return;
133133 }
134134 } else {
135− if (get_sha1(head, sha1)) {
135+ if (cgit_get_sha1(head, sha1)) {
136136 cgit_print_error_page(404, "Not found",
137137 "Bad ref: %s", head);
138138 return;
ui-commit.c+1−1
@@ -26,7 +26,7 @@ void cgit_print_commit(char *hex, const char *prefix) · 25 unmodified lines
2626 if (!hex)
2727 hex = ctx.qry.head;
2828
29− if (get_sha1(hex, sha1)) {
29+ if (cgit_get_sha1(hex, sha1)) {
3030 cgit_print_error_page(400, "Bad request",
3131 "Bad object id: %s", hex);
3232 return;
ui-diff.c+2−2
@@ -402,7 +402,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, · 401 unmodified lines
402402
403403 if (!new_rev)
404404 new_rev = ctx.qry.head;
405− if (get_sha1(new_rev, new_rev_sha1)) {
405+ if (cgit_get_sha1(new_rev, new_rev_sha1)) {
406406 cgit_print_error_page(404, "Not found",
407407 "Bad object name: %s", new_rev);
408408 return;
@@ -416,7 +416,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, · 7 unmodified lines
416416 new_tree_sha1 = commit->tree->object.oid.hash;
417417
418418 if (old_rev) {
419− if (get_sha1(old_rev, old_rev_sha1)) {
419+ if (cgit_get_sha1(old_rev, old_rev_sha1)) {
420420 cgit_print_error_page(404, "Not found",
421421 "Bad object name: %s", old_rev);
422422 return;
ui-log.c+1−1
@@ -325,7 +325,7 @@ static const char *disambiguate_ref(const char *ref, int *must_free_result) · 324 unmodified lines
325325 struct strbuf longref = STRBUF_INIT;
326326
327327 strbuf_addf(&longref, "refs/heads/%s", ref);
328− if (get_sha1(longref.buf, oid.hash) == 0) {
328+ if (cgit_get_sha1(longref.buf, oid.hash) == 0) {
329329 *must_free_result = 1;
330330 return strbuf_detach(&longref, NULL);
331331 }
ui-patch.c+2−2
@@ -24,7 +24,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, · 23 unmodified lines
2424 if (!new_rev)
2525 new_rev = ctx.qry.head;
2626
27− if (get_sha1(new_rev, new_rev_sha1)) {
27+ if (cgit_get_sha1(new_rev, new_rev_sha1)) {
2828 cgit_print_error_page(404, "Not found",
2929 "Bad object id: %s", new_rev);
3030 return;
@@ -37,7 +37,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, · 6 unmodified lines
3737 }
3838
3939 if (old_rev) {
40− if (get_sha1(old_rev, old_rev_sha1)) {
40+ if (cgit_get_sha1(old_rev, old_rev_sha1)) {
4141 cgit_print_error_page(404, "Not found",
4242 "Bad object id: %s", old_rev);
4343 return;
ui-plain.c+1−1
@@ -181,7 +181,7 @@ void cgit_print_plain(void) · 180 unmodified lines
181181 if (!rev)
182182 rev = ctx.qry.head;
183183
184− if (get_sha1(rev, sha1)) {
184+ if (cgit_get_sha1(rev, sha1)) {
185185 cgit_print_error_page(404, "Not found", "Not found");
186186 return;
187187 }
ui-shared.c+4−4
@@ -1079,11 +1079,11 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, · 1078 unmodified lines
10791079 * name starts with {v,V}[0-9] and the prettify mapping is injective,
10801080 * i.e. each stripped tag can be inverted without ambiguities.
10811081 */
1082− if (get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 &&
1082+ if (cgit_get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 &&
10831083 (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) &&
1084− ((get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) +
1085− (get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) +
1086− (get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1))
1084+ ((cgit_get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) +
1085+ (cgit_get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) +
1086+ (cgit_get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1))
10871087 ref++;
10881088
10891089 strbuf_addf(filename, "%s-%s", base, ref);
ui-snapshot.c+5−5
@@ -111,7 +111,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format, · 110 unmodified lines
111111 {
112112 unsigned char sha1[20];
113113
114− if (get_sha1(hex, sha1)) {
114+ if (cgit_get_sha1(hex, sha1)) {
115115 cgit_print_error_page(404, "Not found",
116116 "Bad object id: %s", hex);
117117 return 1;
@@ -150,7 +150,7 @@ static const char *get_ref_from_filename(const char *url, const char *filename, · 32 unmodified lines
150150 strbuf_addstr(&snapshot, filename);
151151 strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix));
152152
153− if (get_sha1(snapshot.buf, sha1) == 0)
153+ if (cgit_get_sha1(snapshot.buf, sha1) == 0)
154154 goto out;
155155
156156 reponame = cgit_repobasename(url);
@@ -162,15 +162,15 @@ static const char *get_ref_from_filename(const char *url, const char *filename, · 5 unmodified lines
162162 strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
163163 }
164164
165− if (get_sha1(snapshot.buf, sha1) == 0)
165+ if (cgit_get_sha1(snapshot.buf, sha1) == 0)
166166 goto out;
167167
168168 strbuf_insert(&snapshot, 0, "v", 1);
169− if (get_sha1(snapshot.buf, sha1) == 0)
169+ if (cgit_get_sha1(snapshot.buf, sha1) == 0)
170170 goto out;
171171
172172 strbuf_splice(&snapshot, 0, 1, "V", 1);
173− if (get_sha1(snapshot.buf, sha1) == 0)
173+ if (cgit_get_sha1(snapshot.buf, sha1) == 0)
174174 goto out;
175175
176176 result = 0;
ui-tag.c+1−1
@@ -51,7 +51,7 @@ void cgit_print_tag(char *revname) · 50 unmodified lines
5151 revname = ctx.qry.head;
5252
5353 strbuf_addf(&fullref, "refs/tags/%s", revname);
54− if (get_sha1(fullref.buf, sha1)) {
54+ if (cgit_get_sha1(fullref.buf, sha1)) {
5555 cgit_print_error_page(404, "Not found",
5656 "Bad tag reference: %s", revname);
5757 goto cleanup;
ui-tree.c+1−1
@@ -306,7 +306,7 @@ void cgit_print_tree(const char *rev, char *path) · 305 unmodified lines
306306 if (!rev)
307307 rev = ctx.qry.head;
308308
309− if (get_sha1(rev, sha1)) {
309+ if (cgit_get_sha1(rev, sha1)) {
310310 cgit_print_error_page(404, "Not found",
311311 "Invalid revision name: %s", rev);
312312 return;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t