Merge branch 'js/close-packs-before-gc'
authorJunio C Hamano <gitster@pobox.com>
Tue, 26 Jan 2016 23:40:29 +0000 (15:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Jan 2016 23:40:29 +0000 (15:40 -0800)
Many codepaths that run "gc --auto" before exiting kept packfiles
mapped and left the file descriptors to them open, which was not
friendly to systems that cannot remove files that are open. They
now close the packs before doing so.

* js/close-packs-before-gc:
receive-pack: release pack files before garbage-collecting
merge: release pack files before garbage-collecting
am: release pack files before garbage-collecting
fetch: release pack files before garbage-collecting

1  2 
builtin/fetch.c
builtin/receive-pack.c
t/t5510-fetch.sh
diff --combined builtin/fetch.c
index 33f04c1b4a3a75c7840e26ed8334b015aa84a099,5b58001a982d0c0361c8693d05c609fd0b5fcd9c..8e742135f049c2792bfc5a20299dac88518929cc
@@@ -37,7 -37,6 +37,7 @@@ static int prune = -1; /* unspecified *
  static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
  static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
  static int tags = TAGS_DEFAULT, unshallow, update_shallow;
 +static int max_children = 1;
  static const char *depth;
  static const char *upload_pack;
  static struct strbuf default_rla = STRBUF_INIT;
@@@ -100,8 -99,6 +100,8 @@@ static struct option builtin_fetch_opti
                    N_("fetch all tags and associated objects"), TAGS_SET),
        OPT_SET_INT('n', NULL, &tags,
                    N_("do not fetch all tags (--no-tags)"), TAGS_UNSET),
 +      OPT_INTEGER('j', "jobs", &max_children,
 +                  N_("number of submodules fetched in parallel")),
        OPT_BOOL('p', "prune", &prune,
                 N_("prune remote-tracking branches no longer on remote")),
        { OPTION_CALLBACK, 0, "recurse-submodules", NULL, N_("on-demand"),
@@@ -840,7 -837,7 +840,7 @@@ static void check_not_current_branch(st
  static int truncate_fetch_head(void)
  {
        const char *filename = git_path_fetch_head();
 -      FILE *fp = fopen(filename, "w");
 +      FILE *fp = fopen_for_writing(filename);
  
        if (!fp)
                return error(_("cannot open %s: %s\n"), filename, strerror(errno));
@@@ -1216,8 -1213,7 +1216,8 @@@ int cmd_fetch(int argc, const char **ar
                result = fetch_populated_submodules(&options,
                                                    submodule_prefix,
                                                    recurse_submodules,
 -                                                  verbosity < 0);
 +                                                  verbosity < 0,
 +                                                  max_children);
                argv_array_clear(&options);
        }
  
        list.strdup_strings = 1;
        string_list_clear(&list, 0);
  
+       close_all_packs();
        argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
        if (verbosity < 0)
                argv_array_push(&argv_gc_auto, "--quiet");
diff --combined builtin/receive-pack.c
index 2b3b746fb40d7a3da9cefd4688b6f60efde10c24,b3104433ed6923600f3874ae564c9d04f9a9dcd2..f2d6761af66c8bcc43c2da13f69fa083cf1e1e60
@@@ -1618,7 -1618,7 +1618,7 @@@ static void prepare_shallow_update(stru
                                continue;
                        si->need_reachability_test[i]++;
                        for (k = 0; k < 32; k++)
 -                              if (si->used_shallow[i][j] & (1 << k))
 +                              if (si->used_shallow[i][j] & (1U << k))
                                        si->shallow_ref[j * 32 + k]++;
                }
  
@@@ -1796,6 -1796,7 +1796,7 @@@ int cmd_receive_pack(int argc, const ch
                                "gc", "--auto", "--quiet", NULL,
                        };
                        int opt = RUN_GIT_CMD | RUN_COMMAND_STDOUT_TO_STDERR;
+                       close_all_packs();
                        run_command_v_opt(argv_gc_auto, opt);
                }
                if (auto_update_server_info)
diff --combined t/t5510-fetch.sh
index 47e68a597cfb5a99a236915845eb8627e47204a5,e3ee4bd700c3e72479ce1c7a4d8b1333a35a8473..9203a6507fa8df75ef187c129f750921caf19951
@@@ -7,7 -7,7 +7,7 @@@ test_description='Per branch config var
  
  . ./test-lib.sh
  
 -D=`pwd`
 +D=$(pwd)
  
  test_bundle_object_count () {
        git verify-pack -v "$1" >verify.out &&
@@@ -64,8 -64,8 +64,8 @@@ test_expect_success "fetch test" 
        cd two &&
        git fetch &&
        test -f .git/refs/heads/one &&
 -      mine=`git rev-parse refs/heads/one` &&
 -      his=`cd ../one && git rev-parse refs/heads/master` &&
 +      mine=$(git rev-parse refs/heads/one) &&
 +      his=$(cd ../one && git rev-parse refs/heads/master) &&
        test "z$mine" = "z$his"
  '
  
@@@ -75,8 -75,8 +75,8 @@@ test_expect_success "fetch test for-mer
        git fetch &&
        test -f .git/refs/heads/two &&
        test -f .git/refs/heads/one &&
 -      master_in_two=`cd ../two && git rev-parse master` &&
 -      one_in_two=`cd ../two && git rev-parse one` &&
 +      master_in_two=$(cd ../two && git rev-parse master) &&
 +      one_in_two=$(cd ../two && git rev-parse one) &&
        {
                echo "$one_in_two       "
                echo "$master_in_two    not-for-merge"
@@@ -708,4 -708,17 +708,17 @@@ test_expect_success 'fetching a one-lev
        )
  '
  
+ test_expect_success 'fetching with auto-gc does not lock up' '
+       write_script askyesno <<-\EOF &&
+       echo "$*" &&
+       false
+       EOF
+       git clone "file://$D" auto-gc &&
+       test_commit test2 &&
+       cd auto-gc &&
+       git config gc.autoPackLimit 1 &&
+       GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
+       ! grep "Should I try again" fetch.out
+ '
  test_done