{"thread":{"id":"685","subject":"[PATCH 2/3] - Convert git-fsck-cache to argp","startedAt":"2005-05-21T18:32:51Z","lastAt":"2005-05-21T18:32:51Z","messageCount":1,"participants":["Sean"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"3707","messageId":"2236.10.10.10.24.1116700371.squirrel@linux1","threadId":"685","inReplyTo":null,"subject":"[PATCH 2/3] - Convert git-fsck-cache to argp","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-21T18:32:51Z","receivedAt":"2005-05-21T18:32:51Z","isPatch":true,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"\nFirst in a series of patches to convert git commands to use \"argp\" for\nargument processing as suggested by Jeff Garzik.  This patch converts\ngit-fsck-cache.  It improves the usage message, adds a --version option,\nand allows options to be combined together with a single leading dash.\n\nSigned-off-by: Sean Estabrooks <seanlkml@sympatico.ca>\nAcked-by: \"Jeff Garzik\" <jgarzik@pobox.com>\nAcked-by: \"Junio C Hamano\" <junkio@cox.net>\n\n\n Documentation/git-fsck-cache.txt |    6 +++\n fsck-cache.c                     |   60\n++++++++++++++++++++++-----------------\n 2 files changed, 39 insertions(+), 27 deletions(-)\n\n\n\nIndex: fsck-cache.c\n===================================================================\n--- 58741c69570705801db4b785681790d636475695/fsck-cache.c  (mode:100644)\n+++ uncommitted/fsck-cache.c  (mode:100644)\n@@ -1,5 +1,7 @@\n #include <sys/types.h>\n #include <dirent.h>\n+#include <argp.h>\n+const char *argp_program_version = VERSION;\n \n #include \"cache.h\"\n #include \"commit.h\"\n@@ -407,36 +409,42 @@\n \tfind_file_objects(git_dir, \"refs\");\n }\n \n+static const char doc[] = \"Perform repository consistency check\";\n+\n+static struct argp_option options[] = {\n+ {\"unreachable\", 'u', 0, 0, \"Show missing objects or deltas\"},\n+ {\"tags\", 't', 0, 0, \"Show revision tags\"},\n+ {\"root\", 'r', 0, 0, \"Show root objects, ie. those without parents\"},\n+ {\"delta-depth\", 'd', 0, 0, \"Show the maximum length of delta chains\"},\n+ {\"cache\", 'c', 0, 0, \"Mark all objects referenced by cache as reachable\"},\n+ { }\n+};\n+\n+static error_t parse_opt (int key, char *arg, struct argp_state *state)\n+{\n+        switch (key) {\n+        case 'u':\t\tshow_unreachable = 1; break;\n+        case 't':\t\tshow_tags = 1; break;\n+        case 'r':\t\tshow_root = 1; break;\n+        case 'd':\t\tshow_max_delta_depth = 1; break;\n+        case 'c':\t\tkeep_cache_objects = 1; break;\n+        default:\t\treturn ARGP_ERR_UNKNOWN;\n+        }\n+        return 0;\n+}\n+\n+static const struct argp argp = { options, parse_opt, \"[HEAD-SHA1...]\", doc };\n+\n int main(int argc, char **argv)\n {\n \tint i, heads;\n \tchar *sha1_dir;\n+\tint idx;\n \n-\tfor (i = 1; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n-\n-\t\tif (!strcmp(arg, \"--unreachable\")) {\n-\t\t\tshow_unreachable = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--tags\")) {\n-\t\t\tshow_tags = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--root\")) {\n-\t\t\tshow_root = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--delta-depth\")) {\n-\t\t\tshow_max_delta_depth = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--cache\")) {\n-\t\t\tkeep_cache_objects = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (*arg == '-')\n-\t\t\tusage(\"git-fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]\");\n+\terror_t rc = argp_parse(&argp, argc, argv, 0, &idx, NULL);\n+\tif (rc) {\n+\t\tfprintf(stderr, \"argument failed: %s\\n\", strerror(rc));\n+\t\treturn 1;\n \t}\n \n \tsha1_dir = get_object_directory();\n@@ -450,7 +458,7 @@\n \texpand_deltas();\n \n \theads = 0;\n-\tfor (i = 1; i < argc; i++) {\n+\tfor (i = idx; i < argc; i++) {\n \t\tconst char *arg = argv[i]; \n \n \t\tif (*arg == '-')\nIndex: Documentation/git-fsck-cache.txt\n===================================================================\n--- 4708925e3e3b955ffcb417fc4acdbb0aafdf8dc0/Documentation/git-fsck-cache.txt  (mode:100644)\n+++ uncommitted/Documentation/git-fsck-cache.txt  (mode:100644)\n@@ -9,7 +9,8 @@\n \n SYNOPSIS\n --------\n-'git-fsck-cache' [--tags] [--root] [[--unreachable] [--cache] <object>\\*]\n+'git-fsck-cache' [--tags] [--root] [--delta-depth] \n+\t\t\t[[--unreachable] [--cache] <object>\\*]\n \n DESCRIPTION\n -----------\n@@ -34,6 +35,9 @@\n \tConsider any object recorded in the cache also as a head node for\n \tan unreachability trace.\n \n+--delta-depth::\n+\tShow length of longest delta chain.\n+\n It tests SHA1 and general object sanity, and it does full tracking of\n the resulting reachability and everything else. It prints out any\n corruption it finds (missing or bad objects), and if you use the\n"}]}