notes-utils.c: remove the_repository references

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 12, 2019 at 09:13 UTC 1d18d7581cf1ce45314b7ed58e52d5cc73b2e7a7
8 files changed +41 -26
builtin/am.c
+1 -1
@@ -527,7 +527,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
527 }
528
529 finish:
530 - finish_copy_notes_for_rewrite(c, msg);
530 + finish_copy_notes_for_rewrite(the_repository, c, msg);
531 fclose(fp);
532 strbuf_release(&sb);
533 return ret;
builtin/commit.c
+1 -1
@@ -1674,7 +1674,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1674 run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
1675 run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
1676 if (amend && !no_post_rewrite) {
1677 - commit_post_rewrite(current_head, &oid);
1677 + commit_post_rewrite(the_repository, current_head, &oid);
1678 }
1679 if (!quiet) {
1680 unsigned int flags = 0;
builtin/notes.c
+13 -8
@@ -330,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
330 }
331
332 if (!rewrite_cmd) {
333 - commit_notes(t, msg);
333 + commit_notes(the_repository, t, msg);
334 free_notes(t);
335 } else {
336 - finish_copy_notes_for_rewrite(c, msg);
336 + finish_copy_notes_for_rewrite(the_repository, c, msg);
337 }
338 strbuf_release(&buf);
339 return ret;
@@ -469,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)
469 write_note_data(&d, &new_note);
470 if (add_note(t, &object, &new_note, combine_notes_overwrite))
471 BUG("combine_notes_overwrite failed");
472 - commit_notes(t, "Notes added by 'git notes add'");
472 + commit_notes(the_repository, t,
473 + "Notes added by 'git notes add'");
474 } else {
475 fprintf(stderr, _("Removing note for object %s\n"),
476 oid_to_hex(&object));
477 remove_note(t, object.hash);
477 - commit_notes(t, "Notes removed by 'git notes add'");
478 + commit_notes(the_repository, t,
479 + "Notes removed by 'git notes add'");
480 }
481
482 free_note_data(&d);
@@ -552,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)
554
555 if (add_note(t, &object, from_note, combine_notes_overwrite))
556 BUG("combine_notes_overwrite failed");
555 - commit_notes(t, "Notes added by 'git notes copy'");
557 + commit_notes(the_repository, t,
558 + "Notes added by 'git notes copy'");
559 out:
560 free_notes(t);
561 return retval;
@@ -636,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
639 remove_note(t, object.hash);
640 logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
641 }
639 - commit_notes(t, logmsg);
642 + commit_notes(the_repository, t, logmsg);
643
644 free(logmsg);
645 free_note_data(&d);
@@ -937,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
940 strbuf_release(&sb);
941 }
942 if (!retval)
940 - commit_notes(t, "Notes removed by 'git notes remove'");
943 + commit_notes(the_repository, t,
944 + "Notes removed by 'git notes remove'");
945 free_notes(t);
946 return retval;
947 }
@@ -965,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)
969 prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
970 (show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
971 if (!show_only)
968 - commit_notes(t, "Notes removed by 'git notes prune'");
972 + commit_notes(the_repository, t,
973 + "Notes removed by 'git notes prune'");
974 free_notes(t);
975 return 0;
976 }
notes-merge.c
+2 -2
@@ -649,7 +649,7 @@ int notes_merge(struct notes_merge_options *o,
649 struct commit_list *parents = NULL;
650 commit_list_insert(remote, &parents); /* LIFO order */
651 commit_list_insert(local, &parents);
652 - create_notes_commit(local_tree, parents, o->commit_msg.buf,
652 + create_notes_commit(o->repo, local_tree, parents, o->commit_msg.buf,
653 o->commit_msg.len, result_oid);
654 }
655
@@ -724,7 +724,7 @@ int notes_merge_commit(struct notes_merge_options *o,
724 strbuf_setlen(&path, baselen);
725 }
726
727 - create_notes_commit(partial_tree, partial_commit->parents, msg,
727 + create_notes_commit(o->repo, partial_tree, partial_commit->parents, msg,
728 strlen(msg), result_oid);
729 unuse_commit_buffer(partial_commit, buffer);
730 if (o->verbosity >= 4)
notes-utils.c
+10 -7
@@ -5,7 +5,9 @@
5 #include "notes-utils.h"
6 #include "repository.h"
7
8 -void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
8 +void create_notes_commit(struct repository *r,
9 + struct notes_tree *t,
10 + struct commit_list *parents,
11 const char *msg, size_t msg_len,
12 struct object_id *result_oid)
13 {
@@ -20,8 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
22 /* Deduce parent commit from t->ref */
23 struct object_id parent_oid;
24 if (!read_ref(t->ref, &parent_oid)) {
23 - struct commit *parent = lookup_commit(the_repository,
24 - &parent_oid);
25 + struct commit *parent = lookup_commit(r, &parent_oid);
26 if (parse_commit(parent))
27 die("Failed to find/parse commit %s", t->ref);
28 commit_list_insert(parent, &parents);
@@ -34,7 +35,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
35 die("Failed to commit notes tree to database");
36 }
37
37 -void commit_notes(struct notes_tree *t, const char *msg)
38 +void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
39 {
40 struct strbuf buf = STRBUF_INIT;
41 struct object_id commit_oid;
@@ -50,7 +51,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
51 strbuf_addstr(&buf, msg);
52 strbuf_complete_line(&buf);
53
53 - create_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);
54 + create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
55 strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
56 update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
57 UPDATE_REFS_DIE_ON_ERR);
@@ -171,11 +172,13 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
172 return ret;
173 }
174
174 -void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg)
175 +void finish_copy_notes_for_rewrite(struct repository *r,
176 + struct notes_rewrite_cfg *c,
177 + const char *msg)
178 {
179 int i;
180 for (i = 0; c->trees[i]; i++) {
178 - commit_notes(c->trees[i], msg);
181 + commit_notes(r, c->trees[i], msg);
182 free_notes(c->trees[i]);
183 }
184 free(c->trees);
notes-utils.h
+8 -3
@@ -5,6 +5,7 @@
5
6 struct commit_list;
7 struct object_id;
8 +struct repository;
9
10 /*
11 * Create new notes commit from the given notes tree
@@ -17,11 +18,13 @@ struct object_id;
18 *
19 * The resulting commit SHA1 is stored in result_sha1.
20 */
20 -void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
21 +void create_notes_commit(struct repository *r,
22 + struct notes_tree *t,
23 + struct commit_list *parents,
24 const char *msg, size_t msg_len,
25 struct object_id *result_oid);
26
24 -void commit_notes(struct notes_tree *t, const char *msg);
27 +void commit_notes(struct repository *r, struct notes_tree *t, const char *msg);
28
29 enum notes_merge_strategy {
30 NOTES_MERGE_RESOLVE_MANUAL = 0,
@@ -45,6 +48,8 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
48 struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
49 int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
50 const struct object_id *from_obj, const struct object_id *to_obj);
48 -void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg);
51 +void finish_copy_notes_for_rewrite(struct repository *r,
52 + struct notes_rewrite_cfg *c,
53 + const char *msg);
54
55 #endif
sequencer.c
+4 -3
@@ -1115,7 +1115,8 @@ static int run_rewrite_hook(const struct object_id *oldoid,
1115 return finish_command(&proc);
1116 }
1117
1118 -void commit_post_rewrite(const struct commit *old_head,
1118 +void commit_post_rewrite(struct repository *r,
1119 + const struct commit *old_head,
1120 const struct object_id *new_head)
1121 {
1122 struct notes_rewrite_cfg *cfg;
@@ -1124,7 +1125,7 @@ void commit_post_rewrite(const struct commit *old_head,
1125 if (cfg) {
1126 /* we are amending, so old_head is not NULL */
1127 copy_note_for_rewrite(cfg, &old_head->object.oid, new_head);
1127 - finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
1128 + finish_copy_notes_for_rewrite(r, cfg, "Notes added by 'git commit --amend'");
1129 }
1130 run_rewrite_hook(&old_head->object.oid, new_head);
1131 }
@@ -1405,7 +1406,7 @@ static int try_to_commit(struct repository *r,
1406 }
1407
1408 if (flags & AMEND_MSG)
1408 - commit_post_rewrite(current_head, oid);
1409 + commit_post_rewrite(r, current_head, oid);
1410
1411 out:
1412 free_commit_extra_headers(extra);
sequencer.h
+2 -1
@@ -124,7 +124,8 @@ int update_head_with_reflog(const struct commit *old_head,
124 const struct object_id *new_head,
125 const char *action, const struct strbuf *msg,
126 struct strbuf *err);
127 -void commit_post_rewrite(const struct commit *current_head,
127 +void commit_post_rewrite(struct repository *r,
128 + const struct commit *current_head,
129 const struct object_id *new_head);
130
131 int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);