static int need_to_gc(void) { /* * Setting gc.auto to 0 or negative can disable the * automatic gc. */ if (gc_auto_threshold <= 0) return 0; /* * If there are too many loose objects, but not too many * packs, we run "repack -d -l". If there are too many packs, * we run "repack -A -d -l". Otherwise we tell the caller * there is no need. */ if (too_many_packs()) add_repack_all_option(); else if (too_many_loose_objects()) add_repack_incremental_option(); else return 0; if (run_hook_le(NULL, "pre-auto-gc", NULL)) return 0; return 1; }
static int checkout(void) { unsigned char sha1[20]; char *head; struct lock_file *lock_file; struct unpack_trees_options opts; struct tree *tree; struct tree_desc t; int err = 0; if (option_no_checkout) return 0; head = resolve_refdup("HEAD", RESOLVE_REF_READING, sha1, NULL); if (!head) { warning(_("remote HEAD refers to nonexistent ref, " "unable to checkout.\n")); return 0; } if (!strcmp(head, "HEAD")) { if (advice_detached_head) detach_advice(sha1_to_hex(sha1)); } else { if (!starts_with(head, "refs/heads/")) die(_("HEAD not found below refs/heads!")); } free(head); /* We need to be in the new work tree for the checkout */ setup_work_tree(); lock_file = xcalloc(1, sizeof(struct lock_file)); hold_locked_index(lock_file, 1); memset(&opts, 0, sizeof opts); opts.update = 1; opts.merge = 1; opts.fn = oneway_merge; opts.verbose_update = (option_verbosity >= 0); opts.src_index = &the_index; opts.dst_index = &the_index; tree = parse_tree_indirect(sha1); parse_tree(tree); init_tree_desc(&t, tree->buffer, tree->size); if (unpack_trees(1, &t, &opts) < 0) die(_("unable to checkout working tree")); if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1), sha1_to_hex(sha1), "1", NULL); if (!err && option_recursive) err = run_command_v_opt(argv_submodule, RUN_GIT_CMD); return err; }
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit, int changed) { return run_hook_le(NULL, "post-checkout", oid_to_hex(old_commit ? &old_commit->object.oid : &null_oid), oid_to_hex(new_commit ? &new_commit->object.oid : &null_oid), changed ? "1" : "0", NULL); /* "new_commit" can be NULL when checking out from the index before a commit exists. */ }
static const char *push_to_checkout(unsigned char *sha1, struct argv_array *env, const char *work_tree) { argv_array_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); if (run_hook_le(env->argv, push_to_checkout_hook, sha1_to_hex(sha1), NULL)) return "push-to-checkout hook declined"; else return NULL; }
static void finish(struct commit *head_commit, struct commit_list *remoteheads, const unsigned char *new_head, const char *msg) { struct strbuf reflog_message = STRBUF_INIT; const unsigned char *head = head_commit->object.oid.hash; if (!msg) strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION")); else { if (verbosity >= 0) printf("%s\n", msg); strbuf_addf(&reflog_message, "%s: %s", getenv("GIT_REFLOG_ACTION"), msg); } if (squash) { squash_message(head_commit, remoteheads); } else { if (verbosity >= 0 && !merge_msg.len) printf(_("No merge message -- not updating HEAD\n")); else { const char *argv_gc_auto[] = { "gc", "--auto", NULL }; update_ref(reflog_message.buf, "HEAD", new_head, head, 0, UPDATE_REFS_DIE_ON_ERR); /* * We ignore errors in 'gc --auto', since the * user should see them. */ close_all_packs(); run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); } } if (new_head && show_diffstat) { struct diff_options opts; diff_setup(&opts); opts.stat_width = -1; /* use full terminal width */ opts.stat_graph_width = -1; /* respect statGraphWidth config */ opts.output_format |= DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; opts.detect_rename = DIFF_DETECT_RENAME; diff_setup_done(&opts); diff_tree_sha1(head, new_head, "", &opts); diffcore_std(&opts); diff_flush(&opts); } /* Run a post-merge hook */ run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL); strbuf_release(&reflog_message); }
static int need_to_gc(void) { /* * Setting gc.auto to 0 or negative can disable the * automatic gc. */ if (gc_auto_threshold <= 0) return 0; /* * If there are too many loose objects, but not too many * packs, we run "repack -d -l". If there are too many packs, * we run "repack -A -d -l". Otherwise we tell the caller * there is no need. */ if (too_many_packs()) { struct string_list keep_pack = STRING_LIST_INIT_NODUP; if (big_pack_threshold) { find_base_packs(&keep_pack, big_pack_threshold); if (keep_pack.nr >= gc_auto_pack_limit) { big_pack_threshold = 0; string_list_clear(&keep_pack, 0); find_base_packs(&keep_pack, 0); } } else { struct packed_git *p = find_base_packs(&keep_pack, 0); uint64_t mem_have, mem_want; mem_have = total_ram(); mem_want = estimate_repack_memory(p); /* * Only allow 1/2 of memory for pack-objects, leave * the rest for the OS and other processes in the * system. */ if (!mem_have || mem_want < mem_have / 2) string_list_clear(&keep_pack, 0); } add_repack_all_option(&keep_pack); string_list_clear(&keep_pack, 0); } else if (too_many_loose_objects()) add_repack_incremental_option(); else return 0; if (run_hook_le(NULL, "pre-auto-gc", NULL)) return 0; return 1; }