refs: get rid of global list of hidden refs
We're about to add a new argument to git-rev-list(1) that allows it to add all references that are visible when taking `transfer.hideRefs` et al into account. This will require us to potentially parse multiple sets of hidden refs, which is not easily possible right now as there is only a single, global instance of the list of parsed hidden refs. Refactor `parse_hide_refs_config()` and `ref_is_hidden()` so that both take the list of hidden references as input and adjust callers to keep a local list, instead. This allows us to easily use multiple hidden-ref lists. Furthermore, it allows us to properly free this list before we exit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:

committed by
Taylor Blau

parent
5eeb9aa208
commit
9b67eb6fbe
@ -62,6 +62,7 @@ struct upload_pack_data {
|
||||
struct object_array have_obj;
|
||||
struct oid_array haves; /* v2 only */
|
||||
struct string_list wanted_refs; /* v2 only */
|
||||
struct string_list hidden_refs;
|
||||
|
||||
struct object_array shallows;
|
||||
struct string_list deepen_not;
|
||||
@ -118,6 +119,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
|
||||
{
|
||||
struct string_list symref = STRING_LIST_INIT_DUP;
|
||||
struct string_list wanted_refs = STRING_LIST_INIT_DUP;
|
||||
struct string_list hidden_refs = STRING_LIST_INIT_DUP;
|
||||
struct object_array want_obj = OBJECT_ARRAY_INIT;
|
||||
struct object_array have_obj = OBJECT_ARRAY_INIT;
|
||||
struct oid_array haves = OID_ARRAY_INIT;
|
||||
@ -130,6 +132,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
|
||||
memset(data, 0, sizeof(*data));
|
||||
data->symref = symref;
|
||||
data->wanted_refs = wanted_refs;
|
||||
data->hidden_refs = hidden_refs;
|
||||
data->want_obj = want_obj;
|
||||
data->have_obj = have_obj;
|
||||
data->haves = haves;
|
||||
@ -151,6 +154,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
|
||||
{
|
||||
string_list_clear(&data->symref, 1);
|
||||
string_list_clear(&data->wanted_refs, 1);
|
||||
string_list_clear(&data->hidden_refs, 0);
|
||||
object_array_clear(&data->want_obj);
|
||||
object_array_clear(&data->have_obj);
|
||||
oid_array_clear(&data->haves);
|
||||
@ -842,8 +846,8 @@ static void deepen(struct upload_pack_data *data, int depth)
|
||||
* Checking for reachable shallows requires that our refs be
|
||||
* marked with OUR_REF.
|
||||
*/
|
||||
head_ref_namespaced(check_ref, NULL);
|
||||
for_each_namespaced_ref(check_ref, NULL);
|
||||
head_ref_namespaced(check_ref, data);
|
||||
for_each_namespaced_ref(check_ref, data);
|
||||
|
||||
get_reachable_list(data, &reachable_shallows);
|
||||
result = get_shallow_commits(&reachable_shallows,
|
||||
@ -1158,11 +1162,11 @@ static void receive_needs(struct upload_pack_data *data,
|
||||
|
||||
/* return non-zero if the ref is hidden, otherwise 0 */
|
||||
static int mark_our_ref(const char *refname, const char *refname_full,
|
||||
const struct object_id *oid)
|
||||
const struct object_id *oid, const struct string_list *hidden_refs)
|
||||
{
|
||||
struct object *o = lookup_unknown_object(the_repository, oid);
|
||||
|
||||
if (ref_is_hidden(refname, refname_full)) {
|
||||
if (ref_is_hidden(refname, refname_full, hidden_refs)) {
|
||||
o->flags |= HIDDEN_REF;
|
||||
return 1;
|
||||
}
|
||||
@ -1171,11 +1175,12 @@ static int mark_our_ref(const char *refname, const char *refname_full,
|
||||
}
|
||||
|
||||
static int check_ref(const char *refname_full, const struct object_id *oid,
|
||||
int flag UNUSED, void *cb_data UNUSED)
|
||||
int flag UNUSED, void *cb_data)
|
||||
{
|
||||
const char *refname = strip_namespace(refname_full);
|
||||
struct upload_pack_data *data = cb_data;
|
||||
|
||||
mark_our_ref(refname, refname_full, oid);
|
||||
mark_our_ref(refname, refname_full, oid, &data->hidden_refs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1204,7 +1209,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
|
||||
struct object_id peeled;
|
||||
struct upload_pack_data *data = cb_data;
|
||||
|
||||
if (mark_our_ref(refname_nons, refname, oid))
|
||||
if (mark_our_ref(refname_nons, refname, oid, &data->hidden_refs))
|
||||
return 0;
|
||||
|
||||
if (capabilities) {
|
||||
@ -1327,7 +1332,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
|
||||
if (parse_object_filter_config(var, value, data) < 0)
|
||||
return -1;
|
||||
|
||||
return parse_hide_refs_config(var, value, "uploadpack");
|
||||
return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);
|
||||
}
|
||||
|
||||
static int upload_pack_protected_config(const char *var, const char *value, void *cb_data)
|
||||
@ -1375,8 +1380,8 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
|
||||
advertise_shallow_grafts(1);
|
||||
packet_flush(1);
|
||||
} else {
|
||||
head_ref_namespaced(check_ref, NULL);
|
||||
for_each_namespaced_ref(check_ref, NULL);
|
||||
head_ref_namespaced(check_ref, &data);
|
||||
for_each_namespaced_ref(check_ref, &data);
|
||||
}
|
||||
|
||||
if (!advertise_refs) {
|
||||
@ -1441,6 +1446,7 @@ static int parse_want(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 *hidden_refs,
|
||||
struct object_array *want_obj)
|
||||
{
|
||||
const char *refname_nons;
|
||||
@ -1451,7 +1457,7 @@ static int parse_want_ref(struct packet_writer *writer, const char *line,
|
||||
struct strbuf refname = STRBUF_INIT;
|
||||
|
||||
strbuf_addf(&refname, "%s%s", get_git_namespace(), refname_nons);
|
||||
if (ref_is_hidden(refname_nons, refname.buf) ||
|
||||
if (ref_is_hidden(refname_nons, refname.buf, hidden_refs) ||
|
||||
read_ref(refname.buf, &oid)) {
|
||||
packet_writer_error(writer, "unknown ref %s", refname_nons);
|
||||
die("unknown ref %s", refname_nons);
|
||||
@ -1508,7 +1514,7 @@ static void process_args(struct packet_reader *request,
|
||||
continue;
|
||||
if (data->allow_ref_in_want &&
|
||||
parse_want_ref(&data->writer, arg, &data->wanted_refs,
|
||||
&data->want_obj))
|
||||
&data->hidden_refs, &data->want_obj))
|
||||
continue;
|
||||
/* process have line */
|
||||
if (parse_have(arg, &data->haves))
|
||||
|
Reference in New Issue
Block a user