Merge branch 'js/close-packs-before-gc' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Feb 2016 22:54:13 +0000 (14:54 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Feb 2016 22:54:13 +0000 (14:54 -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
diff --combined builtin/fetch.c
index 9e24bb485f4ba438c8e3cd84856b13f4ab7fa927,5b58001a982d0c0361c8693d05c609fd0b5fcd9c..17f40e10f6960e73fa1bff0024c7e1a09a1d8503
@@@ -837,7 -837,7 +837,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));
@@@ -1221,6 -1221,8 +1221,8 @@@ int cmd_fetch(int argc, const char **ar
        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)