git/builtin/gc.c

/*
 * git gc builtin command
 *
 * Cleanup unreachable files and optimize the repository.
 *
 * Copyright (c) 2007 James Bowes
 *
 * Based on git-gc.sh, which is
 *
 * Copyright (c) 2006 Shawn O. Pearce
 */
#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "date.h"
#include "environment.h"
#include "hex.h"
#include "config.h"
#include "tempfile.h"
#include "lockfile.h"
#include "parse-options.h"
#include "run-command.h"
#include "sigchain.h"
#include "strvec.h"
#include "commit.h"
#include "commit-graph.h"
#include "packfile.h"
#include "object-file.h"
#include "object-store-ll.h"
#include "pack.h"
#include "pack-objects.h"
#include "path.h"
#include "blob.h"
#include "tree.h"
#include "promisor-remote.h"
#include "refs.h"
#include "remote.h"
#include "exec-cmd.h"
#include "gettext.h"
#include "hook.h"
#include "setup.h"
#include "trace2.h"

#define FAILED_RUN

static const char * const builtin_gc_usage[] =;

static timestamp_t gc_log_expire_time;

static struct strvec reflog =;
static struct strvec repack =;
static struct strvec prune =;
static struct strvec prune_worktrees =;
static struct strvec rerere =;

static struct tempfile *pidfile;
static struct lock_file log_lock;

static struct string_list pack_garbage =;

static void clean_pack_garbage(void)
{}

static void report_pack_garbage(unsigned seen_bits, const char *path)
{}

static void process_log_file(void)
{}

static void process_log_file_at_exit(void)
{}

static int gc_config_is_timestamp_never(const char *var)
{}

struct gc_config {};

#define GC_CONFIG_INIT

static void gc_config_release(struct gc_config *cfg)
{}

static void gc_config(struct gc_config *cfg)
{}

enum schedule_priority {};

static enum schedule_priority parse_schedule(const char *value)
{}

struct maintenance_run_opts {};
#define MAINTENANCE_RUN_OPTS_INIT

static int pack_refs_condition(UNUSED struct gc_config *cfg)
{}

static int maintenance_task_pack_refs(struct maintenance_run_opts *opts,
				      UNUSED struct gc_config *cfg)
{}

static int too_many_loose_objects(struct gc_config *cfg)
{}

static struct packed_git *find_base_packs(struct string_list *packs,
					  unsigned long limit)
{}

static int too_many_packs(struct gc_config *cfg)
{}

static uint64_t total_ram(void)
{}

static uint64_t estimate_repack_memory(struct gc_config *cfg,
				       struct packed_git *pack)
{}

static int keep_one_pack(struct string_list_item *item, void *data UNUSED)
{}

static void add_repack_all_option(struct gc_config *cfg,
				  struct string_list *keep_pack)
{}

static void add_repack_incremental_option(void)
{}

static int need_to_gc(struct gc_config *cfg)
{}

/* return NULL on success, else hostname running the gc */
static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
{}

/*
 * Returns 0 if there was no previous error and gc can proceed, 1 if
 * gc should not proceed due to an error in the last run. Prints a
 * message and returns with a non-[01] status code if an error occurred
 * while reading gc.log
 */
static int report_last_gc_error(void)
{}

static void gc_before_repack(struct maintenance_run_opts *opts,
			     struct gc_config *cfg)
{}

