8
#include "sideband.h"
9
#include "fetch-pack.h"
10
11
-static int keep_pack;
11
static int transfer_unpack_limit = -1;
12
static int fetch_unpack_limit = -1;
13
static int unpack_limit = 100;
15
-static int quiet;
16
-static int verbose;
17
-static int fetch_all;
18
-static int depth;
19
-static int no_progress;
14
+static struct fetch_pack_args args;
15
+
16
static const char fetch_pack_usage[] =
17
"git-fetch-pack [--all] [--quiet|-q] [--keep|-k] [--thin] [--upload-pack=<git-upload-pack>] [--depth=<n>] [--no-progress] [-v] [<host>:]<directory> [<refs>...]";
18
static const char *uploadpack = "git-upload-pack";
177
(use_sideband == 2 ? " side-band-64k" : ""),
178
(use_sideband == 1 ? " side-band" : ""),
179
(use_thin_pack ? " thin-pack" : ""),
184
- (no_progress ? " no-progress" : ""),
180
+ (args.no_progress ? " no-progress" : ""),
181
" ofs-delta");
182
else
183
packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
185
}
186
if (is_repository_shallow())
187
write_shallow_commits(fd[1], 1);
192
- if (depth > 0)
193
- packet_write(fd[1], "deepen %d", depth);
188
+ if (args.depth > 0)
189
+ packet_write(fd[1], "deepen %d", args.depth);
190
packet_flush(fd[1]);
191
if (!fetching)
192
return 1;
193
198
- if (depth > 0) {
194
+ if (args.depth > 0) {
195
char line[1024];
196
unsigned char sha1[20];
197
int len;
222
retval = -1;
223
while ((sha1 = get_rev())) {
224
packet_write(fd[1], "have %s\n", sha1_to_hex(sha1));
229
- if (verbose)
225
+ if (args.verbose)
226
fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
227
in_vain++;
228
if (!(31 & ++count)) {
240
241
do {
242
ack = get_ack(fd[0], result_sha1);
247
- if (verbose && ack)
243
+ if (args.verbose && ack)
244
fprintf(stderr, "got ack %d %s\n", ack,
245
sha1_to_hex(result_sha1));
246
if (ack == 1) {
259
} while (ack);
260
flushes--;
261
if (got_continue && MAX_IN_VAIN < in_vain) {
266
- if (verbose)
262
+ if (args.verbose)
263
fprintf(stderr, "giving up\n");
264
break; /* give up */
265
}
267
}
268
done:
269
packet_write(fd[1], "done\n");
274
- if (verbose)
270
+ if (args.verbose)
271
fprintf(stderr, "done\n");
272
if (retval != 0) {
273
multi_ack = 0;
276
while (flushes || multi_ack) {
277
int ack = get_ack(fd[0], result_sha1);
278
if (ack) {
283
- if (verbose)
279
+ if (args.verbose)
280
fprintf(stderr, "got ack (%d) %s\n", ack,
281
sha1_to_hex(result_sha1));
282
if (ack == 1)
313
static void mark_recent_complete_commits(unsigned long cutoff)
314
{
315
while (complete && cutoff <= complete->item->date) {
320
- if (verbose)
316
+ if (args.verbose)
317
fprintf(stderr, "Marking %s as complete\n",
318
sha1_to_hex(complete->item->object.sha1));
319
pop_most_recent_commit(&complete, COMPLETE);
328
struct ref *ref, *next;
329
struct ref *fastarray[32];
330
335
- if (nr_match && !fetch_all) {
331
+ if (nr_match && !args.fetch_all) {
332
if (ARRAY_SIZE(fastarray) < nr_match)
333
return_refs = xcalloc(nr_match, sizeof(struct ref *));
334
else {
344
if (!memcmp(ref->name, "refs/", 5) &&
345
check_ref_format(ref->name + 5))
346
; /* trash */
351
- else if (fetch_all &&
352
- (!depth || prefixcmp(ref->name, "refs/tags/") )) {
347
+ else if (args.fetch_all &&
348
+ (!args.depth || prefixcmp(ref->name, "refs/tags/") )) {
349
*newtail = ref;
350
ref->next = NULL;
351
newtail = &ref->next;
361
free(ref);
362
}
363
368
- if (!fetch_all) {
364
+ if (!args.fetch_all) {
365
int i;
366
for (i = 0; i < nr_match; i++) {
367
ref = return_refs[i];
404
}
405
}
406
411
- if (!depth) {
407
+ if (!args.depth) {
408
for_each_ref(mark_complete, NULL);
409
if (cutoff)
410
mark_recent_complete_commits(cutoff);
438
o = lookup_object(remote);
439
if (!o || !(o->flags & COMPLETE)) {
440
retval = 0;
445
- if (!verbose)
441
+ if (!args.verbose)
442
continue;
443
fprintf(stderr,
444
"want %s (%s)\n", sha1_to_hex(remote),
447
}
448
449
hashcpy(ref->new_sha1, local);
454
- if (!verbose)
450
+ if (!args.verbose)
451
continue;
452
fprintf(stderr,
453
"already have %s (%s)\n", sha1_to_hex(remote),
498
char keep_arg[256];
499
char hdr_arg[256];
500
const char **av;
505
- int do_keep = keep_pack;
501
+ int do_keep = args.keep_pack;
502
int keep_pipe[2];
503
504
side_pid = setup_sideband(fd, xd);
505
506
av = argv;
507
*hdr_arg = 0;
512
- if (unpack_limit) {
508
+ if (!args.keep_pack && unpack_limit) {
509
struct pack_header header;
510
511
if (read_pack_header(fd[0], &header))
523
die("fetch-pack: pipe setup failure: %s", strerror(errno));
524
*av++ = "index-pack";
525
*av++ = "--stdin";
530
- if (!quiet && !no_progress)
526
+ if (!args.quiet && !args.no_progress)
527
*av++ = "-v";
532
- if (use_thin_pack)
528
+ if (args.use_thin_pack)
529
*av++ = "--fix-thin";
534
- if (keep_pack > 1 || unpack_limit) {
530
+ if (args.lock_pack || unpack_limit) {
531
int s = sprintf(keep_arg,
532
"--keep=fetch-pack %d on ", getpid());
533
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
537
}
538
else {
539
*av++ = "unpack-objects";
544
- if (quiet)
540
+ if (args.quiet)
541
*av++ = "-q";
542
}
543
if (*hdr_arg)
595
if (is_repository_shallow() && !server_supports("shallow"))
596
die("Server does not support shallow clients");
597
if (server_supports("multi_ack")) {
602
- if (verbose)
598
+ if (args.verbose)
599
fprintf(stderr, "Server supports multi_ack\n");
600
multi_ack = 1;
601
}
602
if (server_supports("side-band-64k")) {
607
- if (verbose)
603
+ if (args.verbose)
604
fprintf(stderr, "Server supports side-band-64k\n");
605
use_sideband = 2;
606
}
607
else if (server_supports("side-band")) {
612
- if (verbose)
608
+ if (args.verbose)
609
fprintf(stderr, "Server supports side-band\n");
610
use_sideband = 1;
611
}
618
goto all_done;
619
}
620
if (find_common(fd, sha1, ref) < 0)
625
- if (keep_pack != 1)
621
+ if (!args.keep_pack)
622
/* When cloning, it is not unusual to have
623
* no common commit.
624
*/
670
671
static struct lock_file lock;
672
677
-void setup_fetch_pack(struct fetch_pack_args *args)
678
-{
679
- uploadpack = args->uploadpack;
680
- quiet = args->quiet;
681
- keep_pack = args->keep_pack;
682
- if (args->unpacklimit >= 0)
683
- unpack_limit = args->unpacklimit;
684
- if (args->keep_pack)
685
- unpack_limit = 0;
686
- use_thin_pack = args->use_thin_pack;
687
- fetch_all = args->fetch_all;
688
- verbose = args->verbose;
689
- depth = args->depth;
690
- no_progress = args->no_progress;
691
-}
692
-
673
int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
674
{
675
int i, ret, nr_heads;
690
691
if (*arg == '-') {
692
if (!prefixcmp(arg, "--upload-pack=")) {
713
- uploadpack = arg + 14;
693
+ args.uploadpack = arg + 14;
694
continue;
695
}
696
if (!prefixcmp(arg, "--exec=")) {
717
- uploadpack = arg + 7;
697
+ args.uploadpack = arg + 7;
698
continue;
699
}
700
if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
721
- quiet = 1;
701
+ args.quiet = 1;
702
continue;
703
}
704
if (!strcmp("--keep", arg) || !strcmp("-k", arg)) {
725
- keep_pack++;
726
- unpack_limit = 0;
705
+ args.lock_pack = args.keep_pack;
706
+ args.keep_pack = 1;
707
continue;
708
}
709
if (!strcmp("--thin", arg)) {
730
- use_thin_pack = 1;
710
+ args.use_thin_pack = 1;
711
continue;
712
}
713
if (!strcmp("--all", arg)) {
734
- fetch_all = 1;
714
+ args.fetch_all = 1;
715
continue;
716
}
717
if (!strcmp("-v", arg)) {
738
- verbose = 1;
718
+ args.verbose = 1;
719
continue;
720
}
721
if (!prefixcmp(arg, "--depth=")) {
742
- depth = strtol(arg + 8, NULL, 0);
722
+ args.depth = strtol(arg + 8, NULL, 0);
723
continue;
724
}
725
if (!strcmp("--no-progress", arg)) {
746
- no_progress = 1;
726
+ args.no_progress = 1;
727
continue;
728
}
729
usage(fetch_pack_usage);
736
if (!dest)
737
usage(fetch_pack_usage);
738
759
- ref = fetch_pack(dest, nr_heads, heads, NULL);
760
-
739
+ ref = fetch_pack(&args, dest, nr_heads, heads, NULL);
740
ret = !ref;
741
742
while (ref) {
748
return ret;
749
}
750
772
-struct ref *fetch_pack(const char *dest,
751
+struct ref *fetch_pack(struct fetch_pack_args *my_args,
752
+ const char *dest,
753
int nr_heads,
754
char **heads,
755
char **pack_lockfile)
760
struct ref *ref;
761
struct stat st;
762
783
- if (depth > 0) {
763
+ memcpy(&args, my_args, sizeof(args));
764
+ if (args.depth > 0) {
765
if (stat(git_path("shallow"), &st))
766
st.st_mtime = 0;
767
}
768
769
pid = git_connect(fd, (char *)dest, uploadpack,
789
- verbose ? CONNECT_VERBOSE : 0);
770
+ args.verbose ? CONNECT_VERBOSE : 0);
771
if (pid < 0)
772
return NULL;
773
if (heads && nr_heads)
790
}
791
}
792
812
- if (!ret && depth > 0) {
793
+ if (!ret && args.depth > 0) {
794
struct cache_time mtime;
795
char *shallow = git_path("shallow");
796
int fd;