mirror of
https://github.com/git/git.git
synced 2024-05-10 03:46:08 +02:00
revision.h: store hidden refs in a `strvec`
In subsequent commits, it will be convenient to have a 'const char **' of hidden refs (matching `transfer.hiderefs`, `uploadpack.hideRefs`, etc.), instead of a `string_list`. Convert spots throughout the tree that store the list of hidden refs from a `string_list` to a `strvec`. Note that in `parse_hide_refs_config()` there is an ugly const-cast used to avoid an extra copy of each value before trimming any trailing slash characters. This could instead be written as: ref = xstrdup(value); len = strlen(ref); while (len && ref[len - 1] == '/') ref[--len] = '\0'; strvec_push(hide_refs, ref); free(ref); but the double-copy (once when calling `xstrdup()`, and another via `strvec_push()`) is wasteful. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c489f47a64
commit
c45841fff8
|
@ -90,7 +90,7 @@ static struct object_id push_cert_oid;
|
||||||
static struct signature_check sigcheck;
|
static struct signature_check sigcheck;
|
||||||
static const char *push_cert_nonce;
|
static const char *push_cert_nonce;
|
||||||
static const char *cert_nonce_seed;
|
static const char *cert_nonce_seed;
|
||||||
static struct string_list hidden_refs = STRING_LIST_INIT_DUP;
|
static struct strvec hidden_refs = STRVEC_INIT;
|
||||||
|
|
||||||
static const char *NONCE_UNSOLICITED = "UNSOLICITED";
|
static const char *NONCE_UNSOLICITED = "UNSOLICITED";
|
||||||
static const char *NONCE_BAD = "BAD";
|
static const char *NONCE_BAD = "BAD";
|
||||||
|
@ -2619,7 +2619,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
|
||||||
packet_flush(1);
|
packet_flush(1);
|
||||||
oid_array_clear(&shallow);
|
oid_array_clear(&shallow);
|
||||||
oid_array_clear(&ref);
|
oid_array_clear(&ref);
|
||||||
string_list_clear(&hidden_refs, 0);
|
strvec_clear(&hidden_refs);
|
||||||
free((void *)push_cert_nonce);
|
free((void *)push_cert_nonce);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ struct ls_refs_data {
|
||||||
unsigned symrefs;
|
unsigned symrefs;
|
||||||
struct strvec prefixes;
|
struct strvec prefixes;
|
||||||
struct strbuf buf;
|
struct strbuf buf;
|
||||||
struct string_list hidden_refs;
|
struct strvec hidden_refs;
|
||||||
unsigned unborn : 1;
|
unsigned unborn : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ int ls_refs(struct repository *r, struct packet_reader *request)
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
strvec_init(&data.prefixes);
|
strvec_init(&data.prefixes);
|
||||||
strbuf_init(&data.buf, 0);
|
strbuf_init(&data.buf, 0);
|
||||||
string_list_init_dup(&data.hidden_refs);
|
strvec_init(&data.hidden_refs);
|
||||||
|
|
||||||
git_config(ls_refs_config, &data);
|
git_config(ls_refs_config, &data);
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ int ls_refs(struct repository *r, struct packet_reader *request)
|
||||||
packet_fflush(stdout);
|
packet_fflush(stdout);
|
||||||
strvec_clear(&data.prefixes);
|
strvec_clear(&data.prefixes);
|
||||||
strbuf_release(&data.buf);
|
strbuf_release(&data.buf);
|
||||||
string_list_clear(&data.hidden_refs, 0);
|
strvec_clear(&data.hidden_refs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
refs.c
11
refs.c
|
@ -1427,7 +1427,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_hide_refs_config(const char *var, const char *value, const char *section,
|
int parse_hide_refs_config(const char *var, const char *value, const char *section,
|
||||||
struct string_list *hide_refs)
|
struct strvec *hide_refs)
|
||||||
{
|
{
|
||||||
const char *key;
|
const char *key;
|
||||||
if (!strcmp("transfer.hiderefs", var) ||
|
if (!strcmp("transfer.hiderefs", var) ||
|
||||||
|
@ -1438,22 +1438,23 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return config_error_nonbool(var);
|
return config_error_nonbool(var);
|
||||||
ref = xstrdup(value);
|
|
||||||
|
/* drop const to remove trailing '/' characters */
|
||||||
|
ref = (char *)strvec_push(hide_refs, value);
|
||||||
len = strlen(ref);
|
len = strlen(ref);
|
||||||
while (len && ref[len - 1] == '/')
|
while (len && ref[len - 1] == '/')
|
||||||
ref[--len] = '\0';
|
ref[--len] = '\0';
|
||||||
string_list_append_nodup(hide_refs, ref);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ref_is_hidden(const char *refname, const char *refname_full,
|
int ref_is_hidden(const char *refname, const char *refname_full,
|
||||||
const struct string_list *hide_refs)
|
const struct strvec *hide_refs)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = hide_refs->nr - 1; i >= 0; i--) {
|
for (i = hide_refs->nr - 1; i >= 0; i--) {
|
||||||
const char *match = hide_refs->items[i].string;
|
const char *match = hide_refs->v[i];
|
||||||
const char *subject;
|
const char *subject;
|
||||||
int neg = 0;
|
int neg = 0;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
4
refs.h
4
refs.h
|
@ -814,7 +814,7 @@ int update_ref(const char *msg, const char *refname,
|
||||||
unsigned int flags, enum action_on_err onerr);
|
unsigned int flags, enum action_on_err onerr);
|
||||||
|
|
||||||
int parse_hide_refs_config(const char *var, const char *value, const char *,
|
int parse_hide_refs_config(const char *var, const char *value, const char *,
|
||||||
struct string_list *);
|
struct strvec *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether a ref is hidden. If no namespace is set, both the first and
|
* Check whether a ref is hidden. If no namespace is set, both the first and
|
||||||
|
@ -824,7 +824,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *,
|
||||||
* the ref is outside that namespace, the first parameter is NULL. The second
|
* the ref is outside that namespace, the first parameter is NULL. The second
|
||||||
* parameter always points to the full ref name.
|
* parameter always points to the full ref name.
|
||||||
*/
|
*/
|
||||||
int ref_is_hidden(const char *, const char *, const struct string_list *);
|
int ref_is_hidden(const char *, const char *, const struct strvec *);
|
||||||
|
|
||||||
/* Is this a per-worktree ref living in the refs/ namespace? */
|
/* Is this a per-worktree ref living in the refs/ namespace? */
|
||||||
int is_per_worktree_ref(const char *refname);
|
int is_per_worktree_ref(const char *refname);
|
||||||
|
|
|
@ -1558,7 +1558,7 @@ void init_ref_exclusions(struct ref_exclusions *exclusions)
|
||||||
void clear_ref_exclusions(struct ref_exclusions *exclusions)
|
void clear_ref_exclusions(struct ref_exclusions *exclusions)
|
||||||
{
|
{
|
||||||
string_list_clear(&exclusions->excluded_refs, 0);
|
string_list_clear(&exclusions->excluded_refs, 0);
|
||||||
string_list_clear(&exclusions->hidden_refs, 0);
|
strvec_clear(&exclusions->hidden_refs);
|
||||||
exclusions->hidden_refs_configured = 0;
|
exclusions->hidden_refs_configured = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "decorate.h"
|
#include "decorate.h"
|
||||||
#include "ident.h"
|
#include "ident.h"
|
||||||
#include "list-objects-filter-options.h"
|
#include "list-objects-filter-options.h"
|
||||||
|
#include "strvec.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The revision walking API offers functions to build a list of revisions
|
* The revision walking API offers functions to build a list of revisions
|
||||||
|
@ -95,7 +96,7 @@ struct ref_exclusions {
|
||||||
* Hidden refs is a list of patterns that is to be hidden via
|
* Hidden refs is a list of patterns that is to be hidden via
|
||||||
* `ref_is_hidden()`.
|
* `ref_is_hidden()`.
|
||||||
*/
|
*/
|
||||||
struct string_list hidden_refs;
|
struct strvec hidden_refs;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Indicates whether hidden refs have been configured. This is to
|
* Indicates whether hidden refs have been configured. This is to
|
||||||
|
@ -110,7 +111,7 @@ struct ref_exclusions {
|
||||||
*/
|
*/
|
||||||
#define REF_EXCLUSIONS_INIT { \
|
#define REF_EXCLUSIONS_INIT { \
|
||||||
.excluded_refs = STRING_LIST_INIT_DUP, \
|
.excluded_refs = STRING_LIST_INIT_DUP, \
|
||||||
.hidden_refs = STRING_LIST_INIT_DUP, \
|
.hidden_refs = STRVEC_INIT, \
|
||||||
}
|
}
|
||||||
|
|
||||||
struct oidset;
|
struct oidset;
|
||||||
|
|
|
@ -69,7 +69,7 @@ struct upload_pack_data {
|
||||||
struct object_array have_obj;
|
struct object_array have_obj;
|
||||||
struct oid_array haves; /* v2 only */
|
struct oid_array haves; /* v2 only */
|
||||||
struct string_list wanted_refs; /* v2 only */
|
struct string_list wanted_refs; /* v2 only */
|
||||||
struct string_list hidden_refs;
|
struct strvec hidden_refs;
|
||||||
|
|
||||||
struct object_array shallows;
|
struct object_array shallows;
|
||||||
struct string_list deepen_not;
|
struct string_list deepen_not;
|
||||||
|
@ -127,7 +127,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
|
||||||
{
|
{
|
||||||
struct string_list symref = STRING_LIST_INIT_DUP;
|
struct string_list symref = STRING_LIST_INIT_DUP;
|
||||||
struct string_list wanted_refs = STRING_LIST_INIT_DUP;
|
struct string_list wanted_refs = STRING_LIST_INIT_DUP;
|
||||||
struct string_list hidden_refs = STRING_LIST_INIT_DUP;
|
struct strvec hidden_refs = STRVEC_INIT;
|
||||||
struct object_array want_obj = OBJECT_ARRAY_INIT;
|
struct object_array want_obj = OBJECT_ARRAY_INIT;
|
||||||
struct object_array have_obj = OBJECT_ARRAY_INIT;
|
struct object_array have_obj = OBJECT_ARRAY_INIT;
|
||||||
struct oid_array haves = OID_ARRAY_INIT;
|
struct oid_array haves = OID_ARRAY_INIT;
|
||||||
|
@ -162,7 +162,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
|
||||||
{
|
{
|
||||||
string_list_clear(&data->symref, 1);
|
string_list_clear(&data->symref, 1);
|
||||||
string_list_clear(&data->wanted_refs, 1);
|
string_list_clear(&data->wanted_refs, 1);
|
||||||
string_list_clear(&data->hidden_refs, 0);
|
strvec_clear(&data->hidden_refs);
|
||||||
object_array_clear(&data->want_obj);
|
object_array_clear(&data->want_obj);
|
||||||
object_array_clear(&data->have_obj);
|
object_array_clear(&data->have_obj);
|
||||||
oid_array_clear(&data->haves);
|
oid_array_clear(&data->haves);
|
||||||
|
@ -1170,7 +1170,7 @@ static void receive_needs(struct upload_pack_data *data,
|
||||||
|
|
||||||
/* return non-zero if the ref is hidden, otherwise 0 */
|
/* return non-zero if the ref is hidden, otherwise 0 */
|
||||||
static int mark_our_ref(const char *refname, const char *refname_full,
|
static int mark_our_ref(const char *refname, const char *refname_full,
|
||||||
const struct object_id *oid, const struct string_list *hidden_refs)
|
const struct object_id *oid, const struct strvec *hidden_refs)
|
||||||
{
|
{
|
||||||
struct object *o = lookup_unknown_object(the_repository, oid);
|
struct object *o = lookup_unknown_object(the_repository, oid);
|
||||||
|
|
||||||
|
@ -1465,7 +1465,7 @@ static int parse_want(struct packet_writer *writer, const char *line,
|
||||||
|
|
||||||
static int parse_want_ref(struct packet_writer *writer, const char *line,
|
static int parse_want_ref(struct packet_writer *writer, const char *line,
|
||||||
struct string_list *wanted_refs,
|
struct string_list *wanted_refs,
|
||||||
struct string_list *hidden_refs,
|
struct strvec *hidden_refs,
|
||||||
struct object_array *want_obj)
|
struct object_array *want_obj)
|
||||||
{
|
{
|
||||||
const char *refname_nons;
|
const char *refname_nons;
|
||||||
|
|
Loading…
Reference in New Issue