int cmd_gc(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{}

static const char *const builtin_maintenance_run_usage[] =;

static int maintenance_opt_schedule(const struct option *opt, const char *arg,
				    int unset)
{}

/* Remember to update object flag allocation in object.h */
#define SEEN

struct cg_auto_data {};

static int dfs_on_ref(const char *refname UNUSED,
		      const char *referent UNUSED,
		      const struct object_id *oid,
		      int flags UNUSED,
		      void *cb_data)
{}

static int should_write_commit_graph(struct gc_config *cfg UNUSED)
{}

static int run_write_commit_graph(struct maintenance_run_opts *opts)
{}

static int maintenance_task_commit_graph(struct maintenance_run_opts *opts,
					 struct gc_config *cfg UNUSED)
{}

static int fetch_remote(struct remote *remote, void *cbdata)
{}

static int maintenance_task_prefetch(struct maintenance_run_opts *opts,
				     struct gc_config *cfg UNUSED)
{}

static int maintenance_task_gc(struct maintenance_run_opts *opts,
			       struct gc_config *cfg UNUSED)
{}

static int prune_packed(struct maintenance_run_opts *opts)
{}

struct write_loose_object_data {};

static int loose_object_auto_limit =;

static int loose_object_count(const struct object_id *oid UNUSED,
			      const char *path UNUSED,
			      void *data)
{}

static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
{}

static int bail_on_loose(const struct object_id *oid UNUSED,
			 const char *path UNUSED,
			 void *data UNUSED)
{}

static int write_loose_object_to_stdin(const struct object_id *oid,
				       const char *path UNUSED,
				       void *data)
{}

static int pack_loose(struct maintenance_run_opts *opts)
{}

static int maintenance_task_loose_objects(struct maintenance_run_opts *opts,
					  struct gc_config *cfg UNUSED)
{}

static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED)
{}

static int multi_pack_index_write(struct maintenance_run_opts *opts)
{}

static int multi_pack_index_expire(struct maintenance_run_opts *opts)
{}

#define TWO_GIGABYTES

static off_t get_auto_pack_size(void)
{}

static int multi_pack_index_repack(struct maintenance_run_opts *opts)
{}

static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts,
					       struct gc_config *cfg UNUSED)
{}

maintenance_task_fn;

/*
 * An auto condition function returns 1 if the task should run
 * and 0 if the task should NOT run. See needs_to_gc() for an
 * example.
 */
maintenance_auto_fn;

struct maintenance_task {};

enum maintenance_task_label {};

static struct maintenance_task tasks[] =;

static int compare_tasks_by_selection(const void *a_, const void *b_)
{}

static int maintenance_run_tasks(struct maintenance_run_opts *opts,
				 struct gc_config *cfg)
{}

static void initialize_maintenance_strategy(void)
{}

static void initialize_task_config(int schedule)
{}

static int task_option_parse(const struct option *opt UNUSED,
			     const char *arg, int unset)
{}

static int maintenance_run(int argc, const char **argv, const char *prefix)
{}

static char *get_maintpath(void)
{}

static char const * const builtin_maintenance_register_usage[] =;

static int maintenance_register(int argc, const char **argv, const char *prefix)
{}

static char const * const builtin_maintenance_unregister_usage[] =;

static int maintenance_unregister(int argc, const char **argv, const char *prefix)
{}

static const char *get_frequency(enum schedule_priority schedule)
{}

static const char *extraconfig[] =;

static const char *get_extra_config_parameters(void) {}

static const char *get_extra_launchctl_strings(void) {}

/*
 * get_schedule_cmd` reads the GIT_TEST_MAINT_SCHEDULER environment variable
 * to mock the schedulers that `git maintenance start` rely on.
 *
 * For test purpose, GIT_TEST_MAINT_SCHEDULER can be set to a comma-separated
 * list of colon-separated key/value pairs where each pair contains a scheduler
 * and its corresponding mock.
 *
 * * If $GIT_TEST_MAINT_SCHEDULER is not set, return false and leave the
 *   arguments unmodified.
 *
 * * If $GIT_TEST_MAINT_SCHEDULER is set, return true.
 *   In this case, the *cmd value is read as input.
 *
 *   * if the input value cmd is the key of one of the comma-separated list
 *     item, then *is_available is set to true and *out is set to
 *     the mock command.
 *
 *   * if the input value *cmd isn’t the key of any of the comma-separated list
 *     item, then *is_available is set to false and *out is set to the original
 *     command.
 *
 * Ex.:
 *   GIT_TEST_MAINT_SCHEDULER not set
 *     +-------+-------------------------------------------------+
 *     | Input |                     Output                      |
 *     | *cmd  | return code |       *out        | *is_available |
 *     +-------+-------------+-------------------+---------------+
 *     | "foo" |    false    | NULL              |  (unchanged)  |
 *     +-------+-------------+-------------------+---------------+
 *
 *   GIT_TEST_MAINT_SCHEDULER set to “foo:./mock_foo.sh,bar:./mock_bar.sh”
 *     +-------+-------------------------------------------------+
 *     | Input |                     Output                      |
 *     | *cmd  | return code |       *out        | *is_available |
 *     +-------+-------------+-------------------+---------------+
 *     | "foo" |    true     |  "./mock.foo.sh"  |     true      |
 *     | "qux" |    true     | "qux" (allocated) |     false     |
 *     +-------+-------------+-------------------+---------------+
 */
