diff options
Diffstat (limited to 'builtin/replace.c')
-rw-r--r-- | builtin/replace.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/builtin/replace.c b/builtin/replace.c index da59600ad2..a4eaadff91 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -7,11 +7,10 @@ * and Carlos Rica <jasampler@gmail.com> that was itself based on * git-tag.sh and mktag.c by Linus Torvalds. */ - +#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "config.h" #include "editor.h" -#include "environment.h" #include "gettext.h" #include "hex.h" #include "refs.h" @@ -22,7 +21,6 @@ #include "object-name.h" #include "object-store-ll.h" #include "replace-object.h" -#include "repository.h" #include "tag.h" #include "wildmatch.h" @@ -43,11 +41,13 @@ enum replace_format { }; struct show_data { + struct repository *repo; const char *pattern; enum replace_format format; }; -static int show_reference(struct repository *r, const char *refname, +static int show_reference(const char *refname, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { @@ -62,11 +62,11 @@ static int show_reference(struct repository *r, const char *refname, struct object_id object; enum object_type obj_type, repl_type; - if (repo_get_oid(r, refname, &object)) + if (repo_get_oid(data->repo, refname, &object)) return error(_("failed to resolve '%s' as a valid ref"), refname); - obj_type = oid_object_info(r, &object, NULL); - repl_type = oid_object_info(r, oid, NULL); + obj_type = oid_object_info(data->repo, &object, NULL); + repl_type = oid_object_info(data->repo, oid, NULL); printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type), oid_to_hex(oid), type_name(repl_type)); @@ -80,6 +80,7 @@ static int list_replace_refs(const char *pattern, const char *format) { struct show_data data; + data.repo = the_repository; if (!pattern) pattern = "*"; data.pattern = pattern; @@ -99,7 +100,8 @@ static int list_replace_refs(const char *pattern, const char *format) "valid formats are 'short', 'medium' and 'long'"), format); - for_each_replace_ref(the_repository, show_reference, (void *)&data); + refs_for_each_replace_ref(get_main_ref_store(the_repository), + show_reference, (void *)&data); return 0; } @@ -130,7 +132,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn) strbuf_addstr(&ref, oid_to_hex(&oid)); full_hex = ref.buf + base_len; - if (read_ref(ref.buf, &oid)) { + if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &oid)) { error(_("replace ref '%s' not found"), full_hex); had_error = 1; continue; @@ -145,7 +147,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn) static int delete_replace_ref(const char *name, const char *ref, const struct object_id *oid) { - if (delete_ref(NULL, ref, oid, 0)) + if (refs_delete_ref(get_main_ref_store(the_repository), NULL, ref, oid, 0)) return 1; printf_ln(_("Deleted replace ref '%s'"), name); return 0; @@ -163,8 +165,8 @@ static int check_ref_valid(struct object_id *object, if (check_refname_format(ref->buf, 0)) return error(_("'%s' is not a valid ref name"), ref->buf); - if (read_ref(ref->buf, prev)) - oidclr(prev); + if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev)) + oidclr(prev, the_repository->hash_algo); else if (!force) return error(_("replace ref '%s' already exists"), ref->buf); return 0; @@ -198,10 +200,11 @@ static int replace_object_oid(const char *object_ref, return -1; } - transaction = ref_transaction_begin(&err); + transaction = ref_store_transaction_begin(get_main_ref_store(the_repository), + 0, &err); if (!transaction || ref_transaction_update(transaction, ref.buf, repl, &prev, - 0, NULL, &err) || + NULL, NULL, 0, NULL, &err) || ref_transaction_commit(transaction, &err)) res = error("%s", err.buf); @@ -509,7 +512,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle) static int convert_graft_file(int force) { - const char *graft_file = get_graft_file(the_repository); + const char *graft_file = repo_get_graft_file(the_repository); FILE *fp = fopen_or_warn(graft_file, "r"); struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT; struct strvec args = STRVEC_INIT; @@ -540,7 +543,10 @@ static int convert_graft_file(int force) return -1; } -int cmd_replace(int argc, const char **argv, const char *prefix) +int cmd_replace(int argc, + const char **argv, + const char *prefix, + struct repository *repo UNUSED) { int force = 0; int raw = 0; |