mirror of
https://github.com/git/git.git
synced 2026-08-06 08:01:46 +00:00
refspec: stop depending on the_repository
The only remaining user of `the_hash_algo` in "refspec.c" is `refspec_append()`, which needs to know the hash algorithm so that it can parse the appended refspec item. In contrast to the functions adapted in the preceding commit, this function always operates on a `struct refspec`. As that structure is expected to only ever contain refspecs that all use the same hash function it doesn't make sense though to adapt each caller. Instead, adapt the structure itself so that it gets initialized with a hash function and use that hash function to parse new refspec items. Adapt callers accordingly. This removes the final dependency on the global repository variable in "refspec.c", so we can drop `USE_THE_REPOSITORY_VARIABLE`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
bb71c3f19e
commit
01f4b61d03
@@ -51,7 +51,7 @@ static int show_original_ids;
|
||||
static int mark_tags;
|
||||
static struct string_list extra_refs = STRING_LIST_INIT_DUP;
|
||||
static struct string_list tag_refs = STRING_LIST_INIT_DUP;
|
||||
static struct refspec refspecs = REFSPEC_INIT_FETCH;
|
||||
static struct refspec refspecs;
|
||||
static int anonymize;
|
||||
static struct hashmap anonymized_seeds;
|
||||
static struct revision_sources revision_sources;
|
||||
@@ -1372,6 +1372,8 @@ int cmd_fast_export(int argc,
|
||||
/* we handle encodings */
|
||||
repo_config(the_repository, git_default_config, NULL);
|
||||
|
||||
refspec_init_fetch(&refspecs, the_hash_algo);
|
||||
|
||||
repo_init_revisions(the_repository, &revs, prefix);
|
||||
init_revision_sources(&revision_sources);
|
||||
revs.topo_order = 1;
|
||||
|
||||
@@ -96,7 +96,7 @@ static struct string_list deepen_not = STRING_LIST_INIT_NODUP;
|
||||
static struct strbuf default_rla = STRBUF_INIT;
|
||||
static struct transport *gtransport;
|
||||
static struct transport *gsecondary;
|
||||
static struct refspec refmap = REFSPEC_INIT_FETCH;
|
||||
static struct refspec refmap;
|
||||
static struct string_list server_options = STRING_LIST_INIT_DUP;
|
||||
static struct string_list negotiation_restrict = STRING_LIST_INIT_NODUP;
|
||||
static struct string_list negotiation_include = STRING_LIST_INIT_NODUP;
|
||||
@@ -2429,7 +2429,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
|
||||
const struct fetch_config *config,
|
||||
struct list_objects_filter_options *filter_options)
|
||||
{
|
||||
struct refspec rs = REFSPEC_INIT_FETCH;
|
||||
struct refspec rs = REFSPEC_INIT_FETCH(the_hash_algo);
|
||||
int i;
|
||||
int exit_code;
|
||||
int maybe_prune_tags;
|
||||
@@ -2631,6 +2631,8 @@ int cmd_fetch(int argc,
|
||||
|
||||
filter_options.allow_auto_filter = 1;
|
||||
|
||||
refspec_init_fetch(&refmap, the_hash_algo);
|
||||
|
||||
packet_trace_identity("fetch");
|
||||
|
||||
/* Record the command line for the reflog */
|
||||
|
||||
@@ -66,7 +66,7 @@ static enum transport_family family;
|
||||
|
||||
static struct push_cas_option cas;
|
||||
|
||||
static struct refspec rs = REFSPEC_INIT_PUSH;
|
||||
static struct refspec rs;
|
||||
|
||||
static struct string_list push_options_config = STRING_LIST_INIT_DUP;
|
||||
|
||||
@@ -749,6 +749,8 @@ int cmd_push(int argc,
|
||||
: &push_options_config);
|
||||
set_push_cert_flags(&flags, push_cert);
|
||||
|
||||
refspec_init_push(&rs, the_hash_algo);
|
||||
|
||||
die_for_incompatible_opt4(deleterefs, "--delete",
|
||||
tags, "--tags",
|
||||
flags & TRANSPORT_PUSH_ALL, "--all/--branches",
|
||||
@@ -855,7 +857,7 @@ int cmd_push(int argc,
|
||||
}
|
||||
|
||||
refspec_clear(&rs);
|
||||
rs = (struct refspec) REFSPEC_INIT_PUSH;
|
||||
rs = (struct refspec) REFSPEC_INIT_PUSH(the_hash_algo);
|
||||
|
||||
if (tags)
|
||||
refspec_append(&rs, "refs/tags/*");
|
||||
|
||||
@@ -153,7 +153,7 @@ int cmd_send_pack(int argc,
|
||||
const char *prefix,
|
||||
struct repository *repo)
|
||||
{
|
||||
struct refspec rs = REFSPEC_INIT_PUSH;
|
||||
struct refspec rs;
|
||||
const char *remote_name = NULL;
|
||||
struct remote *remote = NULL;
|
||||
const char *dest = NULL;
|
||||
@@ -214,6 +214,9 @@ int cmd_send_pack(int argc,
|
||||
|
||||
repo_config(repo, send_pack_config, NULL);
|
||||
argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
|
||||
|
||||
refspec_init_push(&rs, repo->hash_algo);
|
||||
|
||||
if (argc > 0) {
|
||||
dest = argv[0];
|
||||
refspec_appendn(&rs, argv + 1, argc - 1);
|
||||
|
||||
@@ -3150,7 +3150,7 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED,
|
||||
if (argc > 2) {
|
||||
int i;
|
||||
struct ref *local_refs = get_local_heads();
|
||||
struct refspec refspec = REFSPEC_INIT_PUSH;
|
||||
struct refspec refspec = REFSPEC_INIT_PUSH(the_hash_algo);
|
||||
|
||||
refspec_appendn(&refspec, argv + 2, argc - 2);
|
||||
|
||||
|
||||
@@ -1716,7 +1716,7 @@ int cmd_main(int argc, const char **argv)
|
||||
{
|
||||
struct transfer_request *request;
|
||||
struct transfer_request *next_request;
|
||||
struct refspec rs = REFSPEC_INIT_PUSH;
|
||||
struct refspec rs = REFSPEC_INIT_PUSH(the_hash_algo);
|
||||
struct remote_lock *ref_lock = NULL;
|
||||
struct remote_lock *info_ref_lock = NULL;
|
||||
int delete_branch = 0;
|
||||
|
||||
13
refspec.c
13
refspec.c
@@ -1,4 +1,3 @@
|
||||
#define USE_THE_REPOSITORY_VARIABLE
|
||||
#define DISABLE_SIGN_COMPARE_WARNINGS
|
||||
|
||||
#include "git-compat-util.h"
|
||||
@@ -185,15 +184,15 @@ void refspec_item_clear(struct refspec_item *item)
|
||||
item->exact_sha1 = 0;
|
||||
}
|
||||
|
||||
void refspec_init_fetch(struct refspec *rs)
|
||||
void refspec_init_fetch(struct refspec *rs, const struct git_hash_algo *algo)
|
||||
{
|
||||
struct refspec blank = REFSPEC_INIT_FETCH;
|
||||
struct refspec blank = REFSPEC_INIT_FETCH(algo);
|
||||
memcpy(rs, &blank, sizeof(*rs));
|
||||
}
|
||||
|
||||
void refspec_init_push(struct refspec *rs)
|
||||
void refspec_init_push(struct refspec *rs, const struct git_hash_algo *algo)
|
||||
{
|
||||
struct refspec blank = REFSPEC_INIT_PUSH;
|
||||
struct refspec blank = REFSPEC_INIT_PUSH(algo);
|
||||
memcpy(rs, &blank, sizeof(*rs));
|
||||
}
|
||||
|
||||
@@ -203,9 +202,9 @@ void refspec_append(struct refspec *rs, const char *refspec)
|
||||
int ret;
|
||||
|
||||
if (rs->fetch)
|
||||
ret = refspec_item_init_fetch(&item, refspec, the_hash_algo);
|
||||
ret = refspec_item_init_fetch(&item, refspec, rs->hash_algo);
|
||||
else
|
||||
ret = refspec_item_init_push(&item, refspec, the_hash_algo);
|
||||
ret = refspec_item_init_push(&item, refspec, rs->hash_algo);
|
||||
if (!ret)
|
||||
die(_("invalid refspec '%s'"), refspec);
|
||||
|
||||
|
||||
15
refspec.h
15
refspec.h
@@ -49,14 +49,21 @@ struct refspec {
|
||||
int alloc;
|
||||
int nr;
|
||||
|
||||
const struct git_hash_algo *hash_algo;
|
||||
unsigned fetch : 1;
|
||||
};
|
||||
|
||||
#define REFSPEC_INIT_FETCH { .fetch = 1 }
|
||||
#define REFSPEC_INIT_PUSH { .fetch = 0 }
|
||||
#define REFSPEC_INIT_FETCH(algo) { \
|
||||
.fetch = 1, \
|
||||
.hash_algo = (algo), \
|
||||
}
|
||||
#define REFSPEC_INIT_PUSH(algo) { \
|
||||
.fetch = 0, \
|
||||
.hash_algo = (algo), \
|
||||
}
|
||||
|
||||
void refspec_init_fetch(struct refspec *rs);
|
||||
void refspec_init_push(struct refspec *rs);
|
||||
void refspec_init_fetch(struct refspec *rs, const struct git_hash_algo *hash_algo);
|
||||
void refspec_init_push(struct refspec *rs, const struct git_hash_algo *hash_algo);
|
||||
void refspec_clear(struct refspec *rs);
|
||||
|
||||
void refspec_append(struct refspec *rs, const char *refspec);
|
||||
|
||||
4
remote.c
4
remote.c
@@ -150,8 +150,8 @@ static struct remote *make_remote(struct remote_state *remote_state,
|
||||
ret->prune = -1; /* unspecified */
|
||||
ret->prune_tags = -1; /* unspecified */
|
||||
ret->name = xstrndup(name, len);
|
||||
refspec_init_push(&ret->push);
|
||||
refspec_init_fetch(&ret->fetch);
|
||||
refspec_init_push(&ret->push, the_hash_algo);
|
||||
refspec_init_fetch(&ret->fetch, the_hash_algo);
|
||||
string_list_init_dup(&ret->server_options);
|
||||
string_list_init_dup(&ret->negotiation_restrict);
|
||||
string_list_init_dup(&ret->negotiation_include);
|
||||
|
||||
@@ -162,7 +162,7 @@ static struct child_process *get_helper(struct transport *transport)
|
||||
|
||||
data->helper = helper;
|
||||
data->no_disconnect_req = 0;
|
||||
refspec_init_fetch(&data->rs);
|
||||
refspec_init_fetch(&data->rs, the_hash_algo);
|
||||
|
||||
/*
|
||||
* Open the output as FILE* so strbuf_getline_*() family of
|
||||
|
||||
Reference in New Issue
Block a user