builtin/fetch-pack: add --refetch option

Add a refetch option to fetch-pack to force a full fetch. Use when applying a new partial clone filter to refetch all matching objects. Signed-off-by: Robert Coup <robert@coup.net.nz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Robert Coup committed Mar 28, 2022 at 14:02 UTC 869a0eb4ebddad9ea758464526524ed06f5a13a9
3 files changed +14
Documentation/git-fetch-pack.txt
+4
@@ -101,6 +101,10 @@ be in a separate packet, and the list must end with a flush packet.
101 current shallow boundary instead of from the tip of each
102 remote branch history.
103
104 +--refetch::
105 + Skips negotiating commits with the server in order to fetch all matching
106 + objects. Use to reapply a new partial clone blob/tree filter.
107 +
108 --no-progress::
109 Do not show the progress.
110
builtin/fetch-pack.c
+4
@@ -153,6 +153,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
153 args.from_promisor = 1;
154 continue;
155 }
156 + if (!strcmp("--refetch", arg)) {
157 + args.refetch = 1;
158 + continue;
159 + }
160 if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
161 parse_list_objects_filter(&args.filter_options, arg);
162 continue;
remote-curl.c
+6
@@ -43,6 +43,7 @@ struct options {
43 /* see documentation of corresponding flag in fetch-pack.h */
44 from_promisor : 1,
45
46 + refetch : 1,
47 atomic : 1,
48 object_format : 1,
49 force_if_includes : 1;
@@ -198,6 +199,9 @@ static int set_option(const char *name, const char *value)
199 } else if (!strcmp(name, "from-promisor")) {
200 options.from_promisor = 1;
201 return 0;
202 + } else if (!strcmp(name, "refetch")) {
203 + options.refetch = 1;
204 + return 0;
205 } else if (!strcmp(name, "filter")) {
206 options.filter = xstrdup(value);
207 return 0;
@@ -1182,6 +1186,8 @@ static int fetch_git(struct discovery *heads,
1186 strvec_push(&args, "--deepen-relative");
1187 if (options.from_promisor)
1188 strvec_push(&args, "--from-promisor");
1189 + if (options.refetch)
1190 + strvec_push(&args, "--refetch");
1191 if (options.filter)
1192 strvec_pushf(&args, "--filter=%s", options.filter);
1193 strvec_push(&args, url.buf);