From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH v2 4/4] fsck: print progress Date: Mon, 7 Nov 2011 09:59:26 +0700 Message-ID: <1320634766-24511-5-git-send-email-pclouds@gmail.com> References: <1320634766-24511-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Junio C Hamano , Jeff King , Stephen Boyd , =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Mon Nov 07 04:01:38 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RNFSq-0008BS-Mv for gcvg-git-2@lo.gmane.org; Mon, 07 Nov 2011 04:01:37 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755172Ab1KGDBc convert rfc822-to-quoted-printable (ORCPT ); Sun, 6 Nov 2011 22:01:32 -0500 Received: from mail-iy0-f174.google.com ([209.85.210.174]:43933 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751071Ab1KGDBb (ORCPT ); Sun, 6 Nov 2011 22:01:31 -0500 Received: by iage36 with SMTP id e36so5338224iag.19 for ; Sun, 06 Nov 2011 19:01:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=YnNGB2aCQ/6vYBTGPzSb9CnpzICyjJKLrgV6wOpe0UY=; b=FtdrWv0Tc55+04bxXgVWfmr9guE57G6E7UlxcNN0f6/0gCB8WsnpR0rxTxKEYPged2 5Aks6DoKUo6VtqmMGagXM7AdHXCBCPHnpnS2fkiv1npy9nwKsZDhlcSP6lwfRHyPaXiY GGQ31WR5+6IaZRpqAoCaQt5eQY5/siC+CV+LY= Received: by 10.42.164.194 with SMTP id h2mr41595344icy.44.1320634891170; Sun, 06 Nov 2011 19:01:31 -0800 (PST) Received: from pclouds@gmail.com ([115.73.230.110]) by mx.google.com with ESMTPS id km16sm32569254pbb.9.2011.11.06.19.01.26 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 06 Nov 2011 19:01:30 -0800 (PST) Received: by pclouds@gmail.com (sSMTP sendmail emulation); Mon, 07 Nov 2011 10:00:06 +0700 X-Mailer: git-send-email 1.7.4.74.g639db In-Reply-To: <1320634766-24511-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: fsck is usually a long process and it would be nice if it prints progress from time to time. Progress meter is not printed when --verbose is given because --verbose prints a lot, there's no need for "alive" indicator. Progress meter may provide "% complete" information but it would be lost anyway in the flood of text. Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- Documentation/git-fsck.txt | 11 ++++++++++- builtin/fsck.c | 40 ++++++++++++++++++++++++++++++++++++= ++-- pack-check.c | 14 +++++++++++--- pack.h | 3 ++- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Documentation/git-fsck.txt b/Documentation/git-fsck.txt index a2a508d..0a17b42 100644 --- a/Documentation/git-fsck.txt +++ b/Documentation/git-fsck.txt @@ -10,7 +10,8 @@ SYNOPSIS -------- [verse] 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs] - [--[no-]full] [--strict] [--verbose] [--lost-found] [*] + [--[no-]full] [--strict] [--verbose] [--lost-found] + [--[no-]progress] [*] =20 DESCRIPTION ----------- @@ -72,6 +73,14 @@ index file, all SHA1 references in .git/refs/*, and = all reflogs (unless a blob, the contents are written into the file, rather than its object name. =20 +--progress:: +--no-progress:: + Progress status is reported on the standard error stream by + default when it is attached to a terminal, unless + --no-progress or --verbose is specified. --progress forces + progress status even if the standard error stream is not + directed to a terminal. + It tests SHA1 and general object sanity, and it does full tracking of the resulting reachability and everything else. It prints out any corruption it finds (missing or bad objects), and if you use the diff --git a/builtin/fsck.c b/builtin/fsck.c index 0603f64..c4b1ca6 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -11,6 +11,7 @@ #include "fsck.h" #include "parse-options.h" #include "dir.h" +#include "progress.h" =20 #define REACHABLE 0x0001 #define SEEN 0x0002 @@ -27,6 +28,7 @@ static const char *head_points_at; static int errors_found; static int write_lost_and_found; static int verbose; +static int show_progress =3D -1; #define ERROR_OBJECT 01 #define ERROR_REACHABLE 02 #define ERROR_PACK 04 @@ -138,7 +140,11 @@ static int traverse_one_object(struct object *obj) =20 static int traverse_reachable(void) { + struct progress *progress =3D NULL; + unsigned int nr =3D 0; int result =3D 0; + if (show_progress) + progress =3D start_progress_delay("Checking connectivity", 0, 0, 2); while (pending.nr) { struct object_array_entry *entry; struct object *obj; @@ -146,7 +152,9 @@ static int traverse_reachable(void) entry =3D pending.objects + --pending.nr; obj =3D entry->item; result |=3D traverse_one_object(obj); + display_progress(progress, ++nr); } + stop_progress(&progress); return !!result; } =20 @@ -530,15 +538,20 @@ static void get_default_heads(void) static void fsck_object_dir(const char *path) { int i; + struct progress *progress =3D NULL; =20 if (verbose) fprintf(stderr, "Checking object directory\n"); =20 + if (show_progress) + progress =3D start_progress("Checking object directories", 256); for (i =3D 0; i < 256; i++) { static char dir[4096]; sprintf(dir, "%s/%02x", path, i); fsck_dir(i, dir); + display_progress(progress, i+1); } + stop_progress(&progress); fsck_sha1_list(); } =20 @@ -609,6 +622,7 @@ static struct option fsck_opts[] =3D { OPT_BOOLEAN(0, "strict", &check_strict, "enable more strict checking"= ), OPT_BOOLEAN(0, "lost-found", &write_lost_and_found, "write dangling objects in .git/lost-found"), + OPT_BOOL (0, "progress", &show_progress, "show progress"), OPT_END(), }; =20 @@ -621,6 +635,12 @@ int cmd_fsck(int argc, const char **argv, const ch= ar *prefix) read_replace_refs =3D 0; =20 argc =3D parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0); + + if (show_progress =3D=3D -1) + show_progress =3D isatty(2); + if (verbose) + show_progress =3D 0; + if (write_lost_and_found) { check_full =3D 1; include_reflogs =3D 0; @@ -640,12 +660,28 @@ int cmd_fsck(int argc, const char **argv, const c= har *prefix) =20 if (check_full) { struct packed_git *p; + uint32_t total =3D 0, count =3D 0; + struct progress *progress =3D NULL; =20 prepare_packed_git(); - for (p =3D packed_git; p; p =3D p->next) + + if (show_progress) { + for (p =3D packed_git; p; p =3D p->next) { + if (open_pack_index(p)) + continue; + total +=3D p->num_objects; + } + + progress =3D start_progress("Checking objects", total); + } + for (p =3D packed_git; p; p =3D p->next) { /* verify gives error messages itself */ - if (verify_pack(p, fsck_obj_buffer)) + if (verify_pack(p, fsck_obj_buffer, + progress, count)) errors_found |=3D ERROR_PACK; + count +=3D p->num_objects; + } + stop_progress(&progress); } =20 heads =3D 0; diff --git a/pack-check.c b/pack-check.c index 3b48b86..63a595c 100644 --- a/pack-check.c +++ b/pack-check.c @@ -1,6 +1,7 @@ #include "cache.h" #include "pack.h" #include "pack-revindex.h" +#include "progress.h" =20 struct idx_entry { off_t offset; @@ -43,7 +44,9 @@ int check_pack_crc(struct packed_git *p, struct pack_= window **w_curs, =20 static int verify_packfile(struct packed_git *p, struct pack_window **w_curs, - verify_fn fn) + verify_fn fn, + struct progress *progress, uint32_t base_count) + { off_t index_size =3D p->index_size; const unsigned char *index_base =3D p->index_data; @@ -127,8 +130,12 @@ static int verify_packfile(struct packed_git *p, if (eaten) data =3D NULL; } + if (((base_count + i) & 1023) =3D=3D 0) + display_progress(progress, base_count + i); free(data); + } + display_progress(progress, base_count + i); free(entries); =20 return err; @@ -157,7 +164,8 @@ int verify_pack_index(struct packed_git *p) return err; } =20 -int verify_pack(struct packed_git *p, verify_fn fn) +int verify_pack(struct packed_git *p, verify_fn fn, + struct progress *progress, uint32_t base_count) { int err =3D 0; struct pack_window *w_curs =3D NULL; @@ -166,7 +174,7 @@ int verify_pack(struct packed_git *p, verify_fn fn) if (!p->index_data) return -1; =20 - err |=3D verify_packfile(p, &w_curs, fn); + err |=3D verify_packfile(p, &w_curs, fn, progress, base_count); unuse_pack(&w_curs); =20 return err; diff --git a/pack.h b/pack.h index 70f3c29..324a1d7 100644 --- a/pack.h +++ b/pack.h @@ -71,12 +71,13 @@ struct pack_idx_entry { }; =20 =20 +struct progress; typedef int (*verify_fn)(const unsigned char*, enum object_type, unsig= ned long, void*, int*); =20 extern const char *write_idx_file(const char *index_name, struct pack_= idx_entry **objects, int nr_objects, const struct pack_idx_option *, un= signed char *sha1); extern int check_pack_crc(struct packed_git *p, struct pack_window **w= _curs, off_t offset, off_t len, unsigned int nr); extern int verify_pack_index(struct packed_git *); -extern int verify_pack(struct packed_git *, verify_fn fn); +extern int verify_pack(struct packed_git *, verify_fn fn, struct progr= ess *, uint32_t); extern void fixup_pack_header_footer(int, unsigned char *, const char = *, uint32_t, unsigned char *, off_t); extern char *index_pack_lockfile(int fd); extern int encode_in_pack_object_header(enum object_type, uintmax_t, u= nsigned char *); --=20 1.7.4.74.g639db