@matheusbsbs / matheus-bagliano / commits / 5ac0a2063e
Fork 0

Make builtin-fsck.c use parse_options.

Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Pierre Habouzit committed Oct 15, 2007 at 22:34 UTC 5ac0a2063e8f824f6e8ffb4d18de74c55aae7131
1 file changed +26 -54
builtin-fsck.c
+26 -54
@@ -8,6 +8,7 @@
8 #include "pack.h"
9 #include "cache-tree.h"
10 #include "tree-walk.h"
11 +#include "parse-options.h"
12
13 #define REACHABLE 0x0001
14 #define SEEN 0x0002
@@ -666,9 +667,24 @@ static int fsck_cache_tree(struct cache_tree *it)
667 return err;
668 }
669
669 -static const char fsck_usage[] =
670 -"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] "
671 -"[--strict] [--verbose] <head-sha1>*]";
670 +static char const * const fsck_usage[] = {
671 + "git-fsck [options] [<object>...]",
672 + NULL
673 +};
674 +
675 +static struct option fsck_opts[] = {
676 + OPT__VERBOSE(&verbose),
677 + OPT_BOOLEAN(0, "unreachable", &show_unreachable, "show unreachable objects"),
678 + OPT_BOOLEAN(0, "tags", &show_tags, "report tags"),
679 + OPT_BOOLEAN(0, "root", &show_root, "report root nodes"),
680 + OPT_BOOLEAN(0, "cache", &keep_cache_objects, "make index objects head nodes"),
681 + OPT_BOOLEAN(0, "reflogs", &include_reflogs, "make reflogs head nodes (default)"),
682 + OPT_BOOLEAN(0, "full", &check_full, "also consider alternate objects"),
683 + OPT_BOOLEAN(0, "struct", &check_strict, "enable more strict checking"),
684 + OPT_BOOLEAN(0, "lost-found", &write_lost_and_found,
685 + "write dangling objects in .git/lost-found"),
686 + OPT_END(),
687 +};
688
689 int cmd_fsck(int argc, const char **argv, const char *prefix)
690 {
@@ -677,49 +693,10 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
693 track_object_refs = 1;
694 errors_found = 0;
695
680 - for (i = 1; i < argc; i++) {
681 - const char *arg = argv[i];
682 -
683 - if (!strcmp(arg, "--unreachable")) {
684 - show_unreachable = 1;
685 - continue;
686 - }
687 - if (!strcmp(arg, "--tags")) {
688 - show_tags = 1;
689 - continue;
690 - }
691 - if (!strcmp(arg, "--root")) {
692 - show_root = 1;
693 - continue;
694 - }
695 - if (!strcmp(arg, "--cache")) {
696 - keep_cache_objects = 1;
697 - continue;
698 - }
699 - if (!strcmp(arg, "--no-reflogs")) {
700 - include_reflogs = 0;
701 - continue;
702 - }
703 - if (!strcmp(arg, "--full")) {
704 - check_full = 1;
705 - continue;
706 - }
707 - if (!strcmp(arg, "--strict")) {
708 - check_strict = 1;
709 - continue;
710 - }
711 - if (!strcmp(arg, "--verbose")) {
712 - verbose = 1;
713 - continue;
714 - }
715 - if (!strcmp(arg, "--lost-found")) {
716 - check_full = 1;
717 - include_reflogs = 0;
718 - write_lost_and_found = 1;
719 - continue;
720 - }
721 - if (*arg == '-')
722 - usage(fsck_usage);
696 + argc = parse_options(argc, argv, fsck_opts, fsck_usage, 0);
697 + if (write_lost_and_found) {
698 + check_full = 1;
699 + include_reflogs = 0;
700 }
701
702 fsck_head_link();
@@ -741,22 +718,18 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
718 verify_pack(p, 0);
719
720 for (p = packed_git; p; p = p->next) {
744 - uint32_t i, num;
721 + uint32_t j, num;
722 if (open_pack_index(p))
723 continue;
724 num = p->num_objects;
748 - for (i = 0; i < num; i++)
749 - fsck_sha1(nth_packed_object_sha1(p, i));
725 + for (j = 0; j < num; j++)
726 + fsck_sha1(nth_packed_object_sha1(p, j));
727 }
728 }
729
730 heads = 0;
731 for (i = 1; i < argc; i++) {
732 const char *arg = argv[i];
756 -
757 - if (*arg == '-')
758 - continue;
759 -
733 if (!get_sha1(arg, head_sha1)) {
734 struct object *obj = lookup_object(head_sha1);
735
@@ -783,7 +756,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
756 }
757
758 if (keep_cache_objects) {
786 - int i;
759 read_cache();
760 for (i = 0; i < active_nr; i++) {
761 unsigned int mode;