Merge branch 'jk/gc-auto-after-fetch'
authorJunio C Hamano <gitster@pobox.com>
Fri, 1 Feb 2013 20:40:16 +0000 (12:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Feb 2013 20:40:16 +0000 (12:40 -0800)
Help "fetch only" repositories that do not trigger "gc --auto"
often enough.

* jk/gc-auto-after-fetch:
fetch-pack: avoid repeatedly re-scanning pack directory
fetch: run gc --auto after fetching

1  2 
builtin/fetch.c
fetch-pack.c
diff --combined builtin/fetch.c
index 3b97fc9bc64fb170bc512cc9054a1a3574a322ba,1ddbf0d0b16490f5135584ff8d3f6acd5dfcf1ec..4b6b1dfe66952a7e3fb1516e7e14473febde3d2d
@@@ -32,7 -32,7 +32,7 @@@ enum 
  
  static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;
  static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 -static int tags = TAGS_DEFAULT;
 +static int tags = TAGS_DEFAULT, unshallow;
  static const char *depth;
  static const char *upload_pack;
  static struct strbuf default_rla = STRBUF_INIT;
@@@ -82,9 -82,6 +82,9 @@@ static struct option builtin_fetch_opti
        OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
        OPT_STRING(0, "depth", &depth, N_("depth"),
                   N_("deepen history of shallow clone")),
 +      { OPTION_SET_INT, 0, "unshallow", &unshallow, NULL,
 +                 N_("convert to a complete repository"),
 +                 PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1 },
        { OPTION_STRING, 0, "submodule-prefix", &submodule_prefix, N_("dir"),
                   N_("prepend this to submodule path output"), PARSE_OPT_HIDDEN },
        { OPTION_STRING, 0, "recurse-submodules-default",
@@@ -962,6 -959,9 +962,9 @@@ int cmd_fetch(int argc, const char **ar
        struct string_list list = STRING_LIST_INIT_NODUP;
        struct remote *remote;
        int result = 0;
+       static const char *argv_gc_auto[] = {
+               "gc", "--auto", NULL,
+       };
  
        packet_trace_identity("fetch");
  
        argc = parse_options(argc, argv, prefix,
                             builtin_fetch_options, builtin_fetch_usage, 0);
  
 +      if (unshallow) {
 +              if (depth)
 +                      die(_("--depth and --unshallow cannot be used together"));
 +              else if (!is_repository_shallow())
 +                      die(_("--unshallow on a complete repository does not make sense"));
 +              else {
 +                      static char inf_depth[12];
 +                      sprintf(inf_depth, "%d", INFINITE_DEPTH);
 +                      depth = inf_depth;
 +              }
 +      }
 +
        if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
                if (recurse_submodules_default) {
                        int arg = parse_fetch_recurse_submodules_arg("--recurse-submodules-default", recurse_submodules_default);
        list.strdup_strings = 1;
        string_list_clear(&list, 0);
  
+       run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
        return result;
  }
diff --combined fetch-pack.c
index f0acdf7331eeaf7a55ad09309a788c5971fe9b7f,b4383c6dca6d10fae3e68a5bd15e094eb3bd1877..6d8926a5504a6cd93e19860f85d58816bdd5c222
@@@ -594,6 -594,9 +594,9 @@@ static int everything_local(struct fetc
        for (ref = *refs; ref; ref = ref->next) {
                struct object *o;
  
+               if (!has_sha1_file(ref->old_sha1))
+                       continue;
                o = parse_object(ref->old_sha1);
                if (!o)
                        continue;
@@@ -874,6 -877,8 +877,6 @@@ static int fetch_pack_config(const cha
        return git_default_config(var, value, cb);
  }
  
 -static struct lock_file lock;
 -
  static void fetch_pack_setup(void)
  {
        static int did_setup;
@@@ -915,7 -920,6 +918,7 @@@ struct ref *fetch_pack(struct fetch_pac
        ref_cpy = do_fetch_pack(args, fd, ref, sought, pack_lockfile);
  
        if (args->depth > 0) {
 +              static struct lock_file lock;
                struct cache_time mtime;
                struct strbuf sb = STRBUF_INIT;
                char *shallow = git_path("shallow");