static int get_schedule_cmd(const char *cmd, int *is_available, char **out)
{}

static int get_random_minute(void)
{}

static int is_launchctl_available(void)
{}

static char *launchctl_service_name(const char *frequency)
{}

static char *launchctl_service_filename(const char *name)
{}

static char *launchctl_get_uid(void)
{}

static int launchctl_boot_plist(int enable, const char *filename)
{}

static int launchctl_remove_plist(enum schedule_priority schedule)
{}

static int launchctl_remove_plists(void)
{}

static int launchctl_list_contains_plist(const char *name, const char *cmd)
{}

static int launchctl_schedule_plist(const char *exec_path, enum schedule_priority schedule)
{}

static int launchctl_add_plists(void)
{}

static int launchctl_update_schedule(int run_maintenance, int fd UNUSED)
{}

static int is_schtasks_available(void)
{}

static char *schtasks_task_name(const char *frequency)
{}

static int schtasks_remove_task(enum schedule_priority schedule)
{}

static int schtasks_remove_tasks(void)
{}

static int schtasks_schedule_task(const char *exec_path, enum schedule_priority schedule)
{}

static int schtasks_schedule_tasks(void)
{}

static int schtasks_update_schedule(int run_maintenance, int fd UNUSED)
{}

MAYBE_UNUSED
static int check_crontab_process(const char *cmd)
{}

static int is_crontab_available(void)
{}

#define BEGIN_LINE
#define END_LINE

static int crontab_update_schedule(int run_maintenance, int fd)
{}

static int real_is_systemd_timer_available(void)
{}

static int is_systemd_timer_available(void)
{}

static char *xdg_config_home_systemd(const char *filename)
{}

#define SYSTEMD_UNIT_FORMAT

static int systemd_timer_delete_timer_file(enum schedule_priority priority)
{}

static int systemd_timer_delete_service_template(void)
{}

/*
 * Write the schedule information into a git-maintenance@<schedule>.timer
 * file using a custom minute. This timer file cannot use the templating
 * system, so we generate a specific file for each.
 */
static int systemd_timer_write_timer_file(enum schedule_priority schedule,
					  int minute)
{}

/*
 * No matter the schedule, we use the same service and can make use of the
 * templating system. When installing git-maintenance@<schedule>.timer,
 * systemd will notice that [email protected] exists as a template
 * and will use this file and insert the <schedule> into the template at
 * the position of "%i".
 */
static int systemd_timer_write_service_template(const char *exec_path)
{}

static int systemd_timer_enable_unit(int enable,
				     enum schedule_priority schedule,
				     int minute)
{}

/*
 * A previous version of Git wrote the timer units as template files.
 * Clean these up, if they exist.
 */
static void systemd_timer_delete_stale_timer_templates(void)
{}

static int systemd_timer_delete_unit_files(void)
{}

static int systemd_timer_delete_units(void)
{}

static int systemd_timer_setup_units(void)
{}

static int systemd_timer_update_schedule(int run_maintenance, int fd UNUSED)
{}

enum scheduler {};

static const struct {} scheduler_fn[] =;

static enum scheduler parse_scheduler(const char *value)
{}

static int maintenance_opt_scheduler(const struct option *opt, const char *arg,
				     int unset)
{}

struct maintenance_start_opts {};

static enum scheduler resolve_scheduler(enum scheduler scheduler)
{}

static void validate_scheduler(enum scheduler scheduler)
{}

static int update_background_schedule(const struct maintenance_start_opts *opts,
				      int enable)
{}

static const char *const builtin_maintenance_start_usage[] =;

static int maintenance_start(int argc, const char **argv, const char *prefix)
{}

static const char *const builtin_maintenance_stop_usage[] =;

static int maintenance_stop(int argc, const char **argv, const char *prefix)
{}

static const char * const builtin_maintenance_usage[] =;

int cmd_maintenance(int argc,
		    const char **argv,
		    const char *prefix,
		    struct repository *repo UNUSED)
{}