493
return side_pid;
494
}
495
496
-static int get_pack(int xd[2])
496
+static int get_pack(int xd[2], char **pack_lockfile)
497
{
498
int status;
499
pid_t pid, side_pid;
503
char hdr_arg[256];
504
const char **av;
505
int do_keep = keep_pack;
506
+ int keep_pipe[2];
507
508
side_pid = setup_sideband(fd, xd);
509
523
}
524
525
if (do_keep) {
526
+ if (pack_lockfile && pipe(keep_pipe))
527
+ die("fetch-pack: pipe setup failure: %s", strerror(errno));
528
*av++ = "index-pack";
529
*av++ = "--stdin";
530
if (!quiet && !no_progress)
553
die("fetch-pack: unable to fork off %s", argv[0]);
554
if (!pid) {
555
dup2(fd[0], 0);
556
+ if (do_keep && pack_lockfile) {
557
+ dup2(keep_pipe[1], 1);
558
+ close(keep_pipe[0]);
559
+ close(keep_pipe[1]);
560
+ }
561
close(fd[0]);
562
close(fd[1]);
563
execv_git_cmd(argv);
565
}
566
close(fd[0]);
567
close(fd[1]);
568
+ if (do_keep && pack_lockfile) {
569
+ close(keep_pipe[1]);
570
+ *pack_lockfile = index_pack_lockfile(keep_pipe[0]);
571
+ close(keep_pipe[0]);
572
+ }
573
while (waitpid(pid, &status, 0) < 0) {
574
if (errno != EINTR)
575
die("waiting for %s: %s", argv[0], strerror(errno));
587
die("%s died of unnatural causes %d", argv[0], status);
588
}
589
577
-static struct ref *do_fetch_pack(int fd[2], int nr_match, char **match)
590
+static struct ref *do_fetch_pack(int fd[2],
591
+ int nr_match,
592
+ char **match,
593
+ char **pack_lockfile)
594
{
595
struct ref *ref;
596
unsigned char sha1[20];
628
*/
629
fprintf(stderr, "warning: no common commits\n");
630
615
- if (get_pack(fd))
631
+ if (get_pack(fd, pack_lockfile))
632
die("git-fetch-pack: fetch failed.");
633
634
all_done:
757
if (!dest)
758
usage(fetch_pack_usage);
759
744
- ref = fetch_pack(dest, nr_heads, heads);
760
+ ref = fetch_pack(dest, nr_heads, heads, NULL);
761
762
ret = !ref;
763
770
return ret;
771
}
772
757
-struct ref *fetch_pack(const char *dest, int nr_heads, char **heads)
773
+struct ref *fetch_pack(const char *dest,
774
+ int nr_heads,
775
+ char **heads,
776
+ char **pack_lockfile)
777
{
778
int i, ret;
779
int fd[2];
792
return NULL;
793
if (heads && nr_heads)
794
nr_heads = remove_duplicates(nr_heads, heads);
776
- ref = do_fetch_pack(fd, nr_heads, heads);
795
+ ref = do_fetch_pack(fd, nr_heads, heads, pack_lockfile);
796
close(fd[0]);
797
close(fd[1]);
798
ret = finish_connect(pid);