Skip to content

Commit 1d18d75

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent dba093d commit 1d18d75

File tree

8 files changed

+41
-26
lines changed

8 files changed

+41
-26
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
527527
}
528528

529529
finish:
530-
finish_copy_notes_for_rewrite(c, msg);
530+
finish_copy_notes_for_rewrite(the_repository, c, msg);
531531
fclose(fp);
532532
strbuf_release(&sb);
533533
return ret;

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16741674
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
16751675
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
16761676
if (amend && !no_post_rewrite) {
1677-
commit_post_rewrite(current_head, &oid);
1677+
commit_post_rewrite(the_repository, current_head, &oid);
16781678
}
16791679
if (!quiet) {
16801680
unsigned int flags = 0;

builtin/notes.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
330330
}
331331

332332
if (!rewrite_cmd) {
333-
commit_notes(t, msg);
333+
commit_notes(the_repository, t, msg);
334334
free_notes(t);
335335
} else {
336-
finish_copy_notes_for_rewrite(c, msg);
336+
finish_copy_notes_for_rewrite(the_repository, c, msg);
337337
}
338338
strbuf_release(&buf);
339339
return ret;
@@ -469,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)
469469
write_note_data(&d, &new_note);
470470
if (add_note(t, &object, &new_note, combine_notes_overwrite))
471471
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'");
473474
} else {
474475
fprintf(stderr, _("Removing note for object %s\n"),
475476
oid_to_hex(&object));
476477
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'");
478480
}
479481

480482
free_note_data(&d);
@@ -552,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)
552554

553555
if (add_note(t, &object, from_note, combine_notes_overwrite))
554556
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'");
556559
out:
557560
free_notes(t);
558561
return retval;
@@ -636,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
636639
remove_note(t, object.hash);
637640
logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
638641
}
639-
commit_notes(t, logmsg);
642+
commit_notes(the_repository, t, logmsg);
640643

641644
free(logmsg);
642645
free_note_data(&d);
@@ -937,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
937940
strbuf_release(&sb);
938941
}
939942
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'");
941945
free_notes(t);
942946
return retval;
943947
}
@@ -965,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)
965969
prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
966970
(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
967971
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'");
969974
free_notes(t);
970975
return 0;
971976
}

notes-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ int notes_merge(struct notes_merge_options *o,
649649
struct commit_list *parents = NULL;
650650
commit_list_insert(remote, &parents); /* LIFO order */
651651
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,
653653
o->commit_msg.len, result_oid);
654654
}
655655

@@ -724,7 +724,7 @@ int notes_merge_commit(struct notes_merge_options *o,
724724
strbuf_setlen(&path, baselen);
725725
}
726726

727-
create_notes_commit(partial_tree, partial_commit->parents, msg,
727+
create_notes_commit(o->repo, partial_tree, partial_commit->parents, msg,
728728
strlen(msg), result_oid);
729729
unuse_commit_buffer(partial_commit, buffer);
730730
if (o->verbosity >= 4)

notes-utils.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include "notes-utils.h"
66
#include "repository.h"
77

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,
911
const char *msg, size_t msg_len,
1012
struct object_id *result_oid)
1113
{
@@ -20,8 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
2022
/* Deduce parent commit from t->ref */
2123
struct object_id parent_oid;
2224
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);
2526
if (parse_commit(parent))
2627
die("Failed to find/parse commit %s", t->ref);
2728
commit_list_insert(parent, &parents);
@@ -34,7 +35,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
3435
die("Failed to commit notes tree to database");
3536
}
3637

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)
3839
{
3940
struct strbuf buf = STRBUF_INIT;
4041
struct object_id commit_oid;
@@ -50,7 +51,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
5051
strbuf_addstr(&buf, msg);
5152
strbuf_complete_line(&buf);
5253

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);
5455
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
5556
update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
5657
UPDATE_REFS_DIE_ON_ERR);
@@ -171,11 +172,13 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
171172
return ret;
172173
}
173174

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)
175178
{
176179
int i;
177180
for (i = 0; c->trees[i]; i++) {
178-
commit_notes(c->trees[i], msg);
181+
commit_notes(r, c->trees[i], msg);
179182
free_notes(c->trees[i]);
180183
}
181184
free(c->trees);

notes-utils.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
struct commit_list;
77
struct object_id;
8+
struct repository;
89

910
/*
1011
* Create new notes commit from the given notes tree
@@ -17,11 +18,13 @@ struct object_id;
1718
*
1819
* The resulting commit SHA1 is stored in result_sha1.
1920
*/
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,
2124
const char *msg, size_t msg_len,
2225
struct object_id *result_oid);
2326

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);
2528

2629
enum notes_merge_strategy {
2730
NOTES_MERGE_RESOLVE_MANUAL = 0,
@@ -45,6 +48,8 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
4548
struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
4649
int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
4750
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);
4954

5055
#endif

sequencer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,8 @@ static int run_rewrite_hook(const struct object_id *oldoid,
11151115
return finish_command(&proc);
11161116
}
11171117

1118-
void commit_post_rewrite(const struct commit *old_head,
1118+
void commit_post_rewrite(struct repository *r,
1119+
const struct commit *old_head,
11191120
const struct object_id *new_head)
11201121
{
11211122
struct notes_rewrite_cfg *cfg;
@@ -1124,7 +1125,7 @@ void commit_post_rewrite(const struct commit *old_head,
11241125
if (cfg) {
11251126
/* we are amending, so old_head is not NULL */
11261127
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'");
11281129
}
11291130
run_rewrite_hook(&old_head->object.oid, new_head);
11301131
}
@@ -1405,7 +1406,7 @@ static int try_to_commit(struct repository *r,
14051406
}
14061407

14071408
if (flags & AMEND_MSG)
1408-
commit_post_rewrite(current_head, oid);
1409+
commit_post_rewrite(r, current_head, oid);
14091410

14101411
out:
14111412
free_commit_extra_headers(extra);

sequencer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ int update_head_with_reflog(const struct commit *old_head,
124124
const struct object_id *new_head,
125125
const char *action, const struct strbuf *msg,
126126
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,
128129
const struct object_id *new_head);
129130

130131
int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);

0 commit comments

Comments
 (0)