예제 #1
0
int cmd_prune(int argc, const char **argv, const char *prefix)
{
	struct rev_info revs;
	struct progress *progress = NULL;
	const struct option options[] = {
		OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
		OPT__VERBOSE(&verbose, N_("report pruned objects")),
		OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
		OPT_EXPIRY_DATE(0, "expire", &expire,
				N_("expire objects older than <time>")),
		OPT_END()
	};
	char *s;

	expire = TIME_MAX;
	save_commit_buffer = 0;
	check_replace_refs = 0;
	ref_paranoia = 1;
	init_revisions(&revs, prefix);

	argc = parse_options(argc, argv, prefix, options, prune_usage, 0);

	if (repository_format_precious_objects)
		die(_("cannot prune in a precious-objects repo"));

	while (argc--) {
		struct object_id oid;
		const char *name = *argv++;

		if (!get_oid(name, &oid)) {
			struct object *object = parse_object_or_die(&oid,
								    name);
			add_pending_object(&revs, object, "");
		}
		else
			die("unrecognized argument: %s", name);
	}

	if (show_progress == -1)
		show_progress = isatty(2);
	if (show_progress)
		progress = start_progress_delay(_("Checking connectivity"), 0, 0, 2);

	mark_reachable_objects(&revs, 1, expire, progress);
	stop_progress(&progress);
	for_each_loose_file_in_objdir(get_object_directory(), prune_object,
				      prune_cruft, prune_subdir, NULL);

	prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
	remove_temporary_files(get_object_directory());
	s = mkpathdup("%s/pack", get_object_directory());
	remove_temporary_files(s);
	free(s);

	if (is_repository_shallow())
		prune_shallow(show_only);

	return 0;
}
예제 #2
0
void prune_packed_objects(int opts)
{
	if (opts & PRUNE_PACKED_VERBOSE)
		progress = start_delayed_progress(_("Removing duplicate objects"), 256);

	for_each_loose_file_in_objdir(get_object_directory(),
				      prune_object, NULL, prune_subdir, &opts);

	/* Ensure we show 100% before finishing progress */
	display_progress(progress, 256);
	stop_progress(&progress);
}
예제 #3
0
파일: fsck.c 프로젝트: DoWonJin/git
static void fsck_object_dir(const char *path)
{
	struct progress *progress = NULL;

	if (verbose)
		fprintf(stderr, "Checking object directory\n");

	if (show_progress)
		progress = start_progress(_("Checking object directories"), 256);

	for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir,
				      progress);
	display_progress(progress, 256);
	stop_progress(&progress);
}
예제 #4
0
int cmd_count_objects(int argc, const char **argv, const char *prefix)
{
    int human_readable = 0;
    struct option opts[] = {
        OPT__VERBOSE(&verbose, N_("be verbose")),
        OPT_BOOL('H', "human-readable", &human_readable,
        N_("print sizes in human readable format")),
        OPT_END(),
    };

    git_config(git_default_config, NULL);

    argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0);
    /* we do not take arguments other than flags for now */
    if (argc)
        usage_with_options(count_objects_usage, opts);
    if (verbose) {
        report_garbage = real_report_garbage;
        report_linked_checkout_garbage();
    }

    for_each_loose_file_in_objdir(get_object_directory(),
                                  count_loose, count_cruft, NULL, NULL);

    if (verbose) {
        struct packed_git *p;
        unsigned long num_pack = 0;
        off_t size_pack = 0;
        struct strbuf loose_buf = STRBUF_INIT;
        struct strbuf pack_buf = STRBUF_INIT;
        struct strbuf garbage_buf = STRBUF_INIT;
        if (!packed_git)
            prepare_packed_git();
        for (p = packed_git; p; p = p->next) {
            if (!p->pack_local)
                continue;
            if (open_pack_index(p))
                continue;
            packed += p->num_objects;
            size_pack += p->pack_size + p->index_size;
            num_pack++;
        }

        if (human_readable) {
            strbuf_humanise_bytes(&loose_buf, loose_size);
            strbuf_humanise_bytes(&pack_buf, size_pack);
            strbuf_humanise_bytes(&garbage_buf, size_garbage);
        } else {
            strbuf_addf(&loose_buf, "%lu",
                        (unsigned long)(loose_size / 1024));
            strbuf_addf(&pack_buf, "%lu",
                        (unsigned long)(size_pack / 1024));
            strbuf_addf(&garbage_buf, "%lu",
                        (unsigned long)(size_garbage / 1024));
        }

        printf("count: %lu\n", loose);
        printf("size: %s\n", loose_buf.buf);
        printf("in-pack: %lu\n", packed);
        printf("packs: %lu\n", num_pack);
        printf("size-pack: %s\n", pack_buf.buf);
        printf("prune-packable: %lu\n", packed_loose);
        printf("garbage: %lu\n", garbage);
        printf("size-garbage: %s\n", garbage_buf.buf);
        foreach_alt_odb(print_alternate, NULL);
        strbuf_release(&loose_buf);
        strbuf_release(&pack_buf);
        strbuf_release(&garbage_buf);
    } else {
        struct strbuf buf = STRBUF_INIT;
        if (human_readable)
            strbuf_humanise_bytes(&buf, loose_size);
        else
            strbuf_addf(&buf, "%lu kilobytes",
                        (unsigned long)(loose_size / 1024));
        printf("%lu objects, %s\n", loose, buf.buf);
        strbuf_release(&buf);
    }
    return 0;
}