Skip to content

Commit e12cbea

Browse files
committed
Merge branch 'bw/ref-prefix-for-configured-refspec'
"git fetch $there $refspec" that talks over protocol v2 can take advantage of server-side ref filtering; the code has been extended so that this mechanism triggers also when fetching with configured refspec. * bw/ref-prefix-for-configured-refspec: (38 commits) fetch: generate ref-prefixes when using a configured refspec refspec: consolidate ref-prefix generation logic submodule: convert push_unpushed_submodules to take a struct refspec remote: convert check_push_refs to take a struct refspec remote: convert match_push_refs to take a struct refspec http-push: store refspecs in a struct refspec transport: remove transport_verify_remote_names send-pack: store refspecs in a struct refspec transport: convert transport_push to take a struct refspec push: convert to use struct refspec push: check for errors earlier remote: convert match_explicit_refs to take a struct refspec remote: convert get_ref_match to take a struct refspec remote: convert query_refspecs to take a struct refspec remote: convert apply_refspecs to take a struct refspec remote: convert get_stale_heads to take a struct refspec fetch: convert prune_refs to take a struct refspec fetch: convert get_ref_map to take a struct refspec fetch: convert do_fetch to take a struct refspec refspec: remove the deprecated functions ...
2 parents 6ac5aca + dcc73cf commit e12cbea

23 files changed

+570
-613
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ LIB_OBJS += refs/files-backend.o
928928
LIB_OBJS += refs/iterator.o
929929
LIB_OBJS += refs/packed-backend.o
930930
LIB_OBJS += refs/ref-cache.o
931+
LIB_OBJS += refspec.o
931932
LIB_OBJS += ref-filter.o
932933
LIB_OBJS += remote.o
933934
LIB_OBJS += replace-object.o

branch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include "config.h"
44
#include "branch.h"
55
#include "refs.h"
6+
#include "refspec.h"
67
#include "remote.h"
78
#include "commit.h"
89
#include "worktree.h"
910

1011
struct tracking {
11-
struct refspec spec;
12+
struct refspec_item spec;
1213
char *src;
1314
const char *remote;
1415
int matches;
@@ -218,8 +219,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force)
218219
static int check_tracking_branch(struct remote *remote, void *cb_data)
219220
{
220221
char *tracking_branch = cb_data;
221-
struct refspec query;
222-
memset(&query, 0, sizeof(struct refspec));
222+
struct refspec_item query;
223+
memset(&query, 0, sizeof(struct refspec_item));
223224
query.dst = tracking_branch;
224225
return !remote_find_tracking(remote, &query);
225226
}

builtin/clone.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "parse-options.h"
1515
#include "fetch-pack.h"
1616
#include "refs.h"
17+
#include "refspec.h"
1718
#include "tree.h"
1819
#include "tree-walk.h"
1920
#include "unpack-trees.h"
@@ -546,7 +547,7 @@ static struct ref *find_remote_branch(const struct ref *refs, const char *branch
546547
}
547548

548549
static struct ref *wanted_peer_refs(const struct ref *refs,
549-
struct refspec *refspec)
550+
struct refspec_item *refspec)
550551
{
551552
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
552553
struct ref *local_refs = head;
@@ -894,8 +895,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
894895
int err = 0, complete_refs_before_fetch = 1;
895896
int submodule_progress;
896897

897-
struct refspec *refspec;
898-
const char *fetch_pattern;
898+
struct refspec_item refspec;
899899

900900
fetch_if_missing = 0;
901901

@@ -1077,8 +1077,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10771077
if (option_required_reference.nr || option_optional_reference.nr)
10781078
setup_reference();
10791079

1080-
fetch_pattern = value.buf;
1081-
refspec = parse_fetch_refspec(1, &fetch_pattern);
1080+
refspec_item_init(&refspec, value.buf, REFSPEC_FETCH);
10821081

10831082
strbuf_reset(&value);
10841083

@@ -1138,7 +1137,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11381137
refs = transport_get_remote_refs(transport, NULL);
11391138

11401139
if (refs) {
1141-
mapped_refs = wanted_peer_refs(refs, refspec);
1140+
mapped_refs = wanted_peer_refs(refs, &refspec);
11421141
/*
11431142
* transport_get_remote_refs() may return refs with null sha-1
11441143
* in mapped_refs (see struct transport->get_refs_list
@@ -1232,6 +1231,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12321231
strbuf_release(&value);
12331232
junk_mode = JUNK_LEAVE_ALL;
12341233

1235-
free(refspec);
1234+
refspec_item_clear(&refspec);
12361235
return err;
12371236
}

builtin/fast-export.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "cache.h"
88
#include "config.h"
99
#include "refs.h"
10+
#include "refspec.h"
1011
#include "commit.h"
1112
#include "object.h"
1213
#include "tag.h"
@@ -35,8 +36,7 @@ static int use_done_feature;
3536
static int no_data;
3637
static int full_tree;
3738
static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
38-
static struct refspec *refspecs;
39-
static int refspecs_nr;
39+
static struct refspec refspecs = REFSPEC_INIT_FETCH;
4040
static int anonymize;
4141

4242
static int parse_opt_signed_tag_mode(const struct option *opt,
@@ -828,9 +828,9 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
828828
if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
829829
continue;
830830

831-
if (refspecs) {
831+
if (refspecs.nr) {
832832
char *private;
833-
private = apply_refspecs(refspecs, refspecs_nr, full_name);
833+
private = apply_refspecs(&refspecs, full_name);
834834
if (private) {
835835
free(full_name);
836836
full_name = private;
@@ -976,8 +976,8 @@ static void import_marks(char *input_file)
976976
static void handle_deletes(void)
977977
{
978978
int i;
979-
for (i = 0; i < refspecs_nr; i++) {
980-
struct refspec *refspec = &refspecs[i];
979+
for (i = 0; i < refspecs.nr; i++) {
980+
struct refspec_item *refspec = &refspecs.items[i];
981981
if (*refspec->src)
982982
continue;
983983

@@ -1038,18 +1038,12 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
10381038
usage_with_options (fast_export_usage, options);
10391039

10401040
if (refspecs_list.nr) {
1041-
const char **refspecs_str;
10421041
int i;
10431042

1044-
ALLOC_ARRAY(refspecs_str, refspecs_list.nr);
10451043
for (i = 0; i < refspecs_list.nr; i++)
1046-
refspecs_str[i] = refspecs_list.items[i].string;
1047-
1048-
refspecs_nr = refspecs_list.nr;
1049-
refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str);
1044+
refspec_append(&refspecs, refspecs_list.items[i].string);
10501045

10511046
string_list_clear(&refspecs_list, 1);
1052-
free(refspecs_str);
10531047
}
10541048

10551049
if (use_done_feature)
@@ -1088,7 +1082,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
10881082
if (use_done_feature)
10891083
printf("done\n");
10901084

1091-
free_refspec(refspecs_nr, refspecs);
1085+
refspec_clear(&refspecs);
10921086

10931087
return 0;
10941088
}

0 commit comments

Comments
 (0)