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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2019-01-12 09:13:23 +07:00 committed by Junio C Hamano
parent dba093ddc0
commit 1d18d7581c
8 changed files with 41 additions and 26 deletions

View File

@ -527,7 +527,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
}
finish:
finish_copy_notes_for_rewrite(c, msg);
finish_copy_notes_for_rewrite(the_repository, c, msg);
fclose(fp);
strbuf_release(&sb);
return ret;

View File

@ -1674,7 +1674,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
if (amend && !no_post_rewrite) {
commit_post_rewrite(current_head, &oid);
commit_post_rewrite(the_repository, current_head, &oid);
}
if (!quiet) {
unsigned int flags = 0;

View File

@ -330,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
}
if (!rewrite_cmd) {
commit_notes(t, msg);
commit_notes(the_repository, t, msg);
free_notes(t);
} else {
finish_copy_notes_for_rewrite(c, msg);
finish_copy_notes_for_rewrite(the_repository, c, msg);
}
strbuf_release(&buf);
return ret;
@ -469,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)
write_note_data(&d, &new_note);
if (add_note(t, &object, &new_note, combine_notes_overwrite))
BUG("combine_notes_overwrite failed");
commit_notes(t, "Notes added by 'git notes add'");
commit_notes(the_repository, t,
"Notes added by 'git notes add'");
} else {
fprintf(stderr, _("Removing note for object %s\n"),
oid_to_hex(&object));
remove_note(t, object.hash);
commit_notes(t, "Notes removed by 'git notes add'");
commit_notes(the_repository, t,
"Notes removed by 'git notes add'");
}
free_note_data(&d);
@ -552,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)
if (add_note(t, &object, from_note, combine_notes_overwrite))
BUG("combine_notes_overwrite failed");
commit_notes(t, "Notes added by 'git notes copy'");
commit_notes(the_repository, t,
"Notes added by 'git notes copy'");
out:
free_notes(t);
return retval;
@ -636,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
remove_note(t, object.hash);
logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
}
commit_notes(t, logmsg);
commit_notes(the_repository, t, logmsg);
free(logmsg);
free_note_data(&d);
@ -937,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
strbuf_release(&sb);
}
if (!retval)
commit_notes(t, "Notes removed by 'git notes remove'");
commit_notes(the_repository, t,
"Notes removed by 'git notes remove'");
free_notes(t);
return retval;
}
@ -965,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)
prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
if (!show_only)
commit_notes(t, "Notes removed by 'git notes prune'");
commit_notes(the_repository, t,
"Notes removed by 'git notes prune'");
free_notes(t);
return 0;
}

View File

@ -649,7 +649,7 @@ int notes_merge(struct notes_merge_options *o,
struct commit_list *parents = NULL;
commit_list_insert(remote, &parents); /* LIFO order */
commit_list_insert(local, &parents);
create_notes_commit(local_tree, parents, o->commit_msg.buf,
create_notes_commit(o->repo, local_tree, parents, o->commit_msg.buf,
o->commit_msg.len, result_oid);
}
@ -724,7 +724,7 @@ int notes_merge_commit(struct notes_merge_options *o,
strbuf_setlen(&path, baselen);
}
create_notes_commit(partial_tree, partial_commit->parents, msg,
create_notes_commit(o->repo, partial_tree, partial_commit->parents, msg,
strlen(msg), result_oid);
unuse_commit_buffer(partial_commit, buffer);
if (o->verbosity >= 4)

View File

@ -5,7 +5,9 @@
#include "notes-utils.h"
#include "repository.h"
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
void create_notes_commit(struct repository *r,
struct notes_tree *t,
struct commit_list *parents,
const char *msg, size_t msg_len,
struct object_id *result_oid)
{
@ -20,8 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
/* Deduce parent commit from t->ref */
struct object_id parent_oid;
if (!read_ref(t->ref, &parent_oid)) {
struct commit *parent = lookup_commit(the_repository,
&parent_oid);
struct commit *parent = lookup_commit(r, &parent_oid);
if (parse_commit(parent))
die("Failed to find/parse commit %s", t->ref);
commit_list_insert(parent, &parents);
@ -34,7 +35,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
die("Failed to commit notes tree to database");
}
void commit_notes(struct notes_tree *t, const char *msg)
void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
{
struct strbuf buf = STRBUF_INIT;
struct object_id commit_oid;
@ -50,7 +51,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
strbuf_addstr(&buf, msg);
strbuf_complete_line(&buf);
create_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);
create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
@ -171,11 +172,13 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
return ret;
}
void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg)
void finish_copy_notes_for_rewrite(struct repository *r,
struct notes_rewrite_cfg *c,
const char *msg)
{
int i;
for (i = 0; c->trees[i]; i++) {
commit_notes(c->trees[i], msg);
commit_notes(r, c->trees[i], msg);
free_notes(c->trees[i]);
}
free(c->trees);

View File

@ -5,6 +5,7 @@
struct commit_list;
struct object_id;
struct repository;
/*
* Create new notes commit from the given notes tree
@ -17,11 +18,13 @@ struct object_id;
*
* The resulting commit SHA1 is stored in result_sha1.
*/
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
void create_notes_commit(struct repository *r,
struct notes_tree *t,
struct commit_list *parents,
const char *msg, size_t msg_len,
struct object_id *result_oid);
void commit_notes(struct notes_tree *t, const char *msg);
void commit_notes(struct repository *r, struct notes_tree *t, const char *msg);
enum notes_merge_strategy {
NOTES_MERGE_RESOLVE_MANUAL = 0,
@ -45,6 +48,8 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
const struct object_id *from_obj, const struct object_id *to_obj);
void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg);
void finish_copy_notes_for_rewrite(struct repository *r,
struct notes_rewrite_cfg *c,
const char *msg);
#endif

View File

@ -1115,7 +1115,8 @@ static int run_rewrite_hook(const struct object_id *oldoid,
return finish_command(&proc);
}
void commit_post_rewrite(const struct commit *old_head,
void commit_post_rewrite(struct repository *r,
const struct commit *old_head,
const struct object_id *new_head)
{
struct notes_rewrite_cfg *cfg;
@ -1124,7 +1125,7 @@ void commit_post_rewrite(const struct commit *old_head,
if (cfg) {
/* we are amending, so old_head is not NULL */
copy_note_for_rewrite(cfg, &old_head->object.oid, new_head);
finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
finish_copy_notes_for_rewrite(r, cfg, "Notes added by 'git commit --amend'");
}
run_rewrite_hook(&old_head->object.oid, new_head);
}
@ -1405,7 +1406,7 @@ static int try_to_commit(struct repository *r,
}
if (flags & AMEND_MSG)
commit_post_rewrite(current_head, oid);
commit_post_rewrite(r, current_head, oid);
out:
free_commit_extra_headers(extra);

View File

@ -124,7 +124,8 @@ int update_head_with_reflog(const struct commit *old_head,
const struct object_id *new_head,
const char *action, const struct strbuf *msg,
struct strbuf *err);
void commit_post_rewrite(const struct commit *current_head,
void commit_post_rewrite(struct repository *r,
const struct commit *current_head,
const struct object_id *new_head);
int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);