Small refactoring of the command line parsing so we can more easily add new long options to the mix. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- builtin-cat-file.c | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/builtin-cat-file.c b/builtin-cat-file.c index f132d58..b2437fe 100644 --- a/builtin-cat-file.c +++ b/builtin-cat-file.c @@ -82,25 +82,26 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) enum object_type type; void *buf; unsigned long size; - int opt; - const char *exp_type, *obj_name; + int opt = 0, i; + const char *exp_type = NULL, *obj_name = NULL; git_config(git_default_config); - if (argc != 3) + for (i = 1; i < argc; i++) { + const char *a = argv[i]; + if (!opt && a[0] == '-' && a[1]) + opt = a[1]; + else if (!opt && !exp_type) + exp_type = a; + else if (!obj_name) + obj_name = a; + else + break; + } + if (!obj_name) usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>"); - exp_type = argv[1]; - obj_name = argv[2]; - if (get_sha1(obj_name, sha1)) die("Not a valid object name %s", obj_name); - opt = 0; - if ( exp_type[0] == '-' ) { - opt = exp_type[1]; - if ( !opt || exp_type[2] ) - opt = -1; /* Not a single character option */ - } - buf = NULL; switch (opt) { case 't': -- 1.5.1.1.135.gf948 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html