From: Junio C Hamano Date: Sat, 3 Apr 2010 19:28:40 +0000 (-0700) Subject: Merge branch 'ef/cherry-abbrev' X-Git-Tag: v1.7.1-rc0~16 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=40a56f45bcfeb5443bbd3b7f9e9f7ffd570d5398;hp=0cb050abc2e7f05894f9f79d5330ce4559653af6;p=git.git Merge branch 'ef/cherry-abbrev' * ef/cherry-abbrev: ls: remove redundant logic cherry: support --abbrev option --- diff --git a/builtin/log.c b/builtin/log.c index 542ecc708..b706a5ff8 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1303,8 +1303,11 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) return -1; } -static const char cherry_usage[] = -"git cherry [-v] [ [ []]]"; +static const char * const cherry_usage[] = { + "git cherry [-v] [ [ []]]", + NULL +}; + int cmd_cherry(int argc, const char **argv, const char *prefix) { struct rev_info revs; @@ -1315,26 +1318,25 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) const char *upstream; const char *head = "HEAD"; const char *limit = NULL; - int verbose = 0; + int verbose = 0, abbrev = 0; - if (argc > 1 && !strcmp(argv[1], "-v")) { - verbose = 1; - argc--; - argv++; - } + struct option options[] = { + OPT__ABBREV(&abbrev), + OPT__VERBOSE(&verbose), + OPT_END() + }; - if (argc > 1 && !strcmp(argv[1], "-h")) - usage(cherry_usage); + argc = parse_options(argc, argv, prefix, options, cherry_usage, 0); switch (argc) { - case 4: - limit = argv[3]; - /* FALLTHROUGH */ case 3: - head = argv[2]; + limit = argv[2]; /* FALLTHROUGH */ case 2: - upstream = argv[1]; + head = argv[1]; + /* FALLTHROUGH */ + case 1: + upstream = argv[0]; break; default: current_branch = branch_get(NULL); @@ -1344,7 +1346,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) fprintf(stderr, "Could not find a tracked" " remote branch, please" " specify manually.\n"); - usage(cherry_usage); + usage_with_options(cherry_usage, options); } upstream = current_branch->merge[0]->dst; @@ -1397,12 +1399,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx); printf("%c %s %s\n", sign, - sha1_to_hex(commit->object.sha1), buf.buf); + find_unique_abbrev(commit->object.sha1, abbrev), + buf.buf); strbuf_release(&buf); } else { printf("%c %s\n", sign, - sha1_to_hex(commit->object.sha1)); + find_unique_abbrev(commit->object.sha1, abbrev)); } list = list->next; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b06506139..c0fbcdcf4 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -153,8 +153,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce) printf("%s%06o %s %d\t", tag, ce->ce_mode, - abbrev ? find_unique_abbrev(ce->sha1,abbrev) - : sha1_to_hex(ce->sha1), + find_unique_abbrev(ce->sha1,abbrev), ce_stage(ce)); } write_name_quoted(ce->name + offset, stdout, line_terminator); @@ -176,9 +175,7 @@ static int show_one_ru(struct string_list_item *item, void *cbdata) if (!ui->mode[i]) continue; printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i], - abbrev - ? find_unique_abbrev(ui->sha1[i], abbrev) - : sha1_to_hex(ui->sha1[i]), + find_unique_abbrev(ui->sha1[i], abbrev), i + 1); write_name_quoted(path + offset, stdout, line_terminator); } diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 4484185af..dc86b0d9a 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -103,13 +103,11 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen, } else strcpy(size_text, "-"); printf("%06o %s %s %7s\t", mode, type, - abbrev ? find_unique_abbrev(sha1, abbrev) - : sha1_to_hex(sha1), + find_unique_abbrev(sha1, abbrev), size_text); } else printf("%06o %s %s\t", mode, type, - abbrev ? find_unique_abbrev(sha1, abbrev) - : sha1_to_hex(sha1)); + find_unique_abbrev(sha1, abbrev)); } write_name_quotedpfx(base + chomp_prefix, baselen - chomp_prefix, pathname, stdout, line_termination);